Skip to content

Commit

Permalink
Fix: overindent in VariableDeclarator parens or brackets (fixes #5492)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgreensp committed Mar 7, 2016
1 parent bb8f470 commit ad100fd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/rules/indent.js
Expand Up @@ -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" ||
Expand Down
24 changes: 21 additions & 3 deletions tests/lib/rules/indent.js
Expand Up @@ -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" +
Expand Down

0 comments on commit ad100fd

Please sign in to comment.