Skip to content

fix(react-x): report no-class-component on class name, closes #1932 - #1934

Merged
Rel1cx merged 1 commit into
Rel1cx:mainfrom
ankitprahladsoni:fix/no-class-component-report-loc
Aug 11, 2026
Merged

fix(react-x): report no-class-component on class name, closes #1932#1934
Rel1cx merged 1 commit into
Rel1cx:mainfrom
ankitprahladsoni:fix/no-class-component-report-loc

Conversation

@ankitprahladsoni

Copy link
Copy Markdown
Contributor

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.
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.

  • Bugfix
  • Feature
  • Perf
  • Docs
  • Test
  • Chore
  • Enhancement
  • New Binding issue #___
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change?

If yes, please describe the impact and migration path for existing applications in an attached issue.

  • Yes, and the changes were approved in issue #___
  • No

Checklist

  • When resolving issues, they are referenced in the PR's title (e.g fix: remove a typo, closes #___, #___)
  • I have added a convincing reason for adding this feature, if necessary

Other information

…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>
@vercel

vercel Bot commented Aug 11, 2026

Copy link
Copy Markdown

@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.

@vercel

vercel Bot commented Aug 11, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
eslint-react Ready Ready Preview Aug 11, 2026 11:12pm

@Rel1cx
Rel1cx merged commit d874fec into Rel1cx:main Aug 11, 2026
8 of 9 checks passed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-component on the class identifier (or class keyword 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,
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] no-class-component: report on class name only, not the entire class body

3 participants