Skip to content
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

Error reported when destructuring with comments in place of skipped variables. #1244

Closed
wjhir opened this issue Feb 1, 2019 · 2 comments

Comments

@wjhir
Copy link

commented Feb 1, 2019

Standard OS node npm
12.0.1 Windows 10 10.2.0 5.6.0

When destructuring an array and skipping unused indices, I like to include a comment to annotate what's being skipped. When the destructuring is a single line and there is a comment either before the first item or after the last, it causes an unexpected error: Expected consistent spacing (standard/array-bracket-even-spacing). This happens whether or not the brackets are padded with spaces. The error does not occur when the destructuring is split over multiple lines.

Examples:

const [/* match */, $1, $2] = regex.exec(str)
const [ match, $1 /* $2 */ ] = regex.exec(str)
const [/* match */, $1 /* $2 */] = regex.exec(str)
const [ /* comment */ match, $1 ] = regex.exec(str)
const [/* comment */ match /* $1 */] = regex.exec(str)
@stale

This comment has been minimized.

Copy link

commented May 30, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the stale label May 30, 2019

@stale stale bot closed this Jun 6, 2019

@feross

This comment has been minimized.

Copy link
Member

commented Aug 6, 2019

In standard 13 we settled on disallowing spaces in arrays.

But you're right, that comments causing the rule to trigger is not ideal. Unfortunately, there is no way to tell ESLint to not treat this as an error. If you'd like to get this fixed, could you open an issue on the ESLint repo and see what the team thinks about adding an exception to allow a space when there's an inline /* */ style comment present. If you do that, please link it from this issue and I'll re-open this issue.

Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants
You can’t perform that action at this time.