Skip to content

Commit

Permalink
Fix: multiline destructure errors (fixes eslint#8729)
Browse files Browse the repository at this point in the history
  • Loading branch information
not-an-aardvark authored and VictorHom committed Jun 17, 2017
1 parent ab8b016 commit 49aba89
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/rules/indent.js
Expand Up @@ -816,7 +816,6 @@ module.exports = {

offsets.ignoreToken(operator);
offsets.ignoreToken(tokensAfterOperator[0]);
offsets.setDesiredOffset(tokensAfterOperator[0], sourceCode.getFirstToken(node), 1);
offsets.setDesiredOffsets(tokensAfterOperator, tokensAfterOperator[0], 1);
}

Expand Down Expand Up @@ -882,6 +881,13 @@ module.exports = {

// We only want to handle parens around expressions, so exclude parentheses that are in function parameters and function call arguments.
if (!parameterParens.has(leftParen) && !parameterParens.has(rightParen)) {
const parenthesizedTokens = new Set(sourceCode.getTokensBetween(leftParen, rightParen));

parenthesizedTokens.forEach(token => {
if (!parenthesizedTokens.has(offsets.getFirstDependency(token))) {
offsets.setDesiredOffset(token, leftParen, 1);
}
});
offsets.setDesiredOffset(sourceCode.getTokenAfter(leftParen), leftParen, 1);
}

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

// https://github.com/eslint/eslint/issues/7233
Expand Down Expand Up @@ -2563,6 +2585,40 @@ ruleTester.run("indent", rule, {
`,
options: [4]
},
{
code: unIndent`
[
] || [
]
`
},
{
code: unIndent`
(
[
] || [
]
)
`
},
{
code: unIndent`
1
+ (
1
)
`
},
{
code: unIndent`
(
foo && (
bar ||
baz
)
)
`
},
{
code: unIndent`
var foo =
Expand Down Expand Up @@ -2983,6 +3039,41 @@ ruleTester.run("indent", rule, {
`,
options: [4, { flatTernaryExpressions: true }]
},
{
code: unIndent`
function wrap() {
return (
foo ? bar :
baz ? qux :
foobar ? boop :
/*else*/ beep
)
}
`,
options: [4, { flatTernaryExpressions: true }]
},
{
code: unIndent`
function wrap() {
return foo
? bar
: baz
}
`,
options: [4, { flatTernaryExpressions: true }]
},
{
code: unIndent`
function wrap() {
return (
foo
? bar
: baz
)
}
`,
options: [4, { flatTernaryExpressions: true }]
},
{
code: unIndent`
foo(
Expand Down Expand Up @@ -7053,6 +7144,34 @@ ruleTester.run("indent", rule, {
options: [4],
errors: expectedErrors([2, 4, 8, "Identifier"])
},
{
code: unIndent`
[
] || [
]
`,
output: unIndent`
[
] || [
]
`,
errors: expectedErrors([3, 0, 4, "Punctuator"])
},
{
code: unIndent`
1
+ (
1
)
`,
output: unIndent`
1
+ (
1
)
`,
errors: expectedErrors([[3, 4, 8, "Numeric"], [4, 0, 4, "Punctuator"]])
},

// Template curlies
{
Expand Down

0 comments on commit 49aba89

Please sign in to comment.