fix: align no-unused-vars with ESLint implementation#558
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request significantly refactors the no-unused-vars rule to align its behavior with the original ESLint implementation, particularly for TypeScript-specific constructs. The core changes involve moving from name-based variable usage tracking to a more robust symbol-based resolution, which correctly handles scoping, aliases, and various declaration types like declare function overloads and declare namespace members. The introduction of compilePatterns for regex pre-compilation and the matchesIgnorePattern function centralizes and improves the handling of ignore patterns. Additionally, the after-used parameter logic has been correctly implemented, and false positives related to type annotations have been removed. The comprehensive new test cases thoroughly validate these improvements.
c1f88a7 to
1902b10
Compare
1902b10 to
1ac3fb1
Compare
Summary
Fixes #555
Aligns
@typescript-eslint/no-unused-varswith the original typescript-eslint rule by fixing all known input/output mismatches. Verified against the rsbuild real-world codebase with identical results to ESLint.Core fixes (issue #555)
declare function/ overload signature parameters: no longer falsely reported as unuseddeclare function/ overloads: correctly reported (with dedup via symbol pointer)New declaration type support
class/interface/type/enum: addedKindClassDeclaration,KindInterfaceDeclaration,KindTypeAliasDeclaration,KindEnumDeclarationlistenersdeclare namespace/declare module: addedKindModuleDeclarationlistener; members not individually reported;declare globaland module augmentations skipped; namespace augmentation (multi-declaration symbol) skippedKindImportSpecifier,KindImportClause,KindNamespaceImport,KindImportEqualsDeclarationlistenersprocessBindingNamerecursively handlesObjectBindingPattern/ArrayBindingPatternfor both variable declarations and parameter destructuringBehavioral fixes
map[string]withmap[*ast.Symbol]usingTypeChecker.GetSymbolAtLocation+SkipAlias, eliminating cross-scope false negatives{ stats }correctly counts as usage viaGetShorthandAssignmentValueSymbolisExportedover-matching: parameters insideexport class/export functionare no longer treated as exportedisInTypeContext: removedAsExpression/TypeAssertionExpression/SatisfiesExpressionfrom type context (their expression operand is a value context)interface/type/enum/imports used in type context are valid usage, not reported as "only used as type".d.tsfiles: skipped entirely (all declarations are ambient)Configuration fixes
parseOptionsarray format: handles ESLint's[{ option: value }]conventionargs: "after-used": implemented — only reports unused params after the last used one; default-value params act as boundaryvarsIgnorePatternscope: no longer applies to parameters or caught errorsargsIgnorePattern/args: "none": correctly applies to destructured parameter elementsreportUsedIgnorePattern: now applies to all three ignore patterns (vars/args/caughtErrors)ignoreRestSiblings: implemented for destructuring patternshasTypeAnnotationfalse positive: removed incorrect logic that treated type-annotated variables as "used"Related Links
@typescript-eslint/no-unused-varsreports false positives #555Checklist