Skip to content

Commit

Permalink
Update: fix parenthesized CallExpression indentation (fixes #8790) (#…
Browse files Browse the repository at this point in the history
…8802)

This fixes a bug in the `indent` rule where the arguments of a call expression were aligned offset the last token of the callee, even when the callee was parenthesized. Instead, the rule should offset from the closing paren in those cases.
  • Loading branch information
not-an-aardvark committed Jun 28, 2017
1 parent be8d354 commit 85c9327
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/indent.js
Expand Up @@ -896,7 +896,7 @@ module.exports = {

parameterParens.add(openingParen);
parameterParens.add(closingParen);
offsets.matchIndentOf(sourceCode.getLastToken(node.callee), openingParen);
offsets.matchIndentOf(sourceCode.getTokenBefore(openingParen), openingParen);

addElementListIndent(node.arguments, openingParen, closingParen, options.CallExpression.arguments);
}
Expand Down
78 changes: 78 additions & 0 deletions tests/lib/rules/indent.js
Expand Up @@ -2160,6 +2160,33 @@ ruleTester.run("indent", rule, {
`,
options: [2]
},
{
code: unIndent`
(
foo
)(
bar
)
`
},
{
code: unIndent`
(() =>
foo
)(
bar
)
`
},
{
code: unIndent`
(() => {
foo();
})(
bar
)
`
},
{

// Don't lint the indentation of the first token after a :
Expand Down Expand Up @@ -8009,6 +8036,57 @@ ruleTester.run("indent", rule, {
`,
errors: expectedErrors([[4, 4, 8, "Identifier"], [5, 0, 4, "Punctuator"]])
},
{
code: unIndent`
(
foo
)(
bar
)
`,
output: unIndent`
(
foo
)(
bar
)
`,
errors: expectedErrors([[4, 4, 8, "Identifier"], [5, 0, 4, "Punctuator"]])
},
{
code: unIndent`
(() =>
foo
)(
bar
)
`,
output: unIndent`
(() =>
foo
)(
bar
)
`,
errors: expectedErrors([[4, 4, 8, "Identifier"], [5, 0, 4, "Punctuator"]])
},
{
code: unIndent`
(() => {
foo();
})(
bar
)
`,
output: unIndent`
(() => {
foo();
})(
bar
)
`,
errors: expectedErrors([[4, 4, 8, "Identifier"], [5, 0, 4, "Punctuator"]])
},
{
code: unIndent`
foo.
Expand Down

0 comments on commit 85c9327

Please sign in to comment.