Skip to content

Commit bc0dda9

Browse files
author
qkdreyer
committed
Fixed vuejs#407
1 parent 4c25403 commit bc0dda9

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

lib/utils/indent-common.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -1446,23 +1446,24 @@ module.exports.defineVisitor = function create (context, tokenStore, defaultOpti
14461446
// Process semicolons.
14471447
':statement' (node) {
14481448
const info = offsets.get(tokenStore.getFirstToken(node))
1449-
const lastToken = tokenStore.getLastToken(node)
14501449
if (info == null) {
14511450
return
14521451
}
1453-
if (isSemicolon(lastToken)) {
1454-
offsets.set(lastToken, info)
1455-
}
14561452

14571453
// Set to the semicolon of the previous token for semicolon-free style.
14581454
// E.g.,
14591455
// foo
14601456
// ;[1,2,3].forEach(f)
1461-
const prevToken = tokenStore.getTokenBefore(node)
1462-
if (isSemicolon(prevToken)) {
1463-
const prevPrevToken = tokenStore.getTokenBefore(prevToken)
1464-
if (prevPrevToken == null || prevToken.loc.end.line !== prevPrevToken.loc.start.line) {
1465-
offsets.set(prevToken, info)
1457+
const tokens = [
1458+
tokenStore.getTokenBefore(node),
1459+
tokenStore.getLastToken(node)
1460+
].filter(isSemicolon)
1461+
1462+
// Set offsets if the semicolon is at beginning of line.
1463+
for (const token of tokens) {
1464+
const prevToken = tokenStore.getTokenBefore(token)
1465+
if (prevToken == null || token.loc.end.line !== prevToken.loc.start.line) {
1466+
offsets.set(token, info)
14661467
}
14671468
}
14681469
},

tests/lib/rules/script-indent.js

+23
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,29 @@ tester.run('script-indent', rule, loadPatterns(
187187
]
188188
},
189189

190+
// Expected Indentation
191+
{
192+
code: unIndent`
193+
export default {
194+
foo() {
195+
bar = 1;
196+
return bar;
197+
},
198+
};
199+
`,
200+
output: unIndent`
201+
export default {
202+
foo() {
203+
bar = 1;
204+
return bar;
205+
},
206+
};
207+
`,
208+
errors: [
209+
{ message: 'Expected indentation of 4 spaces but found 6 spaces.', line: 4 }
210+
]
211+
},
212+
190213
// A mix of spaces and tabs.
191214
{
192215
code: unIndent`

0 commit comments

Comments
 (0)