Disallow space before colon in SwitchStatement
See original GitHub issueHi guys! Today there is no way to disallow space before colon in switch-case statement:
switch (foo) {
case 'bar' :
return '^---oh, that space...';
}
I already use keyword-spacing
, but I can’t configure it for my case. I tried key-spacing
too, but it still doesn’t work.
My configuration looks like this:
...
"key-spacing": "error",
"keyword-spacing": "error",
...
You can also reproduce this by http://eslint.org/demo/ with enabled keyword-spacing
& key-spacing
.
I’ve asked about this in gitter and I was recommended to create an issue. I don’t know, should it be a new rule or modification of an existing?
Thank you!
Issue Analytics
- State:
- Created 7 years ago
- Reactions:3
- Comments:7 (7 by maintainers)
Top Results From Across the Web
switch-colon-spacing - Pluggable JavaScript Linter - ESLint
This rule controls spacing around colons of case and default clauses in switch statements. This rule does the check only if the consecutive...
Read more >Bug: conflict between space-before-blocks and switch-colon ...
For space-before-blocks to acknowledge the rule settings of switch-colon-spacing and behave accordingly. What actually happened? The two rules ...
Read more >spaces not needed in case labels? - Stack Overflow
There needs to be whitespace separating the case word from it's value in order for the compiler to recognize the case . As...
Read more >declaration-colon-space-before - Stylelint
Require a single space or disallow whitespace before the colon of declarations. The fix option can automatically fix all of the problems reported...
Read more >Formatting - Coding Style - Read the Docs
No space before the colon of case . If the default case should never execute, simply assert . case blocks in switch statements...
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’ll champion, too. I try to make a concrete proposal.
label-colon-spacing (or label-spacing)
This rule enforce usage of spaces before/after the colon of labels. The labels is both
LabeledStatement
andSwitchCase
nodes’.Options
after
true
(default) requires spaces after the colon of labels.false
disallows spaces after the colon of labels.before
true
requires spaces before the colon of labels.false
(default) disallows spaces before the colon of labels.Examples
👎 incorrect code for this rule with the default
{"after": true, "before": false}
option.👍 correct code for this rule with the default
{"after": true, "before": false}
option.👎 incorrect code for this rule with the
{"after": false, "before": true}
option.👍 correct code for this rule with the default
{"after": false, "before": true}
option.This has now been accepted! I support adding a rule for this, however it’s not entirely clear to me where we stand with the proposal. It looks like there were two votes for a rule that specifically checks switch cases.