Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix lint issues in src/share #1384

Draft
wants to merge 8 commits into
base: develop
Choose a base branch
from
Draft

Conversation

pano9000
Copy link
Member

WIP for fixing lint issues in src/share folder :-)

/home/pano/Programming/0_repos/TriliumNextNotes/src/share/routes.spec.ts
  14:23  error  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any

/home/pano/Programming/0_repos/TriliumNextNotes/src/share/routes.ts
  186:29  error  Unexpected any. Specify a different type                                         @typescript-eslint/no-explicit-any
  197:38  error  'next' is defined but never used. Allowed unused args must match /^_/u           @typescript-eslint/no-unused-vars
  213:46  error  'next' is defined but never used. Allowed unused args must match /^_/u           @typescript-eslint/no-unused-vars
  223:55  error  'next' is defined but never used. Allowed unused args must match /^_/u           @typescript-eslint/no-unused-vars
  236:64  error  'next' is defined but never used. Allowed unused args must match /^_/u           @typescript-eslint/no-unused-vars
  258:66  error  'next' is defined but never used. Allowed unused args must match /^_/u           @typescript-eslint/no-unused-vars
  284:83  error  'next' is defined but never used. Allowed unused args must match /^_/u           @typescript-eslint/no-unused-vars
  302:76  error  'next' is defined but never used. Allowed unused args must match /^_/u           @typescript-eslint/no-unused-vars
  324:60  error  'next' is defined but never used. Allowed unused args must match /^_/u           @typescript-eslint/no-unused-vars
  342:47  error  'next' is defined but never used. Allowed unused args must match /^_/u           @typescript-eslint/no-unused-vars
  354:15  error  'note' is assigned a value but never used. Allowed unused vars must match /^_/u  @typescript-eslint/no-unused-vars

/home/pano/Programming/0_repos/TriliumNextNotes/src/share/shaca/entities/sattachment.ts
  50:13  error  'content' is never reassigned. Use 'const' instead  prefer-const

/home/pano/Programming/0_repos/TriliumNextNotes/src/share/shaca/entities/snote.ts
  108:13  error  'content' is never reassigned. Use 'const' instead  prefer-const
  215:23  error  Unexpected any. Specify a different type            @typescript-eslint/no-explicit-any
  229:18  error  'e' is defined but never used                       @typescript-eslint/no-unused-vars

/home/pano/Programming/0_repos/TriliumNextNotes/src/share/shaca/shaca-interface.ts
  88:25  error  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any

/home/pano/Programming/0_repos/TriliumNextNotes/src/share/shaca/shaca_loader.ts
  96:8   error  'entityName' is defined but never used. Allowed unused args must match /^_/u  @typescript-eslint/no-unused-vars
  96:20  error  'entity' is defined but never used. Allowed unused args must match /^_/u      @typescript-eslint/no-unused-vars

✖ 19 problems (19 errors, 0 warnings)

Two errors will be left-over for now:

Two errors left:

/home/pano/Programming/0_repos/TriliumNextNotes/src/share/shaca/entities/snote.ts
  229:18  error  'e' is defined but never used  @typescript-eslint/no-unused-vars

this one is a bit weird -> even if I prepend it with an underscore (to mark it as deliberately unused) it flags it as an issue.
I want to avoid needing to add a "eslint disable" comment for that line for now, so I'll just keep it "open" for a final review after I went through all the other folders, running eslint, first

/home/pano/Programming/0_repos/TriliumNextNotes/src/share/shaca/shaca-interface.ts
  88:25  error  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any

currently struggling about the correct way to make TypeScript happy with this "dynamic" way of accessing the Shaca class' properties.

In Becca there is an additional if (!(camelCaseEntityName in this)), but it doesn't really help TS with narrowing down the type unfortunately.

will need to revisit later as well :-)

@pano9000 pano9000 force-pushed the chore_lint-share branch 2 times, most recently from c68f445 to 4b34867 Compare March 10, 2025 18:31
@pano9000 pano9000 marked this pull request as ready for review March 10, 2025 18:31
Comment on lines +120 to +125
const contentSvg = (typeof possibleSvgContent === "object"
&& possibleSvgContent !== null
&& "svg" in possibleSvgContent
&& typeof possibleSvgContent.svg === "string")
? possibleSvgContent.svg
: null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is quite hard to read, I would prefer extracting it in a method and using if statements and writing a test for it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume you mean moving this as method into SNote class?

something like this?
It still looks ugly, but not much we can do about it I guess.
As I've noted in my commit message, using a schema validator like zod would make life a lot easier for these types of situation (but that would be something for the future, not this PR I'd say).

snote.ts

        getSvgContent() {
            const possibleSvgContent = this.getJsonContentSafely();

            return (typeof possibleSvgContent === "object"
                && possibleSvgContent !== null
                && "svg" in possibleSvgContent
                && typeof possibleSvgContent.svg === "string")
                    ? possibleSvgContent.svg
                    : null;
        }

routes.ts

        const contentSvg = image.getSvgContent();

@eliandoran eliandoran marked this pull request as draft March 11, 2025 11:37
alternative solution, since they are unused and it is the last argument → remove it.
We can still go that route later on though, if we agree upon it.
…ariable

there's no need to assign a variable, if we never use the value outside of the if check
JSON and TS without using a validation library like zod, is really a bit of a pain in the backside...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants