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: add config option for foreign elements in svelte/html-self-closing rule #841

Merged
merged 1 commit into from
Sep 13, 2024

Conversation

jrmajor
Copy link
Contributor

@jrmajor jrmajor commented Aug 10, 2024

This PR adds separate configuration option for foreign (SVG and MathML) elements to svelte/html-self-closing rule.

According to HTML spec (https://html.spec.whatwg.org/multipage/syntax.html#elements-2):

Raw text, escapable raw text, and normal elements have a start tag to indicate where they begin, and an end tag to indicate where they end. The start and end tags of certain normal elements can be omitted, as described below in the section on optional tags. Those that cannot be omitted must not be omitted. Void elements only have a start tag; end tags must not be specified for void elements. Foreign elements must either have a start tag and an end tag, or a start tag that is marked as self-closing, in which case they must not have an end tag.

This means that <div/> is invalid, while <path/> (which is a SVG element) is OK. This configuration option would allow users to take advantage of the terser SVG syntax, while still using correct HTML syntax for normal elements (like div).

Closes #837.

Copy link

changeset-bot bot commented Aug 10, 2024

🦋 Changeset detected

Latest commit: 41a8af0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
eslint-plugin-svelte Minor

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

@@ -0,0 +1,140 @@
export const voidElements = [
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved from removed void-elemets.ts file. It's actually different that the list that Svelte uses (https://github.com/sveltejs/svelte/blob/c32a91891fc647998f738371a012fcba97d56e50/packages/svelte/src/utils.js#L16-L33).

'wbr'
];

export const svgElements = [
Copy link
Contributor Author

Choose a reason for hiding this comment

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

'vkern'
];

export const mathmlElements = [
Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

Thank you for this PR! LGTM!

@ota-meshi ota-meshi merged commit 85053a1 into sveltejs:main Sep 13, 2024
ota-meshi pushed a commit that referenced this pull request Sep 13, 2024
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## eslint-plugin-svelte@2.44.0

### Minor Changes

- [#841](#841)
[`85053a1`](85053a1)
Thanks [@jrmajor](https://github.com/jrmajor)! - feat: add config option
for foreign elements in `svelte/html-self-closing` rule

### Patch Changes

- [#853](#853)
[`690c04e`](690c04e)
Thanks [@ota-meshi](https://github.com/ota-meshi)! - fix: update
svelte-eslint-parser to 0.41.1

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
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.

More configuration options for html-self-closing
2 participants