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.

Separate `quotes` rule for Object keys

See original GitHub issue

Currently, 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:closed
  • Created 8 years ago
  • Comments:13 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
ilyavolodincommented, Feb 12, 2016
"quote-props": [2, "always", { "exceptions": ["object"] }]

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).

0reactions
nzakascommented, Feb 13, 2016

I’m thinking this is best off as a custom rule for now. I don’t see a big need for this in core.

Read more comments on GitHub >

github_iconTop 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 >

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