From ad100fd367f33f22be12c9a7ef95528f72828b95 Mon Sep 17 00:00:00 2001 From: David Greenspan Date: Mon, 7 Mar 2016 14:35:42 -0800 Subject: [PATCH] Fix: overindent in VariableDeclarator parens or brackets (fixes #5492) --- lib/rules/indent.js | 2 +- tests/lib/rules/indent.js | 24 +++++++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/rules/indent.js b/lib/rules/indent.js index 1238ee4d68e..3b35b7f8e98 100644 --- a/lib/rules/indent.js +++ b/lib/rules/indent.js @@ -444,7 +444,7 @@ module.exports = function(context) { nodeIndent = getNodeIndent(effectiveParent); if (parentVarNode && parentVarNode.loc.start.line !== node.loc.start.line) { if (parent.type !== "VariableDeclarator" || parentVarNode === parentVarNode.parent.declarations[0]) { - if (parentVarNode.loc.start.line === effectiveParent.loc.start.line) { + if (parent.type === "VariableDeclarator" && parentVarNode.loc.start.line === effectiveParent.loc.start.line) { nodeIndent = nodeIndent + (indentSize * options.VariableDeclarator[parentVarNode.parent.kind]); } else if ( parent.type === "ObjectExpression" || diff --git a/tests/lib/rules/indent.js b/tests/lib/rules/indent.js index 5438266f406..978212178d9 100644 --- a/tests/lib/rules/indent.js +++ b/tests/lib/rules/indent.js @@ -760,12 +760,30 @@ ruleTester.run("indent", rule, { { code: "var items = [\n" + - " {\n" + - " foo: 'bar'\n" + - " }\n" + + " {\n" + + " foo: 'bar'\n" + + " }\n" + "];\n", options: [2, {"VariableDeclarator": 2}] }, + { + code: + "const a = 1,\n" + + " b = 2;\n" + + "const items1 = [\n" + + " {\n" + + " foo: 'bar'\n" + + " }\n" + + "];\n" + + "const items2 = Items(\n" + + " {\n" + + " foo: 'bar'\n" + + " }\n" + + ");\n", + options: [2, {"VariableDeclarator": 3}], + parserOptions: { ecmaVersion: 6 } + + }, { code: "const geometry = 2,\n" +