Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
eslint-factory: resolve destructured bindings precisely in resolveInitializer #53960
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
Uh oh!
There was an error while loading. Please reload this page.
eslint-factory: resolve destructured bindings precisely in resolveInitializer #53960
Changes from all commits
8b7b6a96cb3adcce47824File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
There are no files selected for viewing
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.
[/diagnosing-bugs] The spread guard (
slice(0, index + 1).some(...)) is correct but re-scans previously visited elements on every loop iteration, making the function O(n2) for wide array patterns.💡 Suggested fix — single-pass spread tracking
Track whether a spread element has been seen as you iterate:
Not a correctness issue, but improves readability and avoids redundant work for patterns with many elements.
@copilot please address this.
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.
[/diagnosing-bugs]
asExpressionrejectsAssignmentPattern(default values), which is correct for object shorthand defaults — but there's no test forconst { cmd = fallback } = { cmd: template }. Without coverage, a future reader may not know this is intentionally unsupported.💡 Suggested test
Add a valid-case entry in each rule's test suite:
If the intent is to be conservative (return null), the test documents that; if the intent should be to resolve through defaults, the missing logic becomes visible.
@copilot please address this.
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.
[/tdd] The object-pattern resolver handles duplicate property keys by returning the last one (matching JS runtime semantics). This edge case is not covered by any test, so a future refactor could break it silently.
💡 Suggested test
And the reverse — last value is safe even though the first is not:
@copilot please address this.
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.
[/tdd] The new invalid test cases don't cover nested array destructuring (e.g.,
const [[cmd]] = [[template]]) or aliased object keys (e.g.,const { cmd: alias } = { cmd: template }). The implementation returns null for these (correct conservative behaviour), but without valid-case tests a reader cannot verify that they are intentionally unsupported.💡 Suggested additions to valid cases
Even if these remain unresolvable by design, explicit tests act as executable documentation.
@copilot please address this.
Uh oh!
There was an error while loading. Please reload this page.