feat(js_analyze): implement noJsxLeakedSemicolon#9912
feat(js_analyze): implement noJsxLeakedSemicolon#9912Netail wants to merge 3 commits intobiomejs:mainfrom
Conversation
🦋 Changeset detectedLatest commit: cb1cd6e The changes in this PR will be included in the next version bump. This PR includes changesets to release 13 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Unsure if this is also a common problem in svelte, astro or vue, else we can remove the JSX prefix |
WalkthroughAdds a new nursery lint rule Suggested reviewers
🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Merging this PR will not alter performance
Comparing Footnotes
|
500ad01 to
20bf6b5
Compare
| ) | ||
| } | ||
|
|
||
| fn action(ctx: &RuleContext<Self>, _state: &Self::State) -> Option<JsRuleAction> { |
There was a problem hiding this comment.
should we even bother providing a fix for this? does the source rule?
There was a problem hiding this comment.
|
Also the concern this rule covers is pretty much only a jsx problem, because of the nature of jsx. Not a problem in HTML and HTML-ish langs. |
There was a problem hiding this comment.
Thank you! I believe the rule requires a bit more care:
- all unsafe fixes are incorrect, check the snapshots. Did you check them?
- I believe the configuration that triggers the rule is too naive. I believe the following case triggers the rule
<>
<br />;
Some Tex
</>| use biome_rule_options::no_jsx_leaked_semicolon::NoJsxLeakedSemicolonOptions; | ||
|
|
||
| declare_lint_rule! { | ||
| /// Disallows leaked semicolons in JSX text nodes. |
There was a problem hiding this comment.
"Leaked" doesn't mean anything without context.
Here's a suggestion
"Flags semicolons that could be rendered as content inside JSX tags."
There was a problem hiding this comment.
What about "Flags text nodes with a leading ; after a JSX element"?
There was a problem hiding this comment.
You used "text nodes" which something related to parsing. See if you can find a plain language, beginner friendly
1497522 to
e93576e
Compare
e93576e to
cb1cd6e
Compare
They seem correct to me, the delete is under the Am I overlooking something? |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
.changeset/ten-walls-throw.md (1)
6-6: Tiny copy polish (optional).You could tighten this to: “This is often accidental and renders
;as text in the output.”As per coding guidelines: “Write changeset descriptions concisely and clearly (1-3 sentences) …”
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In @.changeset/ten-walls-throw.md at line 6, Replace the current sentence "This could be an unintentional mistake, resulting in a ';' being rendered as text in the output." with the tighter phrasing "This is often accidental and renders `;` as text in the output." in the changeset description—use backticks around the semicolon to ensure it's rendered as inline code and keep the changeset description concise (1–3 sentences).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@crates/biome_js_analyze/src/lint/nursery/no_jsx_leaked_semicolon.rs`:
- Around line 112-113: The matcher currently only detects text nodes that start
with ";\n" or ";\r", missing lone ";" or ";" followed directly by EOF/closing
tag; update the condition so it also treats a text of exactly ";" or any text
that starts with ";" (e.g., text == ";" || text.starts_with(';')) as a leaked
semicolon and return None accordingly; apply the same fix to the analogous check
later in the file (the second occurrence around the other matcher) so both
locations handle lone semicolons and semicolons without a newline.
---
Nitpick comments:
In @.changeset/ten-walls-throw.md:
- Line 6: Replace the current sentence "This could be an unintentional mistake,
resulting in a ';' being rendered as text in the output." with the tighter
phrasing "This is often accidental and renders `;` as text in the output." in
the changeset description—use backticks around the semicolon to ensure it's
rendered as inline code and keep the changeset description concise (1–3
sentences).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 4e9b712d-beb7-4061-9c40-30f1c8d54c69
⛔ Files ignored due to path filters (6)
crates/biome_cli/src/execute/migrate/eslint_any_rule_to_biome.rsis excluded by!**/migrate/eslint_any_rule_to_biome.rsand included by**crates/biome_configuration/src/analyzer/linter/rules.rsis excluded by!**/rules.rsand included by**crates/biome_configuration/src/generated/domain_selector.rsis excluded by!**/generated/**,!**/generated/**and included by**crates/biome_configuration/src/generated/linter_options_check.rsis excluded by!**/generated/**,!**/generated/**and included by**crates/biome_diagnostics_categories/src/categories.rsis excluded by!**/categories.rsand included by**crates/biome_js_analyze/tests/specs/nursery/noJsxLeakedSemicolon/invalid.jsx.snapis excluded by!**/*.snapand included by**
📒 Files selected for processing (2)
.changeset/ten-walls-throw.mdcrates/biome_js_analyze/src/lint/nursery/no_jsx_leaked_semicolon.rs
| if !(text.starts_with(";\n") || text.starts_with(";\r")) { | ||
| return None; |
There was a problem hiding this comment.
Leaked ; without newline is currently missed.
The matcher only catches ";\n" / ";\r", so a lone ";" text node (for example inline before a closing tag) is not reported and not fixed.
Proposed patch
- if !(text.starts_with(";\n") || text.starts_with(";\r")) {
+ if !text.starts_with(';') {
+ return None;
+ }
+ let rest = &text[1..];
+ if !(rest.is_empty() || rest.starts_with('\n') || rest.starts_with('\r')) {
return None;
}
@@
- // Remove the leading `;`
- let new_text = text[1..].to_string();
+ let new_text = text.strip_prefix(';')?.to_string();Also applies to: 142-143
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@crates/biome_js_analyze/src/lint/nursery/no_jsx_leaked_semicolon.rs` around
lines 112 - 113, The matcher currently only detects text nodes that start with
";\n" or ";\r", missing lone ";" or ";" followed directly by EOF/closing tag;
update the condition so it also treats a text of exactly ";" or any text that
starts with ";" (e.g., text == ";" || text.starts_with(';')) as a leaked
semicolon and return None accordingly; apply the same fix to the analogous check
later in the file (the second occurrence around the other matcher) so both
locations handle lone semicolons and semicolons without a newline.
|
I just realized this is pretty much |
Sorry, my bad. The rule should flag that example, but it doesn't. Or it does, but there aren't any tests. I believe it doesn't, in fact code rabbit says the same |
Summary
Port https://www.eslint-react.xyz/docs/rules/jsx-no-leaked-semicolon, which disallows leaked semicolons in JSX text nodes.
Partially generated by co-pilot
Test Plan
Unit tests
Docs