Skip to content

Commit

Permalink
Update: indentation of comment followed by semicolon (fixes #12232)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaicataldo committed Sep 9, 2019
1 parent 460c5ad commit 0192f74
Show file tree
Hide file tree
Showing 2 changed files with 510 additions and 6 deletions.
26 changes: 20 additions & 6 deletions lib/rules/indent.js
Expand Up @@ -1588,15 +1588,9 @@ module.exports = {
return;
}

// If the token matches the expected expected indentation, don't report it.
if (validateTokenIndent(firstTokenOfLine, offsets.getDesiredIndent(firstTokenOfLine))) {
return;
}

if (astUtils.isCommentToken(firstTokenOfLine)) {
const tokenBefore = precedingTokens.get(firstTokenOfLine);
const tokenAfter = tokenBefore ? sourceCode.getTokenAfter(tokenBefore) : sourceCode.ast.tokens[0];

const mayAlignWithBefore = tokenBefore && !hasBlankLinesBetween(tokenBefore, firstTokenOfLine);
const mayAlignWithAfter = tokenAfter && !hasBlankLinesBetween(firstTokenOfLine, tokenAfter);

Expand All @@ -1607,6 +1601,26 @@ module.exports = {
) {
return;
}

/*
* If a comment precedes a line that begins with a semicolon token, align to that token, i.e.
*
* let foo
* // comment
* ;(async () => {})()
*/
if (tokenAfter && astUtils.isSemicolonToken(tokenAfter) && !astUtils.isTokenOnSameLine(firstTokenOfLine, tokenAfter)) {
offsets.setDesiredOffset(firstTokenOfLine, tokenAfter, 0);

if (validateTokenIndent(firstTokenOfLine, offsets.getDesiredIndent(tokenAfter))) {
return;
}
}
}

// If the token matches the expected indentation, don't report it.
if (validateTokenIndent(firstTokenOfLine, offsets.getDesiredIndent(firstTokenOfLine))) {
return;
}

// Otherwise, report the token/comment.
Expand Down

0 comments on commit 0192f74

Please sign in to comment.