Skip to content

Commit

Permalink
feat(lint): make useSelfClosingElements safe and improve error message (
Browse files Browse the repository at this point in the history
  • Loading branch information
mehm8128 authored Jan 30, 2025
1 parent b9a023e commit f0e6521
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
cli: patch
biome_js_analyze: patch
---

# mark `useSelfClosingElements` as safe and improve error message
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ use crate::JsRuleAction;
declare_lint_rule! {
/// Prevent extra closing tags for components without children
///
/// JSX elements without children should be marked as self-closing. In JSX, it is valid for any element to be self-closing.
///
/// ## Examples
///
/// ### Invalid
Expand Down Expand Up @@ -91,7 +93,7 @@ declare_lint_rule! {
sources: &[RuleSource::EslintStylistic("jsx-self-closing-comp")],
recommended: false,
severity: Severity::Warning,
fix_kind: FixKind::Unsafe,
fix_kind: FixKind::Safe,
}
}

Expand Down Expand Up @@ -180,7 +182,7 @@ impl Rule for UseSelfClosingElements {
Some(JsRuleAction::new(
ctx.metadata().action_category(ctx.category(), ctx.group()),
ctx.metadata().applicability(),
markup! { "Use a SelfClosingElement instead" }.to_owned(),
markup! { "Use a self-closing element instead." }.to_owned(),
mutation,
))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ invalid.tsx:1:1 lint/style/useSelfClosingElements FIXABLE ━━━━━━
2 │ <Component></Component>;
3 │ <Foo.bar></Foo.bar>;
i Unsafe fix: Use a SelfClosingElement instead
i Safe fix: Use a self-closing element instead.
1 │ <div···············></div>;
│ -- ---
Expand All @@ -45,7 +45,7 @@ invalid.tsx:2:1 lint/style/useSelfClosingElements FIXABLE ━━━━━━
3 │ <Foo.bar></Foo.bar>;
4 │ <div
i Unsafe fix: Use a SelfClosingElement instead
i Safe fix: Use a self-closing element instead.
1 1 │ <div ></div>;
2 │ - <Component></Component>;
Expand All @@ -68,7 +68,7 @@ invalid.tsx:3:1 lint/style/useSelfClosingElements FIXABLE ━━━━━━
4 │ <div
5 │
i Unsafe fix: Use a SelfClosingElement instead
i Safe fix: Use a self-closing element instead.
1 1 │ <div ></div>;
2 2 │ <Component></Component>;
Expand All @@ -95,7 +95,7 @@ invalid.tsx:4:1 lint/style/useSelfClosingElements FIXABLE ━━━━━━
7 │
8 │ <div ></div> /* comment */;
i Unsafe fix: Use a SelfClosingElement instead
i Safe fix: Use a self-closing element instead.
6 │ ></div>;
│ -- ---
Expand All @@ -114,7 +114,7 @@ invalid.tsx:8:1 lint/style/useSelfClosingElements FIXABLE ━━━━━━
9 │ /* comment */ <div ></div>;
10 │ <Generic<true>></Generic>;
i Unsafe fix: Use a SelfClosingElement instead
i Safe fix: Use a self-closing element instead.
8 │ <div·></div>·/*·comment·*/;
│ -- ---
Expand All @@ -131,7 +131,7 @@ invalid.tsx:9:15 lint/style/useSelfClosingElements FIXABLE ━━━━━━
│ ^^^^^^^^^^^^
10 │ <Generic<true>></Generic>;
i Unsafe fix: Use a SelfClosingElement instead
i Safe fix: Use a self-closing element instead.
9 │ /*·comment·*/·<div·></div>;
│ -- ---
Expand All @@ -148,7 +148,7 @@ invalid.tsx:10:1 lint/style/useSelfClosingElements FIXABLE ━━━━━━
> 10 │ <Generic<true>></Generic>;
│ ^^^^^^^^^^^^^^^^^^^^^^^^^
i Unsafe fix: Use a SelfClosingElement instead
i Safe fix: Use a self-closing element instead.
8 8 │ <div ></div> /* comment */;
9 9 │ /* comment */ <div ></div>;
Expand All @@ -157,5 +157,3 @@ invalid.tsx:10:1 lint/style/useSelfClosingElements FIXABLE ━━━━━━
```


Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ invalidCheckHtmlElementsFalse.tsx:2:1 lint/style/useSelfClosingElements FIXABLE
3 │ <Foo.bar></Foo.bar>;
4 │ <Generic<true>></Generic>;
i Unsafe fix: Use a SelfClosingElement instead
i Safe fix: Use a self-closing element instead.
1 1 │ // invalid
2 │ - <Component></Component>;
Expand All @@ -46,7 +46,7 @@ invalidCheckHtmlElementsFalse.tsx:3:1 lint/style/useSelfClosingElements FIXABLE
4 │ <Generic<true>></Generic>;
5 │
i Unsafe fix: Use a SelfClosingElement instead
i Safe fix: Use a self-closing element instead.
1 1 │ // invalid
2 2 │ <Component></Component>;
Expand All @@ -69,7 +69,7 @@ invalidCheckHtmlElementsFalse.tsx:4:1 lint/style/useSelfClosingElements FIXABLE
│ ^^^^^^^^^^^^^^^^^^^^^^^^^
5 │
i Unsafe fix: Use a SelfClosingElement instead
i Safe fix: Use a self-closing element instead.
2 2 │ <Component></Component>;
3 3 │ <Foo.bar></Foo.bar>;
Expand Down

0 comments on commit f0e6521

Please sign in to comment.