Skip to content

Fixed #407 #409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions lib/utils/indent-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -1446,23 +1446,24 @@ module.exports.defineVisitor = function create (context, tokenStore, defaultOpti
// Process semicolons.
':statement' (node) {
const info = offsets.get(tokenStore.getFirstToken(node))
const lastToken = tokenStore.getLastToken(node)
if (info == null) {
return
}
if (isSemicolon(lastToken)) {
offsets.set(lastToken, info)
}

// Set to the semicolon of the previous token for semicolon-free style.
// E.g.,
// foo
// ;[1,2,3].forEach(f)
const prevToken = tokenStore.getTokenBefore(node)
if (isSemicolon(prevToken)) {
const prevPrevToken = tokenStore.getTokenBefore(prevToken)
if (prevPrevToken == null || prevToken.loc.end.line !== prevPrevToken.loc.start.line) {
offsets.set(prevToken, info)
const tokens = [
tokenStore.getTokenBefore(node),
tokenStore.getLastToken(node)
].filter(isSemicolon)

// Set offsets if the semicolon is at beginning of line.
for (const token of tokens) {
const prevToken = tokenStore.getTokenBefore(token)
if (prevToken == null || token.loc.end.line !== prevToken.loc.start.line) {
offsets.set(token, info)
}
}
},
Expand Down
23 changes: 23 additions & 0 deletions tests/lib/rules/script-indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,29 @@ tester.run('script-indent', rule, loadPatterns(
]
},

// Expected Indentation
{
code: unIndent`
export default {
foo() {
bar = 1;
return bar;
},
};
`,
output: unIndent`
export default {
foo() {
bar = 1;
return bar;
},
};
`,
errors: [
{ message: 'Expected indentation of 4 spaces but found 6 spaces.', line: 4 }
]
},

// A mix of spaces and tabs.
{
code: unIndent`
Expand Down