From dab18611249ee1b950ab2dfd62401508f2189589 Mon Sep 17 00:00:00 2001 From: Teddy Katz Date: Fri, 9 Dec 2016 16:27:58 -0500 Subject: [PATCH] Fix: `indent` regression with function calls (fixes #7732, fixes #7733) --- lib/rules/indent.js | 8 +++++-- tests/lib/rules/indent.js | 44 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/lib/rules/indent.js b/lib/rules/indent.js index 48122eab1d3c..1c04febd5ea7 100644 --- a/lib/rules/indent.js +++ b/lib/rules/indent.js @@ -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; diff --git a/tests/lib/rules/indent.js b/tests/lib/rules/indent.js index 5024e33054cc..9a5f3da88589 100644 --- a/tests/lib/rules/indent.js +++ b/tests/lib/rules/indent.js @@ -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: [