Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update: don't indent leading semi in line after import (fixes #11082) (
  • Loading branch information
g-plane authored and not-an-aardvark committed Nov 18, 2018
1 parent e18c827 commit 3025cdd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/rules/indent.js
Expand Up @@ -1229,9 +1229,13 @@ module.exports = {
}

const fromToken = sourceCode.getLastToken(node, token => token.type === "Identifier" && token.value === "from");
const sourceToken = sourceCode.getLastToken(node, token => token.type === "String");
const semiToken = sourceCode.getLastToken(node, token => token.type === "Punctuator" && token.value === ";");

if (fromToken) {
offsets.setDesiredOffsets([fromToken.range[0], node.range[1]], sourceCode.getFirstToken(node), 1);
const end = semiToken && semiToken.range[1] === sourceToken.range[1] ? node.range[1] : sourceToken.range[1];

offsets.setDesiredOffsets([fromToken.range[0], end], sourceCode.getFirstToken(node), 1);
}
},

Expand Down
11 changes: 11 additions & 0 deletions tests/lib/rules/indent.js
Expand Up @@ -271,6 +271,17 @@ ruleTester.run("indent", rule, {
`,
options: [4]
},
{

// https://github.com/eslint/eslint/issues/11802
code: unIndent`
import foo from "foo"
;(() => {})()
`,
options: [4],
parserOptions: { sourceType: "module" }
},
{
code: unIndent`
function test() {
Expand Down

0 comments on commit 3025cdd

Please sign in to comment.