8000 Fix: ignore lines with empty elements (fixes #12756) (#14837) · eslint/eslint@d7dc07a · GitHub
[go: up one dir, main page]

Skip to content

Commit d7dc07a

Browse files
Fix: ignore lines with empty elements (fixes #12756) (#14837)
* Fix: ignore lines with empty elements (fixes #12756) * Fix: ignore lines with empty elements (fixes #12756) * Fix: ignore lines with empty elements (fixes #12756)
1 parent 1bfbefd commit d7dc07a

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

lib/rules/comma-style.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ module.exports = {
216216
previousItemToken = tokenAfterItem
217217
? sourceCode.getTokenBefore(tokenAfterItem)
218218
: sourceCode.ast.tokens[sourceCode.ast.tokens.length - 1];
219+
} else {
220+
previousItemToken = currentItemToken;
219221
}
220222
});
221223

tests/lib/rules/comma-style.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,45 @@ ruleTester.run("comma-style", rule, {
233233
NewExpression: true
234234
}
235235
}]
236+
},
237+
"var foo = [\n , \n 1, \n 2 \n];",
238+
{
239+
code: "const [\n , \n , \n a, \n b, \n] = arr;",
240+
options: ["last", {
241+
exceptions: {
242+
ArrayPattern: false
243+
}
244+
}],
245+
parserOptions: {
246+
ecmaVersion: 6
247+
}
248+
},
249+
{
250+
code: "const [\n ,, \n a, \n b, \n] = arr;",
251+
options: ["last", {
252+
exceptions: {
253+
ArrayPattern: false
254+
}
255+
}],
256+
parserOptions: {
257+
ecmaVersion: 6
258+
}
259+
},
260+
{
261+
code: "const arr = [\n 1 \n , \n ,2 \n]",
262+
options: ["first"],
263+
parserOptions: {
264+
ecmaVersion: 6
265+
}
266+
},
267+
{
268+
code: "const arr = [\n ,'fifi' \n]",
269+
options: ["first"],
270+
parserOptions: {
271+
ecmaVersion: 6
272+
}
236273
}
274+
237275
],
238276

239277
invalid: [

0 commit comments

Comments
 (0)
0