New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add handling of lone commas when destructuring arrays #12772
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -585,19 +585,6 @@ ruleTester.run("comma-style", rule, { | |
}], | ||
errors: [{ messageId: "expectedCommaFirst" }] | ||
}, | ||
{ | ||
code: "var foo = [\n(bar\n)\n,\nbaz\n];", | ||
output: "var foo = [\n(bar\n),\nbaz\n];", | ||
errors: [{ | ||
messageId: "unexpectedLineBeforeAndAfterComma", | ||
type: "Identifier" | ||
}] | ||
}, | ||
Comment on lines
-588
to
-595
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This particular test doesn't have empty elements. If it's failing, then the change might be incorrect since it modifies behavior for arrays/patterns that don't have empty elements. A simplified example, this time with an array pattern that doesn't have empty elements: /*eslint comma-style: ["error", "last", {
"exceptions": { "ArrayPattern": false }
}]*/
var [
foo
,
bar] = []; This is invalid code by this rule in the actual version - Online Demo After this change as it's implemented at the moment, this would be a valid code (I think, it would be nice to add a test case). Is this the desired new behavior, i.e., should we ignore any commas on separate lines? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If "comma-style" is enabled, that comma in a new line belongs either with |
||
{ | ||
code: "[(foo),\n,\nbar]", | ||
output: "[(foo),,\nbar]", | ||
errors: [{ messageId: "unexpectedLineBeforeAndAfterComma" }] | ||
}, | ||
{ | ||
code: "new Foo(a\n,b);", | ||
output: "new Foo(a,\nb);", | ||
|
@@ -608,11 +595,6 @@ ruleTester.run("comma-style", rule, { | |
}], | ||
errors: [{ messageId: "expectedCommaLast" }] | ||
}, | ||
{ | ||
code: "[\n[foo(3)],\n,\nbar\n];", | ||
output: "[\n[foo(3)],,\nbar\n];", | ||
errors: [{ messageId: "unexpectedLineBeforeAndAfterComma" }] | ||
}, | ||
{ | ||
|
||
// https://github.com/eslint/eslint/issues/10632 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Place holder in case we may want to report other things later, based on new options.