ESLint: Modernize eslint-plugin rule APIs for v10 compatibility#76507
ESLint: Modernize eslint-plugin rule APIs for v10 compatibility#76507manzoorwanijk merged 1 commit intotrunkfrom
Conversation
Update all custom rules in @wordpress/eslint-plugin to use modern ESLint APIs, preparing for the v10 upgrade: - context.getScope() → context.sourceCode.getScope(node) - context.getFilename() → context.filename - context.getSourceCode() → context.sourceCode - context.getDeclaredVariables() → context.sourceCode.getDeclaredVariables() - context.getAncestors() → context.sourceCode.getAncestors(node) - context.getCommentsBefore() → sourceCode.getCommentsBefore() Also: - Add missing meta.schema to i18n-translator-comments rule - Remove type: from error assertions in 3 test files (no-i18n-in-save, no-unsafe-wp-apis, use-recommended-components) — removed in v10 RuleTester All changes are backward-compatible with ESLint v8.40+.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Size Change: 0 B Total Size: 8.75 MB ℹ️ View Unchanged
|
|
Flaky tests detected in 8f9a88c. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/23094618881
|
ciampo
left a comment
There was a problem hiding this comment.
- Code changes look good
- All tests pass in the PR
- No deprecation warnings
LGTM, thank you for the cleanup! 🚀
What?
Update all custom ESLint rules in
@wordpress/eslint-pluginto use modern APIs and remove deprecated patterns from tests.Part of the ESLint v10 upgrade effort — see #76506.
Why?
ESLint v10 removes 18+ deprecated
context.*methods that our custom rules currently rely on. The replacement APIs have been available since ESLint v8.40+, so updating them now is fully backward-compatible and can land on trunk independently. This reduces the diff in the main ESLint v10 upgrade PR.Similarly, v10's
RuleTesterremoves thetypeproperty from error assertions. Sincetypeis optional in v8, removing it now is safe.How?
Rule API updates (6 rules modified):
context.getScope()context.sourceCode.getScope(node)react-no-unsafe-timeout,no-unused-vars-before-returncontext.getFilename()context.filenameno-i18n-in-savecontext.getSourceCode()context.sourceCodedependency-groupcontext.getDeclaredVariables()context.sourceCode.getDeclaredVariables()data-no-store-string-literalscontext.getAncestors()context.sourceCode.getAncestors(node)data-no-store-string-literalscontext.getCommentsBefore()sourceCode.getCommentsBefore()i18n-translator-commentsOther changes:
meta.schema: []toi18n-translator-commentsrule (required in v10 for rules with options)type:from error assertions in 3 test files:no-i18n-in-save.js(14 occurrences)no-unsafe-wp-apis.js(5 occurrences)use-recommended-components.js(5 occurrences)Testing Instructions
trunk, runnpm run test:unit -- packages/eslint-pluginand notice the deprecation warnings aboutcontext.getScope(),context.getSourceCode(), etc.npm run lint:js— output should be unchanged from trunk.Screenshots or screencast
N/A — no UI changes.
Use of AI Tools
This PR was authored with Claude Code, used for auditing all 28 custom rules for deprecated API usage and making the updates.