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

key-spacing.align doesn't pay attention to non-whitespace before key #3267

Closed
ghost opened this issue Aug 4, 2015 · 4 comments
Closed

key-spacing.align doesn't pay attention to non-whitespace before key #3267

ghost opened this issue Aug 4, 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

@ghost
Copy link

ghost commented Aug 4, 2015

I'll admit my code style is weird, but key-spacing.align doesn't actually enforce alignment of values/colons like the documentation states, it enforces the alignment of keys and values/colons.

If this is intended, the docs should be updated (and theoretically the error messages changed). But I don't think it is:

var x = {
  foo : 10
  , b : 20 // missing space after key
};

var x = {
  foo    : 10, // extra space after key
  /**/ b : 20  // missing space after key
};

these pass:

var x = {
  foo : 10
  , b   : 20
};

var x = {
  foo : 10,
  /**/ b   : 20
};

what it "wants":

var x = {
    foo : 10
  , b   : 20
};

var x = {
       foo : 10,
  /**/ b   : 20
};

eslint 0.24.1, "key-spacing": { "align" : "colon" }

@eslintbot
Copy link

Thanks for the issue! We get a lot of issues, so this message is automatically posted to each one to help you check that you've included all of the information we need to help you.

Reporting a bug? Please be sure to include:

  1. The version of ESLint you are using (run eslint -v)
  2. The source code that caused the problem
  3. The configuration you're using (for the rule or your entire config file)
  4. The actual ESLint output complete with line numbers

Requesting a new rule? Please be sure to include:

  1. The use case for the rule - what is it trying to prevent or flag?
  2. Whether the rule is trying to prevent an error or is purely stylistic
  3. Why you believe this rule is generic enough to be included

Requesting a feature? Please be sure to include:

  1. The problem you want to solve (don't mention the solution)
  2. Your take on the correct solution to problem

Including this information in your issue helps us to triage it and get you a response as quickly as possible.

Thanks!

@gyandeeps gyandeeps added the triage An ESLint team member will look at this issue soon label Aug 4, 2015
@btmills
Copy link
Member

btmills commented Aug 4, 2015

Right now the rule is checking the length of keys, which I just realized is a really inefficient way to do it, in addition to suffering cases like this. We'd be much better off checking the locations of tokens, either the colon (for "align": "colon") or the token immediately after it ("align": "value").

@nzakas
Copy link
Member

nzakas commented Aug 4, 2015

@btmills so is this a bug?

@btmills
Copy link
Member

btmills commented Aug 5, 2015

In the case with leading commas, definitely - we should support that. Leading comments... potentially, but let's just fix both cases all at once with the token locations.

@btmills btmills added bug ESLint is working incorrectly rule Relates to ESLint's core rules and removed triage An ESLint team member will look at this issue soon labels Aug 5, 2015
@nzakas nzakas added the accepted There is consensus among the team that this change meets the criteria for inclusion label Aug 5, 2015
@nzakas nzakas closed this as completed in d465608 Aug 12, 2015
nzakas added a commit that referenced this issue Aug 12, 2015
Fix: `key-spacing.align` doesn't pay attention to non-whitespace before key (fixes #3267)
@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

4 participants