Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix: indent crash on sparse arrays with "off" option (fixes #9157) (#…
  • Loading branch information
not-an-aardvark committed Aug 29, 2017
1 parent c147b97 commit 5ab0434
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/rules/indent.js
Expand Up @@ -802,10 +802,19 @@ module.exports = {
return;
}
elements.forEach((element, index) => {
if (!element) {

// Skip holes in arrays
return;
}
if (offset === "off") {

// Ignore the first token of every element if the "off" option is used
offsets.ignoreToken(getFirstToken(element));
}
if (index === 0 || !element) {

// Offset the following elements correctly relative to the first element
if (index === 0) {
return;
}
if (offset === "first" && tokenInfo.isFirstTokenOfLine(getFirstToken(element))) {
Expand Down
4 changes: 4 additions & 0 deletions tests/lib/rules/indent.js
Expand Up @@ -3222,6 +3222,10 @@ ruleTester.run("indent", rule, {
code: "[,]",
options: [2, { ArrayExpression: "first" }]
},
{
code: "[,]",
options: [2, { ArrayExpression: "off" }]
},
{
code: unIndent`
[
Expand Down

0 comments on commit 5ab0434

Please sign in to comment.