question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Why multiline values restart key-spacing alignment?

See original GitHub issue

My issue resonates from the fact that key-spacing: ['error', {"align": "value"}] rule is not compliant with Webstorm’s “align object on value” option (which can be used to automatically reformat the code).

At first I thought it’s a Webstorm issue and I reported it to JetBrains https://youtrack.jetbrains.com/issue/WEB-29680, but it appears that this behavior is not explicitly mentioned in ESLint docs. It’s only mentioned in the code comment “Non-consecutive lines form a new group”, but I’m not sure if it relates to this unjustified behavior.

What rule do you want to change? key-spacing, “align”: “value” https://eslint.org/docs/2.0.0/rules/key-spacing

Does this change cause the rule to produce more or fewer warnings? It would create less errors for Webstorm users.

How will the change be implemented? (New option, new default behavior, etc.)? Either:

  1. Ideally create a new option, with simplified aligning which doesn’t form a new group after multiline values, or…
  2. Explicitly mention in the docs that multiline values restart key-spacing alignment

Please provide some example code that this change will affect:

var obj = {
        a:    value,
        bcde: 42,

        fg:   foo(), // Eslint error: Extra space before value
        h:    function () { // Eslint error: Extra space before value
            return this.a;
        },
        ijkl: 'Non-consecutive lines form a new group'
    };

What does the rule currently do for this code? With mentioned rule turned on, above code is currently treated as incorrect (“Eslint error: Extra space before value”), and there is no rule that would accept this.

What will the rule do after it’s changed? Instead of changing existing behavior (and confuse users that might find this current behavior useful), I’d rather add a new option for simplified aligning, that wouldn’t throw an error in such case.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
folmertcommented, Jan 18, 2018

You’re using different rule in .eslintrc.js:

"key-spacing": [2, {"beforeColon": false, "afterColon": true}]

It should be:

'key-spacing': ['error', {"align": "value"}]
1reaction
folmertcommented, Jan 15, 2018

I’ve came up with a better, more minimal example (as previous one might be related with restarting alignment on new lines)

var foo = {
    h:    function () { // Eslint error: Extra space before value
        return this.a;
    },
    ijkl: 'Non-consecutive lines form a new group',
};

var bar = {
    ijkl: 'Non-consecutive lines form a new group',
    h:    function () { // error is gone!
        return this.a;
    },
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

Line spacing and alignment issues in tables with multiline cells
While trying to create tables with multiline cells, I run into some line spacing and alignment issues. The following code creates two tables ......
Read more >
multilineTextAlignment(_:) | Apple Developer Documentation
A view that aligns the lines of multiline Text instances it contains. Parameters. alignment. A value that you use to left-, right-, or...
Read more >
Multiline string not aligning properly with ax.annotate
I was able to figure out the way to have the alignment properly, the updated code below. No change in the 'plot' code...
Read more >
no-multi-spaces - ESLint - Pluggable JavaScript Linter
... false }]*/ var x = 5; // comment var x = 5; /* multiline * comment */ ... because for the key-spacing...
Read more >
How to adjust text alignment using multilineTextAlignment()
A center-aligned multiline paragraph of text. You can compare all three text alignments side by side using a picker such as this one:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found