fix(react-x): report no-class-component on class name, closes #1932 - #1934
Merged
Rel1cx merged 1 commit intoAug 11, 2026
Merged
Conversation
…1932 Highlight the class identifier instead of the whole class body. For a class expression, report on the variable name; for an anonymous class, report on the `class` keyword. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
@ankitprahladsoni is attempting to deploy a commit to the Rel1cx's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the react-x/no-class-component rule to report diagnostics on a narrower source range (class identifier / assigned variable / class keyword) instead of spanning the entire class body, improving editor highlighting and aligning with issue #1932.
Changes:
- Report
no-class-componenton the class identifier (orclasskeyword for anonymous classes). - For class expressions, attempt to report on the binding name (via collected
id) rather than the class body. - Add rule tests that assert the new error span locations (column/endColumn).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| plugins/eslint-plugin-react-x/src/rules/no-class-component/no-class-component.ts | Adjusts context.report location to target identifier/keyword rather than the full class node. |
| plugins/eslint-plugin-react-x/src/rules/no-class-component/no-class-component.spec.ts | Adds test cases asserting narrowed diagnostic spans for named, assigned, and anonymous class components. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+39
to
49
| const classToken = context.sourceCode.getFirstToken(component, { | ||
| filter: (token) => token.value === "class", | ||
| }); | ||
| context.report({ | ||
| data: { | ||
| name, | ||
| }, | ||
| loc: (id ?? classToken ?? component).loc, | ||
| messageId: "default", | ||
| node: component, | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Highlight the class identifier instead of the whole class body. For a class expression, report on the variable name; for an anonymous class, report on the
classkeyword.Closes #1932
Update "[ ]" to "[x]" to check a box
What kind of change does this PR introduce?
Check at least one. If you are introducing a new binding, you must reference an issue where this binding has been proposed, discussed and approved by the maintainers.
Does this PR introduce a breaking change?
If yes, please describe the impact and migration path for existing applications in an attached issue.
Checklist
fix: remove a typo, closes #___, #___)Other information