Repository navigation
[eslint-plugin] ESLint 10 compatibility - #1645
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
There was a problem hiding this comment.
Pull request overview
This PR updates the StyleX ESLint plugin toward ESLint 10 by replacing deprecated rule-context filename accessors and aligning the local Flow libdef with the newer context shape.
Changes:
- Replaced
context.getFilename()usages withcontext.filenamein two ESLint rules. - Updated the bundled Flow
RuleContextlibdef to exposefilename,physicalFilename, andcwdproperties. - Kept the scope limited to plugin-side compatibility changes rather than upgrading the monorepo itself to ESLint 10.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
packages/@stylexjs/eslint-plugin/src/stylex-valid-styles.js |
Swaps filename lookup to the newer ESLint context property in the main style validation rule. |
packages/@stylexjs/eslint-plugin/src/stylex-enforce-extension.js |
Swaps filename lookup to the newer ESLint context property in the extension enforcement rule. |
packages/@stylexjs/eslint-plugin/flow_modules/eslint/eslint-rule.js.flow |
Updates the published Flow libdef for ESLint rule contexts to the newer property-based API. |
| // Track same-file defineVars/defineVarsNested/defineConstsNested declarations. | ||
| const currentFilename = | ||
| context.getFilename != null ? context.getFilename() : ''; | ||
| const currentFilename = context.filename; |
There was a problem hiding this comment.
getScope() was removed in ESLint 9, not 10: https://eslint.org/docs/latest/use/troubleshooting/v9-rule-api-changes.
ESLint 9 was released around two years ago. This would have already been an issue? I might need to double-check, but I'm sure that if the lint rule was broken on ESLint 9, we would have heard about it by now.
| let hasDefineMarkerExports = false; | ||
| let reportedDefaultExportError = false; | ||
| const fileName = context.getFilename(); | ||
| const fileName = context.filename; |
There was a problem hiding this comment.
Updating the repo to use ESLint 10 is outside the scope of this diff, since it involves rewriting the config file and ensuring that all lint rules used in the repo are compatible. It can be done in a separate diff.
The fact that the tests pass with ESLint 8 shows that the change is backwards-compatible. Ideally the tests would run with multiple ESLint versions (maybe 8, 9, and 10) but I'm not sure how to do that.
| // parserPath: string, | ||
| // parserServices: SourceCode.ParserServices; | ||
| sourceCode: SourceCode, | ||
| getAncestors(): Array<ESTree.Node>, | ||
|
|
||
| // getDeclaredVariables(node: ESTree.Node): Scope.Variable[]; | ||
|
|
||
| getFilename(): string, | ||
| filename: string; | ||
|
|
||
| getPhysicalFilename(): string, | ||
| physicalFilename: string; | ||
|
|
||
| getCwd(): string, | ||
| cwd: string; |
There was a problem hiding this comment.
Realistically I don't think this would be an issue. ESLint 8 and 9 have these properties too, and I'm not sure how many (if any) downstream users are using Flow along with the types shipped with eslint-plugin. There's a bunch of stuff missing from these types.
mellyeliu
left a comment
There was a problem hiding this comment.
Thanks for cleaning this up, it'll be great to get on ESLint 10 soon
What changed / motivation ?
Several functions that were deprecated in ESLint 9 were deleted in ESLint 10. This diff removes usage of these legacy functions. The only one that was used in stylex is
getFilename(), which has been replaced by thefilenameproperty.https://eslint.org/docs/latest/use/migrate-to-10.0.0#-removal-of-deprecated-context-members
The
filenameproperty has existed since ESLint 8, so this will not break any projects that are still on old ESLint evrsions.Upgrading stylex itself to ESLint v10 is outside the scope of this diff. I tried doing that, but the config file needs to be rewritten as it's in the legacy eslintrc format.
Contribution Guidelines
Test plan
All tests for the ESLint plugin still pass: