Skip to content

Commit

Permalink
Fix: ignore lines with empty elements (fixes #12756) (#14837)
Browse files Browse the repository at this point in the history
* Fix: ignore lines with empty elements (fixes #12756)

* Fix: ignore  lines with empty elements (fixes #12756)

* Fix: ignore  lines with empty elements (fixes #12756)
  • Loading branch information
boutahlilsoufiane committed Jul 30, 2021
1 parent 1bfbefd commit d7dc07a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/rules/comma-style.js
Expand Up @@ -216,6 +216,8 @@ module.exports = {
previousItemToken = tokenAfterItem
? sourceCode.getTokenBefore(tokenAfterItem)
: sourceCode.ast.tokens[sourceCode.ast.tokens.length - 1];
} else {
previousItemToken = currentItemToken;
}
});

Expand Down
38 changes: 38 additions & 0 deletions tests/lib/rules/comma-style.js
Expand Up @@ -233,7 +233,45 @@ ruleTester.run("comma-style", rule, {
NewExpression: true
}
}]
},
"var foo = [\n , \n 1, \n 2 \n];",
{
code: "const [\n , \n , \n a, \n b, \n] = arr;",
options: ["last", {
exceptions: {
ArrayPattern: false
}
}],
parserOptions: {
ecmaVersion: 6
}
},
{
code: "const [\n ,, \n a, \n b, \n] = arr;",
options: ["last", {
exceptions: {
ArrayPattern: false
}
}],
parserOptions: {
ecmaVersion: 6
}
},
{
code: "const arr = [\n 1 \n , \n ,2 \n]",
options: ["first"],
parserOptions: {
ecmaVersion: 6
}
},
{
code: "const arr = [\n ,'fifi' \n]",
options: ["first"],
parserOptions: {
ecmaVersion: 6
}
}

],

invalid: [
Expand Down

0 comments on commit d7dc07a

Please sign in to comment.