|
| 1 | +--- |
| 2 | +pageClass: "rule-details" |
| 3 | +sidebarDepth: 0 |
| 4 | +title: "svelte/no-restricted-html-elements" |
| 5 | +description: "disallow specific HTML elements" |
| 6 | +--- |
| 7 | + |
| 8 | +# svelte/no-restricted-html-elements |
| 9 | + |
| 10 | +> disallow specific HTML elements |
| 11 | +
|
| 12 | +- :exclamation: <badge text="This rule has not been released yet." vertical="middle" type="error"> **_This rule has not been released yet._** </badge> |
| 13 | + |
| 14 | +## :book: Rule Details |
| 15 | + |
| 16 | +This rule reports to usage of resticted HTML elements. |
| 17 | + |
| 18 | +<ESLintCodeBlock> |
| 19 | + |
| 20 | +<!--eslint-skip--> |
| 21 | + |
| 22 | +```svelte |
| 23 | +<script> |
| 24 | + /* eslint svelte/no-restricted-html-elements: ["error", "h1", "h2", "h3", "h4", "h5", "h6"] */ |
| 25 | +</script> |
| 26 | +
|
| 27 | +<!-- ✓ GOOD --> |
| 28 | +<div> |
| 29 | + <p>Hi!</p> |
| 30 | +</div> |
| 31 | +
|
| 32 | +<!-- ✗ BAD --> |
| 33 | +<h1>foo</h1> |
| 34 | +
|
| 35 | +<div> |
| 36 | + <h2>bar</h2> |
| 37 | +</div> |
| 38 | +``` |
| 39 | + |
| 40 | +</ESLintCodeBlock> |
| 41 | + |
| 42 | +--- |
| 43 | + |
| 44 | +<ESLintCodeBlock> |
| 45 | + |
| 46 | +<!--eslint-skip--> |
| 47 | + |
| 48 | +```svelte |
| 49 | +<script> |
| 50 | + /* eslint svelte/no-restricted-html-elements: ["error", { "elements": ["marquee"], "message": "Do not use deprecated HTML tags" }] */ |
| 51 | +</script> |
| 52 | +
|
| 53 | +<!-- ✓ GOOD --> |
| 54 | +<div> |
| 55 | + <p>Hi!</p> |
| 56 | +</div> |
| 57 | +
|
| 58 | +<!-- ✗ BAD --> |
| 59 | +<marquee>foo</marquee> |
| 60 | +
|
| 61 | +<div> |
| 62 | + <marquee>bar</marquee> |
| 63 | +</div> |
| 64 | +``` |
| 65 | + |
| 66 | +</ESLintCodeBlock> |
| 67 | + |
| 68 | +## :wrench: Options |
| 69 | + |
| 70 | +This rule takes a list of strings, where each string is an HTML element name to be restricted: |
| 71 | + |
| 72 | +```json |
| 73 | +{ |
| 74 | + "svelte/no-restricted-html-elements": [ |
| 75 | + "error", |
| 76 | + "h1", |
| 77 | + "h2", |
| 78 | + "h3", |
| 79 | + "h4", |
| 80 | + "h5", |
| 81 | + "h6" |
| 82 | + ] |
| 83 | +} |
| 84 | +``` |
| 85 | + |
| 86 | +Alternatively, the rule also accepts objects. |
| 87 | + |
| 88 | +```json |
| 89 | +{ |
| 90 | + "svelte/no-restricted-html-elements": [ |
| 91 | + "error", |
| 92 | + { |
| 93 | + "elements": ["h1", "h2", "h3", "h4", "h5", "h6"], |
| 94 | + "message": "Prefer use of our custom <Heading /> component" |
| 95 | + }, |
| 96 | + { |
| 97 | + "elements": ["marquee"], |
| 98 | + "message": "Do not use deprecated HTML tags" |
| 99 | + } |
| 100 | + ] |
| 101 | +} |
| 102 | +``` |
| 103 | + |
| 104 | +## :mag: Implementation |
| 105 | + |
| 106 | +- [Rule source](https://github.com/sveltejs/eslint-plugin-svelte/blob/main/src/rules/no-restricted-html-elements.ts) |
| 107 | +- [Test source](https://github.com/sveltejs/eslint-plugin-svelte/blob/main/tests/src/rules/no-restricted-html-elements.ts) |
0 commit comments