Repository navigation
[eslint-plugin] Fix valid-styles crash on ESLint 9 and 10 - #1976
rodrigosdev wants to merge 3 commits into
Conversation
`isNumber` called `context.getScope()`, which ESLint 9 removed. Any number-valued property set to an imported or undeclared identifier made `valid-styles` throw `context.getScope is not a function`. Use `sourceCode.getScope(node)` instead, available since ESLint 8.37. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Hi @rodrigosdev! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
| // `context.getScope()` was removed in ESLint 9; `sourceCode.getScope(node)` | ||
| // is available since ESLint 8.37. |
There was a problem hiding this comment.
nit: I would drop this comment and just let the PR explain the reasoning and historical context.
The reasoning lives in the PR description instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
👍 Would love to see this land. It should also let the rules be supported by Oxlint. |
What changed / motivation ?
On ESLint 9 and 10,
valid-stylescrashes withcontext.getScope is not a functionwhen a number-valued property is set to an imported or undeclared identifier, e.g.flexGrow: IMPORTED.isNumberstill callscontext.getScope(), which ESLint 9 removed.This switches to
sourceCode.getScope(node)through the existinggetSourceCodehelper.History
sourceCode.getScope(node)was added in ESLint 8.37 as the replacement forcontext.getScope(), which was then deprecated (migration guide). ESLint 9 removedcontext.getScope().context.getScope()call came in with [eslint-plugin] allow local resolved constants in valid-styles number checks #1216 (Sep 2025), which added scope lookups sovalid-stylescould resolve local constants in number checks.getFilename()was in use at the time it was written, so this call was missed.context.getScope()still exists, so CI never hit the crash.sourceCode.getScope(node)works on every version from 8.37 up, so older setups are unaffected.Linked PR/Issues
Related to #1248 and #1645
Additional Context
Linted a fixture with every rule against ESLint 8.40.0, 8.57.1, 9.39.5 and 10.13.0. Before: 9.39.5 and 10.13.0 crash in
valid-styles. After: all four report the same 7 messages with no fatal errors. Existing eslint-plugin tests pass.Pre-flight checklist
Contribution Guidelines
🤖 Generated with Claude Code