Bug: `key-spacing` with `align: "value"` produces incorrect alignment
See original GitHub issueEnvironment
Node version: v19.0.0 npm version: v8.19.2 Local ESLint version: v8.26.0 Global ESLint version: Not found Operating System: darwin 22.1.0
What parser are you using?
Default (Espree)
What did you do?
/* eslint "key-spacing": ["error", { align: "value" }] */
var foo =
{
code: 1,
message:
"some value on the next line",
};
What did you expect to happen?
No error.
What actually happened?
Got error
4:9 Missing space before value for key ‘code’. (key-spacing)
Autofix adds three spaces after code:
to align the value 1
one space after message:
, which doesn’t seem correct since there is no other value to align with.
If the order of the properties is swapped, as expected, no error is reported.
/* eslint "key-spacing": ["error", { align: "value" }] */
var foo =
{
message:
"some value on the next line",
code: 1
};
Participation
- I am willing to submit a pull request for this issue.
Additional comments
No response
Issue Analytics
- State:
- Created a year ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
[key-spacing] Allow for "alignment" spacing configuration #5613
I'm fine with on as the key name for align, "align on colons" or "align on values" makes sense to me. Your proposal...
Read more >key-spacing - ESLint - Pluggable JavaScript Linter
"align" with an object value allows for fine-grained spacing when values are being aligned in object literals. "singleLine" specifies a spacing style for...
Read more >Incorrect alignment and formatting of Table of Contents on Word
- Unselected and selected the "right align page numbers" on the Custom ToC box. Anyone can help me fixing this? Disclaimer: I'm not...
Read more >How to handle symbol not found compile error in java? [closed]
One solution is to add a default return statement at the bottom of the method, but if this were my code, I'd chuck...
Read more >Aligning equations when the number of columns change - TeX
Use gather* , and nest an aligned enviroinment within it: \documentclass{article} \usepackage{amsmath} \usepackage{amsthm} \begin{document} ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think that’s fine. Per the documentation (emphasize mine):
Since the value starts on another line, values wouldn’t be aligned so this looks similar to the problem with
align: "value"
. I think it’s correct to always consider that such property does not belong to the preceding group.@fasttime Thanks for taking this up. Yes, you will have to add corresponding test cases in your PR.