Skip to content

Commit

Permalink
Update: fix indent errors on multiline destructure (fixes #8729) (#8756)
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorHom authored and not-an-aardvark committed Jun 20, 2017
1 parent 3608f06 commit 9851288
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/rules/indent.js
Expand Up @@ -658,7 +658,6 @@ module.exports = {
while (astUtils.isOpeningParenToken(token) && token !== startToken) {
token = sourceCode.getTokenBefore(token);
}

return sourceCode.getTokenAfter(token);
}

Expand All @@ -675,7 +674,6 @@ module.exports = {
if (offset === "first" && elements.length && !elements[0]) {
return;
}

elements.forEach((element, index) => {
if (offset === "off") {
offsets.ignoreToken(getFirstToken(element));
Expand Down Expand Up @@ -1242,6 +1240,7 @@ module.exports = {
offsets.ignoreToken(equalOperator);
offsets.ignoreToken(tokenAfterOperator);
offsets.matchIndentOf(equalOperator, tokenAfterOperator);
offsets.matchIndentOf(sourceCode.getFirstToken(node), equalOperator);
}
},

Expand Down
70 changes: 70 additions & 0 deletions tests/lib/rules/indent.js
Expand Up @@ -2026,6 +2026,58 @@ ruleTester.run("indent", rule, {
`,
options: [2]
},
{
code: unIndent`
const {
a
}
=
{
a: 1
}
`,
options: [2]
},
{
code: unIndent`
const {
a
} = {
a: 1
}
`,
options: [2]
},
{
code: unIndent`
const
{
a
} = {
a: 1
};
`,
options: [2]
},
{
code: unIndent`
const
foo = {
bar: 1
}
`,
options: [2]
},
{
code: unIndent`
const [
a
] = [
1
]
`,
options: [2]
},
{

// https://github.com/eslint/eslint/issues/7233
Expand Down Expand Up @@ -6834,6 +6886,24 @@ ruleTester.run("indent", rule, {
options: [2],
errors: expectedErrors([[2, 2, 0, "Identifier"], [4, 2, 4, "Identifier"], [5, 2, 6, "Identifier"], [6, 0, 2, "Punctuator"]])
},
{
code: unIndent`
const {
a
} = {
a: 1
}
`,
output: unIndent`
const {
a
} = {
a: 1
}
`,
options: [2],
errors: expectedErrors([[4, 2, 4, "Identifier"], [5, 0, 2, "Punctuator"]])
},
{
code: unIndent`
var foo = [
Expand Down

0 comments on commit 9851288

Please sign in to comment.