Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lint): make useSelfClosingElements safe and improve error message #4998

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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