Skip to content

Commit a3a73f1

Browse files
authored
Add vue/no-irregular-whitespace rule (#964)
1 parent 501cef9 commit a3a73f1

File tree

5 files changed

+674
-0
lines changed

5 files changed

+674
-0
lines changed

docs/rules/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ For example:
159159
| [vue/no-deprecated-slot-attribute](./no-deprecated-slot-attribute.md) | disallow deprecated `slot` attribute (in Vue.js 2.6.0+) | :wrench: |
160160
| [vue/no-deprecated-slot-scope-attribute](./no-deprecated-slot-scope-attribute.md) | disallow deprecated `slot-scope` attribute (in Vue.js 2.6.0+) | :wrench: |
161161
| [vue/no-empty-pattern](./no-empty-pattern.md) | disallow empty destructuring patterns | |
162+
| [vue/no-irregular-whitespace](./no-irregular-whitespace.md) | disallow irregular whitespace | |
162163
| [vue/no-reserved-component-names](./no-reserved-component-names.md) | disallow the use of reserved names in component definitions | |
163164
| [vue/no-restricted-syntax](./no-restricted-syntax.md) | disallow specified syntax | |
164165
| [vue/no-static-inline-styles](./no-static-inline-styles.md) | disallow static inline `style` attributes | |

docs/rules/no-irregular-whitespace.md

+167
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
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="foo bar" />
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="foo bar" />
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)

lib/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ module.exports = {
4545
'no-dupe-keys': require('./rules/no-dupe-keys'),
4646
'no-duplicate-attributes': require('./rules/no-duplicate-attributes'),
4747
'no-empty-pattern': require('./rules/no-empty-pattern'),
48+
'no-irregular-whitespace': require('./rules/no-irregular-whitespace'),
4849
'no-multi-spaces': require('./rules/no-multi-spaces'),
4950
'no-parsing-error': require('./rules/no-parsing-error'),
5051
'no-reserved-component-names': require('./rules/no-reserved-component-names'),

0 commit comments

Comments
 (0)