-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
refactor: Add lint rules for no unused vars and unused import #9940
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
refactor: Add lint rules for no unused vars and unused import #9940
Conversation
|
🚀 Thanks for opening this pull request! |
📝 WalkthroughWalkthroughAdds the eslint-plugin-unused-imports and updates lint directives; removes unused error-variable bindings from many catch clauses; adjusts an import and ESLint header in the benchmark file. No functional or API changes are introduced. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (2)
src/Adapters/Files/GridFSBucketAdapter.js (1)
166-176: Catch binding removal in key rotation loop is safeSwitching to a bare
catchhere is behavior‑neutral since the error variable was never read and the loop already justcontinues on failure.If you ever revisit this function, consider logging or accumulating the specific errors for
fileNamesNotRotatedto aid debugging key‑rotation issues, but that’s orthogonal to this lint‑driven change.src/Routers/FilesRouter.js (1)
305-316: Metadata handler catch cleanup (optional: consider logging)Removing the unused catch parameter keeps the current contract of always returning
200 {}on failure to fetch metadata, so behavior is unchanged. If you ever revisit this path, you might consider logging the underlying error before responding to help diagnose backend issues while still returning an empty payload to clients.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (31)
benchmark/performance.js(1 hunks)ci/nodeEngineCheck.js(1 hunks)eslint.config.js(2 hunks)package.json(1 hunks)src/Adapters/Analytics/AnalyticsAdapter.js(1 hunks)src/Adapters/Auth/AuthAdapter.js(1 hunks)src/Adapters/Auth/apple.js(1 hunks)src/Adapters/Auth/facebook.js(1 hunks)src/Adapters/Cache/CacheAdapter.js(1 hunks)src/Adapters/Email/MailAdapter.js(1 hunks)src/Adapters/Files/FilesAdapter.js(1 hunks)src/Adapters/Files/GridFSBucketAdapter.js(1 hunks)src/Adapters/Logger/LoggerAdapter.js(1 hunks)src/Adapters/Logger/WinstonLogger.js(2 hunks)src/Adapters/PubSub/PubSubAdapter.js(1 hunks)src/Adapters/Push/PushAdapter.js(1 hunks)src/Adapters/WebSocketServer/WSAdapter.js(2 hunks)src/Adapters/WebSocketServer/WSSAdapter.js(1 hunks)src/Controllers/HooksController.js(1 hunks)src/Controllers/index.js(1 hunks)src/GraphQL/loaders/filesMutations.js(1 hunks)src/Options/parsers.js(1 hunks)src/Routers/ClassesRouter.js(1 hunks)src/Routers/FilesRouter.js(1 hunks)src/Routers/PagesRouter.js(3 hunks)src/Utils.js(1 hunks)src/batch.js(1 hunks)src/cli/utils/runner.js(1 hunks)src/middlewares.js(3 hunks)src/password.js(1 hunks)src/request.js(1 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: mtrezza
Repo: parse-community/parse-server PR: 0
File: :0-0
Timestamp: 2025-11-08T13:46:04.940Z
Learning: When reviewing Parse Server PRs that add new features, always check whether the feature is documented in the README.md file, though for new Parse Server options this is optional rather than required.
📚 Learning: 2025-05-09T09:59:06.289Z
Learnt from: mtrezza
Repo: parse-community/parse-server PR: 9445
File: spec/ParseLiveQuery.spec.js:1340-1375
Timestamp: 2025-05-09T09:59:06.289Z
Learning: Tests in the parse-server repository should use promise-based approaches rather than callback patterns with `done()`. Use a pattern where a Promise is created that resolves when the event occurs, then await that promise.
Applied to files:
src/GraphQL/loaders/filesMutations.js
📚 Learning: 2025-05-09T09:59:06.289Z
Learnt from: mtrezza
Repo: parse-community/parse-server PR: 9445
File: spec/ParseLiveQuery.spec.js:1340-1375
Timestamp: 2025-05-09T09:59:06.289Z
Learning: New tests in the parse-server repository should use async/await with promise-based patterns rather than callback patterns with `done()`. The preferred pattern is to create a Promise that resolves when an expected event occurs, then await that Promise.
Applied to files:
src/GraphQL/loaders/filesMutations.js
🧬 Code graph analysis (1)
benchmark/performance.js (1)
benchmark/MongoLatencyWrapper.js (1)
require(20-20)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (16)
- GitHub Check: PostgreSQL 18, PostGIS 3.6
- GitHub Check: PostgreSQL 15, PostGIS 3.5
- GitHub Check: PostgreSQL 17, PostGIS 3.5
- GitHub Check: Node 20
- GitHub Check: MongoDB 6, ReplicaSet
- GitHub Check: Node 18
- GitHub Check: Node 22
- GitHub Check: PostgreSQL 15, PostGIS 3.3
- GitHub Check: PostgreSQL 15, PostGIS 3.4
- GitHub Check: MongoDB 7, ReplicaSet
- GitHub Check: PostgreSQL 16, PostGIS 3.5
- GitHub Check: Redis Cache
- GitHub Check: MongoDB 8, ReplicaSet
- GitHub Check: Docker Build
- GitHub Check: Code Analysis (javascript)
- GitHub Check: Benchmarks
🔇 Additional comments (30)
ci/nodeEngineCheck.js (1)
89-93: LGTM! Unused error binding correctly removed.The error variable was not being used in the catch block, so removing the binding is appropriate. The behavior remains identical—the catch block still logs the filename and issues a warning for invalid JSON.
src/GraphQL/loaders/filesMutations.js (1)
41-41: LGTM!Removing the unused error binding is appropriate since the error value is not referenced in the catch block.
src/Adapters/Analytics/AnalyticsAdapter.js (1)
1-1: LGTM!The ESLint directive update aligns with the PR objectives to adopt the
unused-importsplugin.src/Adapters/WebSocketServer/WSAdapter.js (1)
1-1: LGTM!The ESLint directive update is consistent with the PR objectives.
src/Adapters/WebSocketServer/WSSAdapter.js (1)
1-1: LGTM!The ESLint directive update is consistent with the PR objectives to migrate to the
unused-importsplugin.src/Adapters/Logger/LoggerAdapter.js (1)
1-1: LGTM!The ESLint directive update aligns with the PR objectives.
src/Adapters/Logger/WinstonLogger.js (2)
45-47: LGTM!Removing the unused error binding is appropriate for this silent error handler.
89-91: LGTM!Removing the unused error binding is appropriate for this silent error handler.
src/Adapters/Auth/AuthAdapter.js (1)
1-1: LGTM!The ESLint directive update is consistent with the PR objectives to adopt the
unused-importsplugin.src/Controllers/index.js (1)
220-222: LGTM!Removing the unused error binding is appropriate since the error is not referenced in this silent error handler.
src/Adapters/PubSub/PubSubAdapter.js (1)
1-1: Header lint directive switch is consistent and non-functionalDisabling
unused-imports/no-unused-varsat file scope for this adapter matches the new lint setup and doesn’t affect runtime behavior. Looks good.src/batch.js (1)
14-18: ParameterlesscatchinparseURLpreserves previous behaviorRemoving the unused error binding (
catch (error)→catch {}) keeps the same control flow (invalid URLs still returnundefined) while satisfying the new unused-vars lint rule.src/Adapters/Files/FilesAdapter.js (1)
1-1: Adapter-wide unused-vars rule disable is appropriate hereDisabling
unused-imports/no-unused-varsfor this abstract adapter/interface file is consistent with the rest of the adapters and has no runtime effect.src/Utils.js (1)
81-87:fileExistscatch change is purely syntacticSwitching from
catch (e)tocatch {}keeps the same behavior (any access error yieldsfalse) while removing an unused binding. Safe and aligned with the PR’s linting goal.src/password.js (1)
5-13: Native bcrypt feature-detection catch remains behaviorally identicalThe move to a parameterless
catchin the optional@node-rs/bcryptrequire keeps the same fallback semantics (silently usingbcryptjson failure) while addressing the unused error variable. No functional change.src/request.js (1)
30-36:HTTPResponse.getDatastill safely ignores JSON parse failuresReplacing
catch (e)withcatch {}keeps the existing behavior of silently ignoring JSON.parse errors and leavingdataundefined, just without an unused error binding.src/cli/utils/runner.js (1)
21-27: Startup options logging keeps same fallback behaviorThe parameterless
catchstill falls back to using the constructor name whenJSON.stringifythrows, so logging semantics are unchanged while satisfying the unused-vars rule.package.json (1)
90-96: eslint-plugin-unused-imports devDependency aligns with lint rule changesAdding
"eslint-plugin-unused-imports": "4.3.0"under devDependencies matches the new unused-imports lint rules and is tooling-only, so it won’t affect runtime. Just ensure eslint.config is updated to register this plugin and its rules, as referenced in the PR description.src/Adapters/Email/MailAdapter.js (1)
1-1: ESLint directive correctly aligned with unused-imports pluginSwitching the top-of-file disable to
unused-imports/no-unused-varsis appropriate here given the abstract interface-style methods that intentionally don't use their parameters.Please confirm
eslint-plugin-unused-importsis registered ineslint.config.jsand thatunused-imports/no-unused-varsis the active rule name in this codebase.src/Routers/PagesRouter.js (1)
435-437: Optional catch binding change is behavior‑preservingUpdating these blocks from
catch (e)to barecatchkeeps behavior identical (the error object was never used) while satisfying the unused‑vars lint rule. Given Parse Server’s Node target, ES2019’s optional catch binding should be supported.Please confirm that the minimum Node/ECMAScript target for this project supports parameterless
catchso that tooling (e.g., TypeScript, Babel, ESLint parser) all parse this syntax correctly.Also applies to: 477-479, 520-522
src/Options/parsers.js (1)
58-60: moduleOrObjectParser catch cleanup keeps semantics unchangedUsing a bare
catchhere is fine—the parse error was already intentionally ignored so thatoptis returned as‑is, and the unused error binding is removed.As with other parameterless
catchusages in this PR, please ensure the project’s JS/Node tooling stack fully supports optional catch bindings.src/Adapters/Cache/CacheAdapter.js (1)
1-1: Lint directive matches interface-style usageAligning this file’s disable comment with
unused-imports/no-unused-varsis appropriate given the abstract methods with intentionally unused parameters.Please double‑check that this rule name matches the configuration in
eslint.config.jsso the directive has the intended effect.src/Adapters/Push/PushAdapter.js (1)
1-1: Local disable of unused vars for abstract adapter is appropriateThis file intentionally has unused parameters (interface-like methods). Switching the directive to target
unused-imports/no-unused-varsmatches the new lint setup and avoids noisy violations without changing behavior.src/Adapters/Auth/facebook.js (1)
122-131: Catch binding removal keeps behavior unchangedSwapping
catch (error)for a barecatchis safe here since the caught value was never used. The function still maps any failure to the sameOBJECT_NOT_FOUNDerror and message.src/Adapters/Auth/apple.js (1)
63-72: Bare catch here is a no-op behaviorallyThe catch parameter was unused, so moving to
catch { ... }simply satisfies the new lint rule without changing the function’s semantics or error surface.src/middlewares.js (1)
77-84: Catch parameter removal in header/context parsing is safeIn all three places (
X-Parse-Cloud-Contextheader, body JSON parsing, and_contextparsing), the caught error value was never inspected; the code only falls back tomalformedContextorinvalidRequest. Converting to barecatch {}keeps the same control flow while satisfying the unused-variable lint rules.Also applies to: 127-131, 171-178
src/Routers/ClassesRouter.js (1)
147-155: JSONFromQuery catch binding removal is behavior‑preservingFor query parameters that aren’t valid JSON, this helper still falls back to the original string value. Since the error object was never used, switching to
catch { ... }is purely a lint cleanup.eslint.config.js (1)
4-5: eslint-plugin-unused-imports is correctly configured for ESLint 9The plugin version 4.x targets ESLint 9 and the official README confirms the flat config usage pattern
plugins: { "unused-imports": unusedImports }exactly as implemented. Requiring the plugin, registering it in thepluginsobject, enabling itsno-unused-importsandno-unused-varsrules, and disabling the coreno-unused-varsrule is a coherent setup that avoids duplicate diagnostics and aligns with the PR goal of strict unused detection.benchmark/performance.js (1)
11-15: Import cleanup and switch tonode:perf_hooksis correctThe "node:" protocol for require() is supported by Node.js since v14.18.0, and Parse Server v8+ requires Node >= 18.20.4 / 20.18.0 / 22.12.0, so the change is fully compatible. Removing unused
PerformanceObserveris the right cleanup.src/Controllers/HooksController.js (1)
225-234: Unused error binding removed without changing behaviorSwitching from
catch (e)to a barecatchhere is correct: the caught error wasn’t used, and the logic still produces the same genericerrobject on JSON parse failure. No behavior change, just cleaner code consistent with the new lint rules.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## alpha #9940 +/- ##
=======================================
Coverage 93.08% 93.08%
=======================================
Files 187 187
Lines 15275 15275
Branches 177 177
=======================================
Hits 14219 14219
Misses 1044 1044
Partials 12 12 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
mtrezza
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one! Ready for merge?
|
Yes ! |
Pull Request
Add rules for no-unused-vars and no-unused-import
Summary by CodeRabbit
Chores
Refactor
✏️ Tip: You can customize this high-level summary in your review settings.