Fix #33854: [Bug]: eslint 10 support#33893
Fix #33854: [Bug]: eslint 10 support#33893danielalanbates wants to merge 1 commit intostorybookjs:nextfrom
Conversation
…ontext.sourceCode for ESLint 10 compatibility Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
📝 WalkthroughWalkthroughUpdates four ESLint plugin rule files to use Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes ✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
code/lib/eslint-plugin/src/rules/prefer-pascal-case.ts (1)
39-175:⚠️ Potential issue | 🟠 MajorRemove deprecated
typeproperty from RuleTester error assertions.ESLint v10.0.0 removed the deprecated
typeproperty from error assertions inRuleTester. Multiple test files in the eslint-plugin use this pattern and will fail under ESLint v10. Update all error objects in test files to remove thetype:property — for example, removetype: AST_NODE_TYPES.Identifierfrom error assertions in prefer-pascal-case.test.ts and other affected test files.Affected files include:
- code/lib/eslint-plugin/src/rules/prefer-pascal-case.test.ts
- code/lib/eslint-plugin/src/rules/use-storybook-testing-library.test.ts
- code/lib/eslint-plugin/src/rules/use-storybook-expect.test.ts
- code/lib/eslint-plugin/src/rules/story-exports.test.ts
- code/lib/eslint-plugin/src/rules/no-title-property-in-meta.test.ts
- code/lib/eslint-plugin/src/rules/no-stories-of.test.ts
- code/lib/eslint-plugin/src/rules/no-renderer-packages.test.ts
- code/lib/eslint-plugin/src/rules/no-redundant-story-name.test.ts
- code/lib/eslint-plugin/src/rules/no-uninstalled-addons.test.ts
- code/lib/eslint-plugin/src/rules/meta-inline-properties.test.ts
- code/lib/eslint-plugin/src/rules/hierarchy-separator.test.ts
- code/lib/eslint-plugin/src/rules/csf-component.test.ts
- code/lib/eslint-plugin/src/rules/context-in-play-function.test.ts
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@code/lib/eslint-plugin/src/rules/prefer-pascal-case.ts` around lines 39 - 175, Tests are failing under ESLint v10 because RuleTester error assertion objects still include the deprecated type property (e.g., type: AST_NODE_TYPES.Identifier); update the tests (starting with prefer-pascal-case.test.ts and the other listed rule test files) to remove any error.type entries from their expected error objects, leaving message/messageId/location etc. intact so assertions use the supported shape for ESLint v10.
🧹 Nitpick comments (1)
code/lib/eslint-plugin/src/rules/prefer-pascal-case.ts (1)
59-94: Optional: hoistsourceCodeto the top ofcreate()for consistency.
context.sourceCodeis accessed twice in separate inner-function scopes — once at line 59 (insidegetModuleScope) and again at line 94 (inside the fixer). Hoisting a singleconst sourceCode = context.sourceCode;to the top ofcreate()— mirroringmeta-satisfies-type.ts— would eliminate the duplicate accesses and keep the rule consistent across the plugin.♻️ Suggested refactor
create(context) { // variables should be defined here + const sourceCode = context.sourceCode; //---------------------------------------------------------------------- // Helpers //---------------------------------------------------------------------- ... const getModuleScope = (): TSESLint.Scope.Scope | undefined => { - const { sourceCode } = context; ... }; const checkAndReportError = (id: TSESTree.Identifier, nonStoryExportsConfig = {}) => { ... *fix(fixer) { - const fullText = context.sourceCode.text; + const fullText = sourceCode.text;🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@code/lib/eslint-plugin/src/rules/prefer-pascal-case.ts` around lines 59 - 94, Hoist a single const sourceCode = context.sourceCode at the top of the create() function and replace all direct uses of context.sourceCode inside getModuleScope and inside the fixer generator in checkAndReportError with that hoisted sourceCode variable; keep existing compatibility logic in getModuleScope and ensure the fixer reads fullText from the hoisted sourceCode.text to avoid duplicate context.sourceCode accesses and match the pattern used in meta-satisfies-type.ts.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@code/lib/eslint-plugin/src/rules/prefer-pascal-case.ts`:
- Around line 39-175: Tests are failing under ESLint v10 because RuleTester
error assertion objects still include the deprecated type property (e.g., type:
AST_NODE_TYPES.Identifier); update the tests (starting with
prefer-pascal-case.test.ts and the other listed rule test files) to remove any
error.type entries from their expected error objects, leaving
message/messageId/location etc. intact so assertions use the supported shape for
ESLint v10.
---
Nitpick comments:
In `@code/lib/eslint-plugin/src/rules/prefer-pascal-case.ts`:
- Around line 59-94: Hoist a single const sourceCode = context.sourceCode at the
top of the create() function and replace all direct uses of context.sourceCode
inside getModuleScope and inside the fixer generator in checkAndReportError with
that hoisted sourceCode variable; keep existing compatibility logic in
getModuleScope and ensure the fixer reads fullText from the hoisted
sourceCode.text to avoid duplicate context.sourceCode accesses and match the
pattern used in meta-satisfies-type.ts.
Fixes #33854
Summary
This PR fixes: [Bug]: eslint 10 support
Changes
Testing
Please review the changes carefully. The fix was verified against the existing test suite.
This PR was created with the assistance of Claude Sonnet 4.6 by Anthropic | effort: low. Happy to make any adjustments!
Summary by CodeRabbit