Skip to content

Commit f4f998b

Browse files
committed
update a bit
1 parent a5e5e5f commit f4f998b

File tree

4 files changed

+151
-9
lines changed

4 files changed

+151
-9
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"editor.tabSize": 2
2+
"editor.tabSize": 2,
3+
"javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": true
34
}

lib/rules/html-indent.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -483,9 +483,12 @@ function create (context) {
483483

484484
VExpressionContainer (node) {
485485
if (node.expression != null && node.range[0] !== node.expression.range[0]) {
486-
const baseToken = template.getFirstToken(node)
486+
const startQuoteToken = template.getFirstToken(node)
487+
const endQuoteToken = template.getLastToken(node)
487488
const childTokens = template.getTokens(node.expression)
488-
setOffset(childTokens, 1, baseToken)
489+
490+
setOffset(childTokens, 1, startQuoteToken)
491+
setOffset(endQuoteToken, 0, startQuoteToken)
489492
}
490493
},
491494

@@ -503,6 +506,13 @@ function create (context) {
503506
setOffset(rightToken, 1, inToken)
504507
},
505508

509+
VOnExpression (node) {
510+
const firstToken = template.getFirstToken(node)
511+
for (let i = 1; i < node.body.length; ++i) {
512+
setOffset(template.getFirstToken(node.body[i]), EXACT, firstToken)
513+
}
514+
},
515+
506516
VStartTag (node) {
507517
const openToken = template.getFirstToken(node)
508518
const closeToken = template.getLastToken(node)
@@ -959,6 +969,7 @@ function create (context) {
959969
const indents = []
960970
let comments = []
961971
let tokensOnSameLine = []
972+
let shouldSkip = false
962973

963974
// Set the base indent.
964975
indents[node.loc.start.line] = 0
@@ -972,6 +983,8 @@ function create (context) {
972983
console.log(JSON.stringify(sourceCode.getText(token)), 'is unknown.')
973984
} else if (offsetInfo.offset === 0) {
974985
console.log(JSON.stringify(sourceCode.getText(token)), 'is the same as', JSON.stringify(sourceCode.getText(offsetInfo.baseToken)))
986+
} else if (offsetInfo.offset === EXACT) {
987+
console.log(JSON.stringify(sourceCode.getText(token)), 'is the exactly same as', JSON.stringify(sourceCode.getText(offsetInfo.baseToken)))
975988
} else {
976989
console.log(JSON.stringify(sourceCode.getText(token)), 'is', offsetInfo.offset, 'offset from', JSON.stringify(sourceCode.getText(offsetInfo.baseToken)))
977990
}
@@ -980,10 +993,14 @@ function create (context) {
980993
if (tokensOnSameLine.length === 0 || last(tokensOnSameLine).loc.start.line === token.loc.start.line) {
981994
tokensOnSameLine.push(token)
982995
} else if (tokensOnSameLine.every(isComment)) {
983-
Array.prototype.push.apply(comments, tokensOnSameLine) // push all.
996+
comments.push(tokensOnSameLine[0])
997+
shouldSkip = (last(tokensOnSameLine).loc.end.line === token.loc.start.line)
984998
tokensOnSameLine = [token]
985999
} else {
986-
validate(tokensOnSameLine, comments, indents)
1000+
if (!shouldSkip) {
1001+
validate(tokensOnSameLine, comments, indents)
1002+
}
1003+
shouldSkip = (last(tokensOnSameLine).loc.end.line === token.loc.start.line)
9871004
tokensOnSameLine = [token]
9881005
comments = []
9891006
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
},
4747
"dependencies": {
4848
"requireindex": "^1.1.0",
49-
"vue-eslint-parser": "2.0.0-beta.6"
49+
"vue-eslint-parser": "^2.0.0-beta.7"
5050
},
5151
"devDependencies": {
5252
"@types/node": "^4.2.16",

tests/lib/rules/html-indent.js

Lines changed: 127 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ function unIndent (strings) {
3535
// ------------------------------------------------------------------------------
3636

3737
const tester = new RuleTester({
38-
parser: 'vue-eslint-parser'
38+
parser: 'vue-eslint-parser',
39+
parserOptions: {
40+
ecmaVersion: 2015
41+
}
3942
})
4043

4144
tester.run('html-indent', rule, {
@@ -55,7 +58,7 @@ tester.run('html-indent', rule, {
5558
=
5659
></div>
5760
</template>
58-
`,
61+
`,
5962
unIndent`
6063
<template>
6164
<div a="a"
@@ -69,7 +72,50 @@ tester.run('html-indent', rule, {
6972
=
7073
></div>
7174
</template>
72-
`
75+
`,
76+
unIndent`
77+
<template>
78+
<div a="
79+
a" b="b"></div>
80+
</template>
81+
`,
82+
83+
// VExpressionContainer
84+
unIndent`
85+
<template>
86+
<div
87+
:foo="
88+
value
89+
"
90+
></div>
91+
</template>
92+
`,
93+
94+
// VForExpression
95+
unIndent`
96+
<template>
97+
<div
98+
v-for="
99+
x
100+
in
101+
xs
102+
"
103+
></div>
104+
<div
105+
v-for="
106+
(
107+
x
108+
,
109+
y
110+
,
111+
z
112+
)
113+
of
114+
xs
115+
"
116+
></div>
117+
</template>
118+
`
73119
],
74120
invalid: [
75121
// VAttribute
@@ -94,6 +140,84 @@ tester.run('html-indent', rule, {
94140
errors: [
95141
{ message: 'Expected indentation of 8 spaces but found 6 spaces.', line: 3 }
96142
]
143+
},
144+
145+
// VEndTag
146+
{
147+
code: unIndent`
148+
<template>
149+
</template
150+
`,
151+
errors: [
152+
{ message: 'Expected indentation of 0 spaces but found 2 spaces.', line: 2 }
153+
]
154+
},
155+
156+
// VExpressionContainer
157+
{
158+
code: unIndent`
159+
<template>
160+
<div
161+
:a="
162+
value
163+
"
164+
:b=
165+
value
166+
:c=
167+
'value'
168+
>
169+
{{
170+
value
171+
}}
172+
</div>
173+
</template>
174+
`,
175+
errors: [
176+
{ message: 'Expected indentation of 12 spaces but found 10 spaces.', line: 4 },
177+
{ message: 'Expected indentation of 8 spaces but found 6 spaces.', line: 5 },
178+
{ message: 'Expected indentation of 12 spaces but found 10 spaces.', line: 7 },
179+
{ message: 'Expected indentation of 12 spaces but found 10 spaces.', line: 9 },
180+
{ message: 'Expected indentation of 12 spaces but found 10 spaces.', line: 12 },
181+
{ message: 'Expected indentation of 8 spaces but found 6 spaces.', line: 13 }
182+
]
183+
},
184+
185+
// VForExpression
186+
{
187+
code: unIndent`
188+
<template>
189+
<div
190+
v-for="
191+
x
192+
in
193+
xs
194+
"
195+
></div>
196+
<div
197+
v-for="
198+
(
199+
x
200+
,
201+
y
202+
,
203+
z
204+
)
205+
of
206+
xs
207+
"
208+
></div>
209+
</template>
210+
`,
211+
errors: [
212+
{ message: 'Expected indentation of 12 spaces but found 10 spaces.', line: 4 },
213+
{ message: 'Expected indentation of 16 spaces but found 10 spaces.', line: 5 },
214+
{ message: 'Expected indentation of 20 spaces but found 10 spaces.', line: 6 },
215+
{ message: 'Expected indentation of 12 spaces but found 10 spaces.', line: 11 },
216+
{ message: 'Expected indentation of 16 spaces but found 10 spaces.', line: 12 },
217+
{ message: 'Expected indentation of 12 spaces but found 10 spaces.', line: 17 },
218+
{ message: 'Expected indentation of 16 spaces but found 10 spaces.', line: 18 },
219+
{ message: 'Expected indentation of 20 spaces but found 10 spaces.', line: 19 }
220+
]
97221
}
98222
]
99223
})

0 commit comments

Comments
 (0)