Skip to content

feat(jsx): add jsx-no-leaked-semicolon rule, closes #1685#1686

Merged
Rel1cx merged 8 commits intomainfrom
react-jsx/no-trailing-semicolon
Apr 2, 2026
Merged

feat(jsx): add jsx-no-leaked-semicolon rule, closes #1685#1686
Rel1cx merged 8 commits intomainfrom
react-jsx/no-trailing-semicolon

Conversation

@Rel1cx
Copy link
Copy Markdown
Owner

@Rel1cx Rel1cx commented Apr 2, 2026

Disallows trailing semicolons that would be rendered as text nodes in JSX. When refactoring JSX, trailing semicolons may be accidentally left immediately after JSX elements or fragments, causing ; to be unexpectedly rendered.

  • Add rule implementation with JSXText and Literal node detection
  • Include comprehensive test cases
  • Add documentation with examples
  • Register in recommended, all, and jsx presets

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

Disallows trailing semicolons that would be rendered as text nodes
in JSX. When refactoring JSX, trailing semicolons may be accidentally
left immediately after JSX elements or fragments, causing `;` to be
unexpectedly rendered.

- Add rule implementation with JSXText and Literal node detection
- Include comprehensive test cases
- Add documentation with examples
- Register in recommended, all, and jsx presets
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 2, 2026

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

Project Deployment Actions Updated (UTC)
eslint-react Ready Ready Preview, Comment Apr 2, 2026 4:46pm

Request Review

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new JSX-focused ESLint rule to detect and warn on “dangling” semicolons that become rendered JSX text nodes, and wires it into presets and documentation.

Changes:

  • Implement react-jsx/no-trailing-semicolon (exposed as @eslint-react/jsx-no-trailing-semicolon) to report suspicious semicolons in JSX children text.
  • Add unit tests and rule documentation page.
  • Register the rule in recommended/all/jsx-related presets and the website rules metadata.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/plugins/eslint-plugin/src/configs/jsx.ts Enables the new @eslint-react/jsx-no-trailing-semicolon rule in the JSX preset.
packages/plugins/eslint-plugin/src/configs/all.ts Enables the new rule in the @eslint-react/all preset.
packages/plugins/eslint-plugin-react-jsx/src/rules/no-trailing-semicolon/no-trailing-semicolon.ts Adds the rule implementation and reporting logic.
packages/plugins/eslint-plugin-react-jsx/src/rules/no-trailing-semicolon/no-trailing-semicolon.spec.ts Adds rule tests covering common trailing-semicolon cases and non-violations.
packages/plugins/eslint-plugin-react-jsx/src/rules/no-trailing-semicolon/no-trailing-semicolon.mdx Adds end-user documentation and examples for the new rule.
packages/plugins/eslint-plugin-react-jsx/src/plugin.ts Registers the rule in the eslint-plugin-react-jsx plugin export.
packages/plugins/eslint-plugin-react-jsx/src/configs/recommended.ts Enables the rule in the react-jsx/recommended config (and thus strict).
apps/website/content/docs/rules/meta.json Adds the rule to the website rules index metadata.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…-semicolon/no-trailing-semicolon.mdx

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: REL1CX <solarflarex@qq.com>
@nstepien
Copy link
Copy Markdown

nstepien commented Apr 2, 2026

Thinking about it, I wonder if "jsx-no-dangling-semicolon" would be a better rule name 🤔

@Rel1cx
Copy link
Copy Markdown
Owner Author

Rel1cx commented Apr 2, 2026

Thinking about it, I wonder if "jsx-no-dangling-semicolon" would be a better rule name 🤔

"jsx-no-dangling-semicolon" sounds better than "no-trailing-semicolon," though I personally prefer "no-leaked-semicolon." Anyway, until a final name is decided, I'll publish this as a recipe at https://www.eslint-react.xyz/docs/recipes/overview to avoid any breaking changes from a future rename.

@nstepien
Copy link
Copy Markdown

nstepien commented Apr 2, 2026

I'm not totally against "no-leaked-semicolon", but it can a bit confusing to understand at first glance: how can you "leak" a semicolon? Leaks generally refer to memory leaks, no?

@Rel1cx Rel1cx force-pushed the react-jsx/no-trailing-semicolon branch 2 times, most recently from 4ad0783 to 4c398da Compare April 2, 2026 14:42
@Rel1cx
Copy link
Copy Markdown
Owner Author

Rel1cx commented Apr 2, 2026

I'm not totally against "no-leaked-semicolon", but it can a bit confusing to understand at first glance: how can you "leak" a semicolon? Leaks generally refer to memory leaks, no?

The naming follows an established convention in the React community where "leaked" describes
values accidentally rendered to the UI. Similar rules include:

In this context, "leak" means an unintended value appearing in the rendered output, not a
memory leak.

Happy to consider alternative names if this still feels confusing.

@nstepien
Copy link
Copy Markdown

nstepien commented Apr 2, 2026

:shipit:👍

Gotta rename the PR title too

@Rel1cx Rel1cx changed the title feat(jsx): add jsx-no-trailing-semicolon rule, closes #1685 feat(jsx): add jsx-no-leaked-semicolon rule, closes #1685 Apr 2, 2026
…o-leaked-semicolon

- Rename rule files and update all references
- Rename function hasSuspiciousSemicolon to hasLeakedSemicolon
- Update error message: "Leaked semicolon in JSX"
- Update configs: recommended.ts, all.ts, jsx.ts
- Update documentation meta.json
@Rel1cx Rel1cx merged commit fbb4950 into main Apr 2, 2026
10 of 11 checks passed
@Rel1cx Rel1cx deleted the react-jsx/no-trailing-semicolon branch April 2, 2026 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants