Skip to content

Commit

Permalink
Fix: indent rule crash on sparse array with object (fixes #7959) (#7960)
Browse files Browse the repository at this point in the history
  • Loading branch information
gyandeeps authored and btmills committed Jan 23, 2017
1 parent a7bd66a commit b9e5b68
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/indent.js
Expand Up @@ -729,7 +729,7 @@ module.exports = {
} else if (parent.type === "ObjectExpression" || parent.type === "ArrayExpression") {
const parentElements = node.parent.type === "ObjectExpression" ? node.parent.properties : node.parent.elements;

if (parentElements[0].loc.start.line === parent.loc.start.line && parentElements[0].loc.end.line !== parent.loc.start.line) {
if (parentElements[0] && parentElements[0].loc.start.line === parent.loc.start.line && parentElements[0].loc.end.line !== parent.loc.start.line) {

/*
* If the first element of the array spans multiple lines, don't increase the expected indentation of the rest.
Expand Down
10 changes: 10 additions & 0 deletions tests/lib/rules/indent.js
Expand Up @@ -65,6 +65,16 @@ ruleTester.run("indent", rule, {
");\n",
options: [2]
},
{
code:
"var a = [\n" +
" , /*{\n" +
" }, */{\n" +
" name: 'foo',\n" +
" }\n" +
"];\n",
options: [2]
},
{
code:
"bridge.callHandler(\n" +
Expand Down

0 comments on commit b9e5b68

Please sign in to comment.