-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add config option for foreign elements in `svelte/html-self-clo…
…sing` rule (#841) 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.
- Loading branch information
Showing
18 changed files
with
215 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'eslint-plugin-svelte': minor | ||
--- | ||
|
||
feat: add config option for foreign elements in `svelte/html-self-closing` rule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
packages/eslint-plugin-svelte/src/utils/element-types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
export const voidElements = [ | ||
'area', | ||
'base', | ||
'br', | ||
'col', | ||
'embed', | ||
'hr', | ||
'img', | ||
'input', | ||
'keygen', | ||
'link', | ||
'menuitem', | ||
'meta', | ||
'param', | ||
'source', | ||
'track', | ||
'wbr' | ||
]; | ||
|
||
export const svgElements = [ | ||
'altGlyph', | ||
'altGlyphDef', | ||
'altGlyphItem', | ||
'animate', | ||
'animateColor', | ||
'animateMotion', | ||
'animateTransform', | ||
'circle', | ||
'clipPath', | ||
'color-profile', | ||
'cursor', | ||
'defs', | ||
'desc', | ||
'discard', | ||
'ellipse', | ||
'feBlend', | ||
'feColorMatrix', | ||
'feComponentTransfer', | ||
'feComposite', | ||
'feConvolveMatrix', | ||
'feDiffuseLighting', | ||
'feDisplacementMap', | ||
'feDistantLight', | ||
'feDropShadow', | ||
'feFlood', | ||
'feFuncA', | ||
'feFuncB', | ||
'feFuncG', | ||
'feFuncR', | ||
'feGaussianBlur', | ||
'feImage', | ||
'feMerge', | ||
'feMergeNode', | ||
'feMorphology', | ||
'feOffset', | ||
'fePointLight', | ||
'feSpecularLighting', | ||
'feSpotLight', | ||
'feTile', | ||
'feTurbulence', | ||
'filter', | ||
'font', | ||
'font-face', | ||
'font-face-format', | ||
'font-face-name', | ||
'font-face-src', | ||
'font-face-uri', | ||
'foreignObject', | ||
'g', | ||
'glyph', | ||
'glyphRef', | ||
'hatch', | ||
'hatchpath', | ||
'hkern', | ||
'image', | ||
'line', | ||
'linearGradient', | ||
'marker', | ||
'mask', | ||
'mesh', | ||
'meshgradient', | ||
'meshpatch', | ||
'meshrow', | ||
'metadata', | ||
'missing-glyph', | ||
'mpath', | ||
'path', | ||
'pattern', | ||
'polygon', | ||
'polyline', | ||
'radialGradient', | ||
'rect', | ||
'set', | ||
'solidcolor', | ||
'stop', | ||
'svg', | ||
'switch', | ||
'symbol', | ||
'text', | ||
'textPath', | ||
'tref', | ||
'tspan', | ||
'unknown', | ||
'use', | ||
'view', | ||
'vkern' | ||
]; | ||
|
||
export const mathmlElements = [ | ||
'annotation', | ||
'annotation-xml', | ||
'maction', | ||
'math', | ||
'merror', | ||
'mfrac', | ||
'mi', | ||
'mmultiscripts', | ||
'mn', | ||
'mo', | ||
'mover', | ||
'mpadded', | ||
'mphantom', | ||
'mprescripts', | ||
'mroot', | ||
'mrow', | ||
'ms', | ||
'mspace', | ||
'msqrt', | ||
'mstyle', | ||
'msub', | ||
'msubsup', | ||
'msup', | ||
'mtable', | ||
'mtd', | ||
'mtext', | ||
'mtr', | ||
'munder', | ||
'munderover', | ||
'semantics' | ||
]; |
This file was deleted.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
...t-plugin-svelte/tests/fixtures/rules/html-self-closing/invalid/foreign-never/_config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"options": [ | ||
{ | ||
"foreign": "never" | ||
} | ||
] | ||
} |
8 changes: 8 additions & 0 deletions
8
...lte/tests/fixtures/rules/html-self-closing/invalid/foreign-never/svelte-never-errors.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
- message: Disallow self-closing on foreign (SVG or MathML) elements. | ||
line: 2 | ||
column: 12 | ||
suggestions: null | ||
- message: Disallow self-closing on foreign (SVG or MathML) elements. | ||
line: 3 | ||
column: 13 | ||
suggestions: null |
3 changes: 3 additions & 0 deletions
3
...te/tests/fixtures/rules/html-self-closing/invalid/foreign-never/svelte-never-input.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<!-- prettier-ignore --> | ||
<svg><path /></svg> | ||
<math><msup /></math> |
3 changes: 3 additions & 0 deletions
3
...e/tests/fixtures/rules/html-self-closing/invalid/foreign-never/svelte-never-output.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<!-- prettier-ignore --> | ||
<svg><path ></path></svg> | ||
<math><msup ></msup></math> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters