Skip to content

Commit 784925b

Browse files
mysticateamichalsnik
authored andcommitted
New: vue/script-indent rule (fixes #118) (#309)
* Chore: extract common part of indent * Chore: refactor tests of html-indent * New: vue/script-indent (fixes #118) * Chore: upgrade deps * Chore: fix test script - To dedupe deps * Chore: revive lost tests * Update: add alignAttributesVertically * change category * add comments
1 parent 9da315c commit 784925b

File tree

230 files changed

+4765
-5629
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

230 files changed

+4765
-5629
lines changed

Diff for: .eslintignore

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
node_modules
2-
coverage
3-
.nyc_output
1+
/.nyc_output
2+
/coverage
3+
/node_modules
4+
/tests/fixtures
5+
/tests/integrations/*/node_modules

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ Enforce all the rules in this category, as well as all higher priority rules, wi
204204
|:---|:--------|:------------|
205205
| :wrench: | [vue/html-closing-bracket-newline](./docs/rules/html-closing-bracket-newline.md) | require or disallow a line break before tag's closing brackets |
206206
| :wrench: | [vue/html-closing-bracket-spacing](./docs/rules/html-closing-bracket-spacing.md) | require or disallow a space before tag's closing brackets |
207+
| :wrench: | [vue/script-indent](./docs/rules/script-indent.md) | enforce consistent indentation in `<script>` |
207208

208209
<!--RULES_TABLE_END-->
209210

Diff for: circle.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
machine:
22
node:
3-
version: 4
3+
version: 8
44

55
dependencies:
66
pre:
77
- nvm install 6
8-
- nvm install 8
8+
- nvm install 4
99

1010
test:
1111
override:

Diff for: docs/rules/script-indent.md

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# enforce consistent indentation in `<script>` (script-indent)
2+
3+
- :wrench: The `--fix` option on the [command line](http://eslint.org/docs/user-guide/command-line-interface#fix) can automatically fix some of the problems reported by this rule.
4+
5+
This rule is similar to core [indent](https://eslint.org/docs/rules/indent) rule, but it has an option for inside of `<script>` tag.
6+
7+
## Rule Details
8+
9+
This rule has some options.
10+
11+
```json
12+
{
13+
"script-indent": ["error", TYPE, {
14+
"baseIndent": 0,
15+
"switchCase": 0,
16+
"ignores": []
17+
}]
18+
}
19+
```
20+
21+
- `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.
22+
- `baseIndent` (`integer`) ... The multiplier of indentation for top-level statements. Default is `0`.
23+
- `switchCase` (`integer`) ... The multiplier of indentation for `case`/`default` clauses. Default is `0`.
24+
- `ignores` (`string[]`) ... The selector to ignore nodes. The AST spec is [here](https://github.com/mysticatea/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.
25+
26+
:+1: Examples of **correct** code for this rule:
27+
28+
```js
29+
/*eslint script-indent: "error"*/
30+
<script>
31+
let a = {
32+
foo: 1,
33+
bar: 2
34+
}
35+
let b = {
36+
foo: 1,
37+
bar: 2
38+
},
39+
c = {
40+
foo: 1,
41+
bar: 2
42+
}
43+
const d = {
44+
foo: 1,
45+
bar: 2
46+
},
47+
e = {
48+
foo: 1,
49+
bar: 2
50+
}
51+
</script>
52+
```
53+
54+
:+1: Examples of **correct** code for this rule:
55+
56+
```js
57+
/*eslint script-indent: ["error", 2, {"baseIndent": 1}]*/
58+
<script>
59+
let a = {
60+
foo: 1,
61+
bar: 2
62+
}
63+
let b = {
64+
foo: 1,
65+
bar: 2
66+
},
67+
c = {
68+
foo: 1,
69+
bar: 2
70+
}
71+
const d = {
72+
foo: 1,
73+
bar: 2
74+
},
75+
e = {
76+
foo: 1,
77+
bar: 2
78+
}
79+
</script>
80+
```
81+
82+
## Related rules
83+
84+
- [indent](https://eslint.org/docs/rules/indent)
85+
- [vue/html-indent](./html-indent.md)

0 commit comments

Comments
 (0)