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

Bug: key-spacing change has broken alignment of single-line and multi-line keys when mixed #16674

Closed
1 task
pdl opened this issue Dec 16, 2022 · 4 comments · Fixed by #16677
Closed
1 task
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 repro:yes rule Relates to ESLint's core rules
Projects

Comments

@pdl
Copy link

pdl commented Dec 16, 2022

Environment

Node version: v16.13.2
npm version: v8.3.2
Local ESLint version: Not found
Global ESLint version: Not found
Operating System: linux 4.15.0-194-generic

NB: $ yarn -s eslint --version returns v8.29.0.

What parser are you using?

(Initially noticed with an environment which I think uses) vue-eslint-parser (but reproduced as below).

What did you do?

In ESLint demo, paste the following, or use this link:

/* eslint key-spacing: [ "error", {"singleLine" : { "beforeColon": false, "afterColon": true }, "multiLine" : { "beforeColon": false, "afterColon": true }, "align" : { "beforeColon": true, "afterColon": true, "on": "colon" } }] */

// I use the rules above to line up my colons

// Lining these up used to be ok
const a = {
  item       : 123,
  longerItem : (
    1 + 1
  ),
};

// This is still fine
const b = {
  item       : 123,
  longerItem : 456,
};

// No, I specifically don't want this style, it used to be an error, I want my colons to align
const c = {
  item: 123,
  longerItem: (
    1 + 1
  ),
};

// these lines just to get rid of output about a, b, c being unused
a.item++;
b.item++;
c.item++;

What did you expect to happen?

The first two const assignments to a and b should have no error and c should raise an error, fixable to become like a.

What actually happened?

Errors are reported in case a, not c. ESLint will attempt to 'correct' to c.

Error
7:7
Extra space after key 'item'.  ([key-spacing](https://eslint.org/docs/rules/key-spacing))

Error
8:13
Extra space after key 'longerItem'.  ([key-spacing](https://eslint.org/docs/rules/key-spacing))

Participation

  • I am willing to submit a pull request for this issue.

Additional comments

I assume it was broken by #16532.

@pdl pdl added bug ESLint is working incorrectly repro:needed labels Dec 16, 2022
@eslint-github-bot eslint-github-bot bot added this to Needs Triage in Triage Dec 16, 2022
@pdl pdl changed the title Bug: (fill in) Bug: key-spacing change has broken alignment of single-line and multi-line keys when mixed Dec 16, 2022
@pdl
Copy link
Author

pdl commented Dec 16, 2022

@fasttime could you confirm whether this was an intentional outcome of your change?

@mdjermanovic mdjermanovic added rule Relates to ESLint's core rules accepted There is consensus among the team that this change meets the criteria for inclusion repro:yes and removed repro:needed labels Dec 16, 2022
@mdjermanovic mdjermanovic moved this from Needs Triage to Ready to Implement in Triage Dec 16, 2022
@mdjermanovic
Copy link
Member

Looks like a bug to me. Marked accepted.

// No, I specifically don't want this style, it used to be an error, I want my colons to align
const c = {
  item: 123,
  longerItem: (
    1 + 1
  ),
};

This is because the parentheses are not considered to be part of Property#value, so it starts on a separate line. We can fix this by getting the first token after : and then using its line instead of the property value's line.

@fasttime
Copy link
Member

@pdl This was not intentional. I did not consider that property values wrapped in parentheses would not align correctly after my change, although it's obvious in afterthought. My apologies for the slip!
The fix suggested by @mdjermanovic should solve it already. I would be happy to do a PR.

@mdjermanovic
Copy link
Member

PR is welcome!

Triage automation moved this from Ready to Implement to Complete Dec 21, 2022
@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Jun 20, 2023
@eslint-github-bot eslint-github-bot bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Jun 20, 2023
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 repro:yes rule Relates to ESLint's core rules
Projects
Archived in project
Triage
Complete
Development

Successfully merging a pull request may close this issue.

4 participants
@pdl @fasttime @mdjermanovic and others