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

comma-spacing conflicts with array-bracket-spacing #3392

Closed
lo1tuma opened this issue Aug 13, 2015 · 4 comments
Closed

comma-spacing conflicts with array-bracket-spacing #3392

lo1tuma opened this issue Aug 13, 2015 · 4 comments
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly rule Relates to ESLint's core rules

Comments

@lo1tuma
Copy link
Member

lo1tuma commented Aug 13, 2015

Problem description

Given the following config

{
    "env": {
        "es6": true
    },
    "ecmaFeatures": {
        "modules": true
    },
    "rules": {
        "comma-spacing": [ 2, { "before": false, "after": true } ],
        "array-bracket-spacing": [ 2, "always" ]
    }
}

and the following code:

const [ , a, ...rest ] = foo;

then the comma-spacing rule warns about an extra space before to first comma in the destructuring statement.

foo.js
  1:9  error  There should be no space before ','  comma-spacing

✖ 1 problem (1 error, 0 warnings)

when I remove the leading whitespace

const [, a, ...rest ] = foo;

then the array-bracket-spacing rule warns about a missing space after the opening bracket

foo.js
  1:7  error  A space is required after '['  array-bracket-spacing

✖ 1 problem (1 error, 0 warnings)

Same problem exist for array literals:

const foo = [ , 1, 2 ];
foo.js
  1:15  error  There should be no space before ','  comma-spacing

✖ 1 problem (1 error, 0 warnings)

I’m using ESLint version 1.1.0


Possible solution

I suggest that the comma-spacing rule should ignore null elements of an ArrayExpression or ArrayPattern.

@nzakas nzakas added bug ESLint is working incorrectly rule Relates to ESLint's core rules accepted There is consensus among the team that this change meets the criteria for inclusion labels Aug 13, 2015
@nzakas
Copy link
Member

nzakas commented Aug 13, 2015

Not sure you really want to ignore null elements - you'd still want the extra space after, correct?

@lo1tuma
Copy link
Member Author

lo1tuma commented Aug 13, 2015

@nzakas You are right, maybe we can just ignore the check for leading extra space of null elements?

@gyandeeps
Copy link
Member

@lo1tuma I actually ended up filtering out the null elements in indent rule. Maybe we can have a function in ast-utils which can do that?

@lo1tuma
Copy link
Member Author

lo1tuma commented Aug 19, 2015

@gyandeeps Not sure if we need to filter null elements completely in this case. I think we only want to make an exception for the check of leading space.

lo1tuma added a commit to lo1tuma/eslint that referenced this issue Aug 20, 2015
ilyavolodin added a commit that referenced this issue Aug 20, 2015
Fix: ignore leading space check for `null` elements in comma-spacing (fixes #3392)
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 7, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly rule Relates to ESLint's core rules
Projects
None yet
Development

No branches or pull requests

3 participants