Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix: incorrect indent check for array property access (fixes #7484) (
  • Loading branch information
not-an-aardvark authored and kaicataldo committed Oct 31, 2016
1 parent 8a71d4a commit 2012258
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
14 changes: 3 additions & 11 deletions lib/rules/indent.js
Expand Up @@ -695,19 +695,11 @@ module.exports = {
// TODO - come up with a better strategy in future
if (isNodeFirstInLine(node)) {
const parent = node.parent;
let effectiveParent = parent;

if (parent.type === "MemberExpression") {
if (isNodeFirstInLine(parent)) {
effectiveParent = parent.parent.parent;
} else {
effectiveParent = parent.parent;
}
}
nodeIndent = getNodeIndent(effectiveParent).goodChar;
nodeIndent = getNodeIndent(parent).goodChar;
if (parentVarNode && parentVarNode.loc.start.line !== node.loc.start.line) {
if (parent.type !== "VariableDeclarator" || parentVarNode === parentVarNode.parent.declarations[0]) {
if (parent.type === "VariableDeclarator" && parentVarNode.loc.start.line === effectiveParent.loc.start.line) {
if (parent.type === "VariableDeclarator" && parentVarNode.loc.start.line === parent.loc.start.line) {
nodeIndent = nodeIndent + (indentSize * options.VariableDeclarator[parentVarNode.parent.kind]);
} else if (
parent.type === "ObjectExpression" ||
Expand All @@ -720,7 +712,7 @@ module.exports = {
nodeIndent = nodeIndent + indentSize;
}
}
} else if (!parentVarNode && !isFirstArrayElementOnSameLine(parent) && effectiveParent.type !== "MemberExpression" && effectiveParent.type !== "ExpressionStatement" && effectiveParent.type !== "AssignmentExpression" && effectiveParent.type !== "Property") {
} else if (!parentVarNode && !isFirstArrayElementOnSameLine(parent) && parent.type !== "MemberExpression" && parent.type !== "ExpressionStatement" && parent.type !== "AssignmentExpression" && parent.type !== "Property") {
nodeIndent = nodeIndent + indentSize;
}

Expand Down
12 changes: 12 additions & 0 deletions tests/lib/rules/indent.js
Expand Up @@ -1698,6 +1698,18 @@ ruleTester.run("indent", rule, {
" new Car('!')\n" +
");",
options: [2, {CallExpression: {arguments: 4}}]
},

// https://github.com/eslint/eslint/issues/7484
{
code:
"var foo = function() {\n" +
" return bar(\n" +
" [{\n" +
" }].concat(baz)\n" +
" );\n" +
"};",
options: [2]
}
],
invalid: [
Expand Down

0 comments on commit 2012258

Please sign in to comment.