Skip to content

Commit

Permalink
Fix: indent regression with function calls (fixes #7732, fixes #7733)…
Browse files Browse the repository at this point in the history
… (#7734)
  • Loading branch information
not-an-aardvark authored and kaicataldo committed Dec 12, 2016
1 parent ab246dd commit 0ad4d33
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/rules/indent.js
Expand Up @@ -737,8 +737,12 @@ module.exports = {
} else if (parent.type === "CallExpression" || parent.type === "NewExpression") {
if (typeof options.CallExpression.arguments === "number") {
nodeIndent += options.CallExpression.arguments * indentSize;
} else if (parent.arguments.indexOf(node) !== -1) {
nodeIndent = parent.arguments[0].loc.start.column;
} else if (options.CallExpression.arguments === "first") {
if (parent.arguments.indexOf(node) !== -1) {
nodeIndent = parent.arguments[0].loc.start.column;
}
} else {
nodeIndent += indentSize;
}
} else if (parent.type === "LogicalExpression" || parent.type === "ArrowFunctionExpression") {
nodeIndent += indentSize;
Expand Down
44 changes: 44 additions & 0 deletions tests/lib/rules/indent.js
Expand Up @@ -1863,6 +1863,50 @@ ruleTester.run("indent", rule, {
" [\n" +
" ]()",
options: [4, {CallExpression: {arguments: "first"}, ArrayExpression: "first"}]
},

// https://github.com/eslint/eslint/issues/7732
{
code:
"const lambda = foo => {\n" +
" Object.assign({},\n" +
" filterName,\n" +
" {\n" +
" display\n" +
" }\n" +
" );" +
"}",
options: [2, {ObjectExpression: 1}],
parserOptions: { ecmaVersion: 6 }
},
{
code:
"const lambda = foo => {\n" +
" Object.assign({},\n" +
" filterName,\n" +
" {\n" +
" display\n" +
" }\n" +
" );" +
"}",
options: [2, {ObjectExpression: "first"}],
parserOptions: { ecmaVersion: 6 }
},

// https://github.com/eslint/eslint/issues/7733
{
code:
"var foo = function() {\n" +
"\twindow.foo('foo',\n" +
"\t\t{\n" +
"\t\t\tfoo: 'bar'," +
"\t\t\tbar: {\n" +
"\t\t\t\tfoo: 'bar'\n" +
"\t\t\t}\n" +
"\t\t}\n" +
"\t);\n" +
"}",
options: ["tab"]
}
],
invalid: [
Expand Down

0 comments on commit 0ad4d33

Please sign in to comment.