Separate `quotes` rule for Object keys
See original GitHub issueCurrently, the quotes
rule is applied to all strings.
Although, JS supports both single, double or no quotes for key names in Objects, JSON spec. explicitly states to use double quotes for keys.
To be consistent with JSON spec., I’d like to have my keys in double quotes, while other strings in single quotes.
I propose a new rule specifically for handling quotes in Object keys - key-quotes
.
By default, it could very well inherit the quotes
rule.
<bountysource-plugin>
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource. </bountysource-plugin>
Issue Analytics
- State:
- Created 8 years ago
- Comments:13 (9 by maintainers)
Top Results From Across the Web
What is the difference between object keys with quotes and ...
No, the quotes do not make a difference (unless, as you noted, you want to use a key that's not a valid JavaScript...
Read more >object-literal-key-quotes - Rule
"consistent-as-needed" : If any property name requires quotes, then all properties must be quoted. Otherwise, no property names may be quoted.
Read more >Unquoted property names / object keys in JavaScript
In other words, quotes can only be omitted if the property name is a numeric literal or a valid identifier name.
Read more >Never confuse JSON and JavaScript Object ever again!
→ JavaScript objects do not contain single or double quote marks around the keys when no spacing is used in the key name....
Read more >JavaScript Object Keys Tutorial – How to Use a JS Key-Value ...
There's another rule to keep in mind about key names: if your key name contains spaces, you need to wrap it in quotes....
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
Don’t take this proposal as me wanting to champion this feature though. I’m not convinced this is a necessary enhancement. Just wanted to move discussion one way or another (it’s been sitting around without resolution for a long time).
I’m thinking this is best off as a custom rule for now. I don’t see a big need for this in core.