Skip to content

Commit

Permalink
Update: fix indent behavior on template literal arguments (fixes #9061)…
Browse files Browse the repository at this point in the history
… (#9820)
  • Loading branch information
not-an-aardvark committed Jan 10, 2018
1 parent ea1b15d commit 133336e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
3 changes: 2 additions & 1 deletion lib/rules/indent.js
Expand Up @@ -442,6 +442,7 @@ class OffsetStorage {
const offset = (
offsetInfo.from &&
offsetInfo.from.loc.start.line === token.loc.start.line &&
!/^\s*?\n/.test(token.value) &&
!offsetInfo.force
) ? 0 : offsetInfo.offset * this._indentSize;

Expand Down Expand Up @@ -836,7 +837,7 @@ module.exports = {
const previousElement = elements[index - 1];
const firstTokenOfPreviousElement = previousElement && getFirstToken(previousElement);

if (previousElement && sourceCode.getLastToken(previousElement).loc.start.line > startToken.loc.end.line) {
if (previousElement && sourceCode.getLastToken(previousElement).loc.end.line > startToken.loc.end.line) {
offsets.setDesiredOffsets(element.range, firstTokenOfPreviousElement, 0);
}
}
Expand Down
28 changes: 17 additions & 11 deletions tests/lib/rules/indent.js
Expand Up @@ -2830,6 +2830,13 @@ ruleTester.run("indent", rule, {
`,
options: [2]
},
unIndent`
foo(\`
bar
\`, {
baz: 1
});
`,
unIndent`
function foo() {
\`foo\${bar}baz\${
Expand Down Expand Up @@ -3856,21 +3863,20 @@ ruleTester.run("indent", rule, {
unIndent`
foo(\`foo
\`, {
ok: true
},
{
ok: false
}
)
ok: true
},
{
ok: false
})
`,
unIndent`
foo(tag\`foo
\`, {
ok: true
},
{
ok: false
}
ok: true
},
{
ok: false
}
)
`,

Expand Down

0 comments on commit 133336e

Please sign in to comment.