|
| 1 | +--- |
| 2 | +pageClass: rule-details |
| 3 | +sidebarDepth: 0 |
| 4 | +title: vue/no-restricted-html-elements |
| 5 | +description: disallow specific HTML elements |
| 6 | +--- |
| 7 | +# vue/no-restricted-html-elements |
| 8 | + |
| 9 | +> disallow specific HTML elements |
| 10 | +
|
| 11 | +- :exclamation: <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge> |
| 12 | + |
| 13 | +## :book: Rule Details |
| 14 | + |
| 15 | +This rule allows you to specify HTML elements that you don't want to use in your application. |
| 16 | + |
| 17 | +<eslint-code-block :rules="{'vue/no-restricted-html-elements': ['error', 'marquee', 'button'] }"> |
| 18 | + |
| 19 | +```vue |
| 20 | +<template> |
| 21 | + <!-- ✓ GOOD --> |
| 22 | + <p></p> |
| 23 | + <input /> |
| 24 | + <br /> |
| 25 | +
|
| 26 | + <!-- ✗ BAD --> |
| 27 | + <button></button> |
| 28 | + <marquee></marquee> |
| 29 | +</template> |
| 30 | +``` |
| 31 | + |
| 32 | +</eslint-code-block> |
| 33 | + |
| 34 | +## :wrench: Options |
| 35 | + |
| 36 | +This rule takes a list of strings, where each string is an HTML element name to be restricted: |
| 37 | + |
| 38 | +```json |
| 39 | +{ |
| 40 | + "vue/no-restricted-html-elements": ["error", "button", "marquee"] |
| 41 | +} |
| 42 | +``` |
| 43 | + |
| 44 | +<eslint-code-block :rules="{'vue/no-restricted-html-elements': ['error', 'button', 'marquee']}"> |
| 45 | + |
| 46 | +```vue |
| 47 | +<template> |
| 48 | + <!-- ✗ BAD --> |
| 49 | + <button></button> |
| 50 | + <marquee></marquee> |
| 51 | +</template> |
| 52 | +``` |
| 53 | + |
| 54 | +</eslint-code-block> |
| 55 | + |
| 56 | +Alternatively, the rule also accepts objects. |
| 57 | + |
| 58 | +```json |
| 59 | +{ |
| 60 | + "vue/no-restricted-html-elements": [ |
| 61 | + "error", |
| 62 | + { |
| 63 | + "element": "button", |
| 64 | + "message": "Prefer use of our custom <AppButton /> component" |
| 65 | + }, |
| 66 | + { |
| 67 | + "element": "marquee", |
| 68 | + "message": "Do not use deprecated HTML tags" |
| 69 | + } |
| 70 | + ] |
| 71 | +} |
| 72 | +``` |
| 73 | + |
| 74 | +The following properties can be specified for the object. |
| 75 | + |
| 76 | +- `element` ... Specify the html element. |
| 77 | +- `message` ... Specify an optional custom message. |
| 78 | + |
| 79 | +### `{ "element": "marquee" }, { "element": "button" }` |
| 80 | + |
| 81 | +<eslint-code-block :rules="{'vue/no-restricted-html-elements': ['error', { element: 'marquee' }, { element: 'button' }]}"> |
| 82 | + |
| 83 | +```vue |
| 84 | +<template> |
| 85 | + <!-- ✗ BAD --> |
| 86 | + <marquee></marquee> |
| 87 | + <button></button> |
| 88 | +</template> |
| 89 | +``` |
| 90 | + |
| 91 | +</eslint-code-block> |
| 92 | + |
| 93 | +## :mag: Implementation |
| 94 | + |
| 95 | +- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/no-restricted-html-elements.js) |
| 96 | +- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/no-restricted-html-elements.js) |
0 commit comments