Skip to content

feat: add svelte/html-self-closing #190

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

Merged
merged 5 commits into from
Aug 4, 2022
Merged

feat: add svelte/html-self-closing #190

merged 5 commits into from
Aug 4, 2022

Conversation

marekvospel
Copy link
Contributor

@marekvospel marekvospel commented Jul 21, 2022

Moved to separate PR from #186

svelte/html-self-closing

A simple rule which automatically closes html tags.

<div></div>
<!-- gets fixed to -->
<div>

vue/html-self-closing also supports custom setting for svg and math elements, which I couldn't simply extract from Svelte AST, so I didn't include it. It can be simply added by checking whether element name is known svg / math element (just like it's done with void elements)

Coverage

100% test coverage.

Issues

svelte:self</svelte:self> seems to be affected by the normal option, but I think they need to share the component option or have different option.

is yet to be resolved
solved

Moved to separate PR from #186
@JounQin JounQin marked this pull request as ready for review July 21, 2022 12:03
@JounQin
Copy link
Collaborator

JounQin commented Jul 21, 2022

Sorry, I accidentally changed the review status. 😅

@JounQin JounQin marked this pull request as draft July 21, 2022 12:05
@marekvospel marekvospel marked this pull request as ready for review July 23, 2022 20:22
Copy link
Member

@ota-meshi ota-meshi left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you!

@ota-meshi ota-meshi requested a review from JounQin July 28, 2022 01:00
</script>

<!-- ✓ GOOD -->
<div />
Copy link
Collaborator

@JounQin JounQin Jul 28, 2022

Choose a reason for hiding this comment

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

This makes the template less html compliant, div is not self-closing in HTML, we should have three options: 'all' | 'html-compliant' | 'none', and 'html-compliant' should be default IMO.

Of course the options naming can be better.

Copy link
Member

Choose a reason for hiding this comment

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

div is not self-closing in HTML
'html-compliant' should be default IMO.

I think we should make the default of prettier-plugin-svelte the default behavior rather than the HTML standard. So I think all should be the default.
prettier-plugin-svelte has long been the default style for the community.
Turn off these rules when users use plugins with prettier-plugin-svelte, but I think it makes sense to adopt the same style as prettier-plugin-svelte by default.

Copy link
Member

Choose a reason for hiding this comment

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

we should have three options: 'all' | 'html-compliant' | 'none'

I think the current options can already do the same. Why do you think we need three options?

{
  "svelte/html-self-closing": [
    "error",
    {
      "void": "always", // or "always" or "ignore"
      "normal": "always", // or "never" or "ignore"
      "component": "always", // or "never" or "ignore"
      "svelte": "always" // or "never" or "ignore"
    }
  ]
}
  • void ("always" by default)... Style of HTML void elements
  • component ("always" by default)... Style of svelte components
  • svelte ("always" by default)... Style of svelte special elements (<svelte:head>, <svelte:self>)
  • normal ("always" by default)... Style of other elements

Every option can be set to

  • "always" (<div />)
  • "never" (<div></div>)
  • "ignore" (either <div /> or <div></div>)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Oh. I didn't know that.
Hmm. The maintainers don't seem to be involved in the discussion, so I'm still not sure if they're thinking of doing so by default.

Copy link
Collaborator

@JounQin JounQin Jul 28, 2022

Choose a reason for hiding this comment

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

The linked option is not related to tag closing, it's related to whitespace and prettier-plugin-svelte already adheres to that option.

I know, I'm just saying we can have such single option, maybe.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I know, I'm just saying we can have such single option, maybe.

That's a good idea, but I'd also keep the current configuration in overrides section, because there could be someone who only wants self closing on tags in specific category, and it would be waste to just throw away the option to set that.

Copy link
Member

Choose a reason for hiding this comment

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

@marekvospel Do you currently have time to work on this PR?

I think the new single option is that we can add features later, so if you don't have time now, after merging this PR, we can work on a new PR when you/we have time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ota-meshi no, I'll have time in 2 weeks or later. I'll create a new PR when I have time

Copy link
Member

Choose a reason for hiding this comment

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

Okay! I will merge this PR. Thank you for the great job!

@ota-meshi ota-meshi merged commit 54d0d68 into sveltejs:main Aug 4, 2022
@marekvospel marekvospel deleted the add-html-self-closing branch August 11, 2022 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants