|
| 1 | +--- |
| 2 | +pageClass: rule-details |
| 3 | +sidebarDepth: 0 |
| 4 | +title: vue/no-irregular-whitespace |
| 5 | +description: disallow irregular whitespace |
| 6 | +--- |
| 7 | +# vue/no-irregular-whitespace |
| 8 | +> disallow irregular whitespace |
| 9 | +
|
| 10 | +`vue/no-irregular-whitespace` rule is aimed at catching invalid whitespace that is not a normal tab and space. Some of these characters may cause issues in modern browsers and others will be a debugging issue to spot. |
| 11 | +`vue/no-irregular-whitespace` rule is the similar rule as core [no-irregular-whitespace] rule but it applies to the source code in .vue. |
| 12 | + |
| 13 | +<eslint-code-block :rules="{'vue/no-irregular-whitespace': ['error']}"> |
| 14 | + |
| 15 | +```vue |
| 16 | +<template> |
| 17 | + <!-- ✓ GOOD --> |
| 18 | + <div class="foo bar" /> |
| 19 | + <!-- ✗ BAD --> |
| 20 | + <div class="foobar" /> |
| 21 | + <!-- ^ LINE TABULATION (U+000B) --> |
| 22 | +</template> |
| 23 | +<script> |
| 24 | +/* ✓ GOOD */ |
| 25 | +var foo = bar; |
| 26 | +/* ✗ BAD */ |
| 27 | +var foo =bar; |
| 28 | +// ^ LINE TABULATION (U+000B) |
| 29 | +</script> |
| 30 | +``` |
| 31 | + |
| 32 | +</eslint-code-block> |
| 33 | + |
| 34 | +## :wrench: Options |
| 35 | + |
| 36 | +```js |
| 37 | +{ |
| 38 | + "vue/no-irregular-whitespace": ["error", { |
| 39 | + "skipStrings": true, |
| 40 | + "skipComments": false, |
| 41 | + "skipRegExps": false, |
| 42 | + "skipTemplates": false, |
| 43 | + "skipHTMLAttributeValues": false, |
| 44 | + "skipHTMLTextContents": false |
| 45 | + }] |
| 46 | +} |
| 47 | +``` |
| 48 | + |
| 49 | +- `skipStrings`: if `true`, allows any whitespace characters in string literals. default `true` |
| 50 | +- `skipComments`: if `true`, allows any whitespace characters in comments. default `false` |
| 51 | +- `skipRegExps`: if `true`, allows any whitespace characters in regular expression literals. default `false` |
| 52 | +- `skipTemplates`: if `true`, allows any whitespace characters in template literals. default `false` |
| 53 | +- `skipHTMLAttributeValues`: if `true`, allows any whitespace characters in HTML attribute values. default `false` |
| 54 | +- `skipHTMLTextContents`: if `true`, allows any whitespace characters in HTML text contents. default `false` |
| 55 | + |
| 56 | +### `"skipStrings": true` (default) |
| 57 | + |
| 58 | +<eslint-code-block :rules="{'vue/no-irregular-whitespace': ['error', {skipStrings: true}]}"> |
| 59 | + |
| 60 | +```vue |
| 61 | +<script> |
| 62 | +/* ✓ GOOD */ |
| 63 | +var foo = '' |
| 64 | +// ^ LINE TABULATION (U+000B) |
| 65 | +</script> |
| 66 | +``` |
| 67 | + |
| 68 | +</eslint-code-block> |
| 69 | + |
| 70 | +### `"skipStrings": false` |
| 71 | + |
| 72 | +<eslint-code-block :rules="{'vue/no-irregular-whitespace': ['error', {skipStrings: false}]}"> |
| 73 | + |
| 74 | +```vue |
| 75 | +<script> |
| 76 | +/* ✗ BAD */ |
| 77 | +var foo = '' |
| 78 | +// ^ LINE TABULATION (U+000B) |
| 79 | +</script> |
| 80 | +``` |
| 81 | + |
| 82 | +</eslint-code-block> |
| 83 | + |
| 84 | +### `"skipComments": true` |
| 85 | + |
| 86 | +<eslint-code-block :rules="{'vue/no-irregular-whitespace': ['error', {skipComments: true}]}"> |
| 87 | + |
| 88 | +```vue |
| 89 | +<template> |
| 90 | + <!-- ✓ GOOD --> |
| 91 | + <!-- []< LINE TABULATION (U+000B) --> |
| 92 | +</template> |
| 93 | +<script> |
| 94 | +/* ✓ GOOD */ |
| 95 | +// []< LINE TABULATION (U+000B) |
| 96 | +/* []< LINE TABULATION (U+000B) */ |
| 97 | +</script> |
| 98 | +``` |
| 99 | + |
| 100 | +</eslint-code-block> |
| 101 | + |
| 102 | +### `"skipRegExps": true` |
| 103 | + |
| 104 | +<eslint-code-block :rules="{'vue/no-irregular-whitespace': ['error', {skipRegExps: true}]}"> |
| 105 | + |
| 106 | +```vue |
| 107 | +<script> |
| 108 | +/* ✓ GOOD */ |
| 109 | +var foo = // |
| 110 | +// ^ LINE TABULATION (U+000B) |
| 111 | +</script> |
| 112 | +``` |
| 113 | + |
| 114 | +</eslint-code-block> |
| 115 | + |
| 116 | +### `"skipTemplates": true` |
| 117 | + |
| 118 | +<eslint-code-block :rules="{'vue/no-irregular-whitespace': ['error', {skipTemplates: true}]}"> |
| 119 | + |
| 120 | +```vue |
| 121 | +<script> |
| 122 | +/* ✓ GOOD */ |
| 123 | +var foo = `` |
| 124 | +// ^ LINE TABULATION (U+000B) |
| 125 | +</script> |
| 126 | +``` |
| 127 | + |
| 128 | +</eslint-code-block> |
| 129 | + |
| 130 | +### `"skipHTMLAttributeValues": true` |
| 131 | + |
| 132 | +<eslint-code-block :rules="{'vue/no-irregular-whitespace': ['error', {skipHTMLAttributeValues: true}]}"> |
| 133 | + |
| 134 | +```vue |
| 135 | +<template> |
| 136 | + <!-- ✓ GOOD --> |
| 137 | + <div class="foobar" /> |
| 138 | + <!-- ^ LINE TABULATION (U+000B) --> |
| 139 | +</template> |
| 140 | +``` |
| 141 | + |
| 142 | +</eslint-code-block> |
| 143 | + |
| 144 | +### `"skipHTMLTextContents": true` |
| 145 | + |
| 146 | +<eslint-code-block :rules="{'vue/no-irregular-whitespace': ['error', {skipHTMLTextContents: true}]}"> |
| 147 | + |
| 148 | +```vue |
| 149 | +<template> |
| 150 | + <!-- ✓ GOOD --> |
| 151 | + <div></div> |
| 152 | + <!-- ^ LINE TABULATION (U+000B) --> |
| 153 | +</template> |
| 154 | +``` |
| 155 | + |
| 156 | +</eslint-code-block> |
| 157 | + |
| 158 | +## :books: Further reading |
| 159 | + |
| 160 | +- [no-irregular-whitespace] |
| 161 | + |
| 162 | +[no-irregular-whitespace]: https://eslint.org/docs/rules/no-irregular-whitespace |
| 163 | + |
| 164 | +## :mag: Implementation |
| 165 | + |
| 166 | +- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/no-irregular-whitespace.js) |
| 167 | +- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/no-irregular-whitespace.js) |
0 commit comments