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

📚 Why is the useSelfClosingElements fix unsafe? #1708

Closed
1 task done
jacobconley opened this issue Jan 24, 2025 · 2 comments
Closed
1 task done

📚 Why is the useSelfClosingElements fix unsafe? #1708

jacobconley opened this issue Jan 24, 2025 · 2 comments

Comments

@jacobconley
Copy link

jacobconley commented Jan 24, 2025

Documentation URL

https://biomejs.dev/linter/rules/use-self-closing-elements/

Description

Forgive me if this information isn't meant to be included in the documentation, I opened it here because it's more of a question than a problem and I think others would benefit.

In VSCode the rule description is as follows:

JSX elements without children should be marked as self-closing. In JSX, it is valid for any element to be self-closing.

That sentence is missing from the online docs, but it's pretty assertive that self-closing tags are always good and there is never a difference. If that's the case, why is the fix marked unsafe?

Expectations

In situations like this, I'd like to understand why the fix is unsafe, so that I can decide whether or not to apply it.
Sometimes it's obvious, such as the lint that prefers ? over ! in nonnull assertions, but seems to me that self-closing tags are semantically identical to empty tags, so I'm unsure here.

If it's marked unsafe not because of the semantics but rather because the fix implementation isn't completely reliable, that makes sense to me, but I think it'd be useful to clarify that in the documentation. I might even take that a step further and propose adding a new category alongside "safe" and "unsafe" - "safe in theory, but might not be perfect yet so make sure to double check it".

Cheers!

Code of Conduct

  • I agree to follow Biome's Code of Conduct
@ematipico
Copy link
Member

There are two situations when a fix is unsafe:

  1. The fix is really unsafe because it could break somebody's code due to the nature of JavaScript.
  2. Sometimes, we (maintainers) aren't confident about the stability of the code fix because it might miss some use cases.

Generally, if a code fix is unsafe due to 2., then we aim to make it safe with time by adding more cases. And we might forget about it! It can happen

Regarding this particular rule, this was one of the first rules that was created and I believe we eventually forgot to update it. In fact, the documentation is very poor and the message is incorrect (what's SelfClosingElement anyway??). I think we forgot to follow up and make the rule fix safe :)

Thank you for bringing it up, I will open an issue

@jacobconley
Copy link
Author

Thank you! I'll go ahead and close this then since my question is answered and the documentation part is addressed by the new one.

Loving Biome so far, thanks for all of your work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants