-
-
Notifications
You must be signed in to change notification settings - Fork 681
/
Copy pathscript-indent.md
130 lines (107 loc) · 3.12 KB
/
script-indent.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
---
pageClass: rule-details
sidebarDepth: 0
title: vue/script-indent
description: enforce consistent indentation in `<script>`
since: v4.2.0
---
# vue/script-indent
> enforce consistent indentation in `<script>`
- :wrench: The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule.
## :book: Rule Details
This rule enforces a consistent indentation style in `<script>`. The default style is 2 spaces.
<eslint-code-block fix :rules="{'vue/script-indent': ['error']}">
```vue
<script>
let a = {
foo: 1,
bar: 2
}
let b = {
foo: 1,
bar: 2
},
c = {
foo: 1,
bar: 2
}
const d = {
foo: 1,
bar: 2
},
e = {
foo: 1,
bar: 2
}
</script>
```
</eslint-code-block>
## :wrench: Options
This rule has some options.
```json
{
"vue/script-indent": ["error", TYPE, {
"baseIndent": 0,
"switchCase": 0,
"ignores": []
}]
}
```
- `TYPE` (`number | "tab"`) ... The type of indentation. Default is `2`. If this is a number, it's the number of spaces for one indent. If this is `"tab"`, it uses one tab for one indent.
- `baseIndent` (`integer`) ... The multiplier of indentation for top-level statements. Default is `0`.
- `switchCase` (`integer`) ... The multiplier of indentation for `case`/`default` clauses. Default is `0`.
- `ignores` (`string[]`) ... The selector to ignore nodes. The AST spec is [here](https://github.com/vuejs/vue-eslint-parser/blob/master/docs/ast.md). You can use [esquery](https://github.com/estools/esquery#readme) to select nodes. Default is an empty array.
::: warning Note
This rule only checks `.vue` files and does not interfere with other `.js` files. Unfortunately the default `indent` rule when turned on will try to lint both, so in order to make them complementary you can use `overrides` setting and disable `indent` rule on `.vue` files:
:::
```json
{
"rules": {
"vue/script-indent": ["error", 4, { "baseIndent": 1 }]
},
"overrides": [
{
"files": ["*.vue"],
"rules": {
"indent": "off"
}
}
]
}
```
### `2, "baseIndent": 1`
<eslint-code-block fix :rules="{'vue/script-indent': ['error', 2, { 'baseIndent': 1 }]}">
```vue
<script>
let a = {
foo: 1,
bar: 2
}
let b = {
foo: 1,
bar: 2
},
c = {
foo: 1,
bar: 2
}
const d = {
foo: 1,
bar: 2
},
e = {
foo: 1,
bar: 2
}
</script>
```
</eslint-code-block>
## :couple: Related Rules
- [indent](https://eslint.org/docs/rules/indent)
- [vue/html-indent](./html-indent.md)
- [@typescript-eslint/indent](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/indent.md)
## :rocket: Version
This rule was introduced in eslint-plugin-vue v4.2.0
## :mag: Implementation
- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/script-indent.js)
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/script-indent.js)