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(lint): fix eslint issues in src/routes #1347

Merged
merged 23 commits into from
Mar 8, 2025

Conversation

pano9000
Copy link
Contributor

@pano9000 pano9000 commented Mar 6, 2025

Fix eslint issues reported for src/routes

/home/pano/Programming/0_repos/TriliumNextNotes/src/routes/api/attachments.ts
  36:38  error  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any
  44:29  error  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any

/home/pano/Programming/0_repos/TriliumNextNotes/src/routes/api/clipper.ts
   33:11  error  'title' is never reassigned. Use 'const' instead      prefer-const
   33:18  error  'content' is never reassigned. Use 'const' instead    prefer-const
   33:36  error  'images' is never reassigned. Use 'const' instead     prefer-const
   64:26  error  Unexpected any. Specify a different type              @typescript-eslint/no-explicit-any
  103:18  error  'content' is never reassigned. Use 'const' instead    prefer-const
  103:36  error  'images' is never reassigned. Use 'const' instead     prefer-const
  103:54  error  'labels' is never reassigned. Use 'const' instead     prefer-const
  222:9   error  'pageUrl' is never reassigned. Use 'const' instead    prefer-const
  224:9   error  'foundPage' is never reassigned. Use 'const' instead  prefer-const

/home/pano/Programming/0_repos/TriliumNextNotes/src/routes/api/export.ts
  40:17  error  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any

/home/pano/Programming/0_repos/TriliumNextNotes/src/routes/api/image.ts
  85:11  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/routes/api/import.ts
   71:17  error  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any
  123:17  error  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any

/home/pano/Programming/0_repos/TriliumNextNotes/src/routes/api/recent_changes.ts
  8:15  error  'RevisionRow' is defined but never used. Allowed unused vars must match /^_/u  @typescript-eslint/no-unused-vars

/home/pano/Programming/0_repos/TriliumNextNotes/src/routes/api/relation-map.ts
  33:40  error  'noteId' is defined but never used. Allowed unused args must match /^_/u  @typescript-eslint/no-unused-vars

/home/pano/Programming/0_repos/TriliumNextNotes/src/routes/api/revisions.ts
    4:8   error  'revisionService' is defined but never used. Allowed unused vars must match /^_/u  @typescript-eslint/no-unused-vars
  114:9   error  'allNoteIds' is never reassigned. Use 'const' instead                              prefer-const
  148:42  error  Unexpected any. Specify a different type                                           @typescript-eslint/no-explicit-any

/home/pano/Programming/0_repos/TriliumNextNotes/src/routes/api/script.ts
  12:13  error  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any
  36:17  error  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any

/home/pano/Programming/0_repos/TriliumNextNotes/src/routes/api/similar_notes.ts
  11:11  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/routes/api/sql.ts
  59:17  error  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any

/home/pano/Programming/0_repos/TriliumNextNotes/src/routes/api/sync.ts
  33:17  error  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any

/home/pano/Programming/0_repos/TriliumNextNotes/src/routes/api_docs.ts
  1:28  error  'Router' is defined but never used. Allowed unused vars must match /^_/u  @typescript-eslint/no-unused-vars

/home/pano/Programming/0_repos/TriliumNextNotes/src/routes/assets.ts
  8:104  error  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any
  8:124  error  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any

/home/pano/Programming/0_repos/TriliumNextNotes/src/routes/custom.ts
  28:21  error  Unexpected any. Specify a different type                                @typescript-eslint/no-explicit-any
  48:25  error  Unexpected any. Specify a different type                                @typescript-eslint/no-explicit-any
  71:64  error  'next' is defined but never used. Allowed unused args must match /^_/u  @typescript-eslint/no-unused-vars

/home/pano/Programming/0_repos/TriliumNextNotes/src/routes/electron.ts
  10:17  error  The `{}` ("empty object") type allows any non-nullish value, including literals like `0` and `""`.
- If that's what you want, disable this lint rule with an inline comment or configure the 'allowObjectTypes' rule option.
- If you want a type meaning "any object", you probably want `object` instead.
- If you want a type meaning "any value", you probably want `unknown` instead  @typescript-eslint/no-empty-object-type

/home/pano/Programming/0_repos/TriliumNextNotes/src/routes/error_handlers.ts
   5:19  error  Unexpected any. Specify a different type                                @typescript-eslint/no-explicit-any
  20:17  error  Unexpected any. Specify a different type                                @typescript-eslint/no-explicit-any
  25:19  error  Unexpected any. Specify a different type                                @typescript-eslint/no-explicit-any
  25:53  error  'next' is defined but never used. Allowed unused args must match /^_/u  @typescript-eslint/no-unused-vars

/home/pano/Programming/0_repos/TriliumNextNotes/src/routes/routes.ts
  480:130  error  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any
  496:29   error  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any

✖ 38 problems (38 errors, 0 warnings)
  3 errors and 0 warnings potentially fixable with the `--fix` option.

fixes all of the above errors, except for:

/home/pano/Programming/0_repos/TriliumNextNotes/src/routes/api/clipper.ts
  64:26  error  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any

/home/pano/Programming/0_repos/TriliumNextNotes/src/routes/api/script.ts
  12:13  error  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any

✖ 2 problems (2 errors, 0 warnings)

as I do not fully understand what form these any types can take

——

This PR also includes two changes which are not strictly linting related, but helped fix those errors.
I hope it's ok to just include them in this PR anyways.

They both have to do with the way we check for errors in the try/catch blocks.
Since in JS you can throw anything, we need to make sure that we are dealing with an actual Error instance, before we can use the message and stack properties.

a) I've added a HttpError class, which extends from the Error class, and made the ValidationError and NotFoundError extend from HttpError class – this makes handling these errors a bit easier, as these errors are now instances of Error.
b) I've added an safeExtractMessageAndStackFromError to extract the message and stack properties from an "unknown" type error - it will check if the error is of instance Error, and return these. If it isn't it will use fallback strings. This get rid of code duplication in all of these error blocks.

pano9000 added 15 commits March 5, 2025 18:09
req.file is of type "Express.Multer.File | undefined".
Returning with an "uploaded: false" type object -> same handling as in
image.ts
this is in preparation for updating the routes/handleException method, to get rid of "any" (and improve in general)
in this case using "{}" allows all primitive values, which seems to be what is required here.
so let's disable the rule "@typescript-eslint/no-empty-object-type" for this line
@pano9000 pano9000 force-pushed the chore_eslint-fixes_src-routes branch from cdf1ebc to 91c37fa Compare March 7, 2025 23:59
@pano9000 pano9000 marked this pull request as ready for review March 8, 2025 16:16
@eliandoran eliandoran merged commit 14c3fd5 into develop Mar 8, 2025
5 checks passed
@eliandoran eliandoran deleted the chore_eslint-fixes_src-routes branch March 8, 2025 16:25
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