Consistently add quotes to object keys
See original GitHub issueWhile running through the codebase, prettier happens to conflict with the eslint quote props “consistent-as-needed” ( http://eslint.org/docs/rules/quote-props ):
const request = {
method: 'GET',
headers: {
'Accept': 'application/json', // Accept isn't quoted right now
'Content-Type': 'application/json',
},
}
Apparently we are now doing “as-needed”. The difference is that if one element in an object has quotes, then all of them must.
Given those two examples, it sounds like this is a better way to add quotes, but I wanted to get some feedback before implementing it.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:38
- Comments:19 (4 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 >Unquoted property names / object keys in JavaScript
Unless an object key is a numeric literal or a valid identifier name, you need to quote it to avoid a syntax error...
Read more >Add quotation marks to key-value object - Javascript
Remove and delete key-value pair from object literal · Loop and iterate through key value pair from object literal · Set key and...
Read more >Prettier 1.17: More quotes options and support for shared ...
--quote-props <as-needed|preserve|consistent>. as-needed (default) - Only add quotes around object properties where required.
Read more >Smart Keys | PyCharm Documentation
Select this checkbox to have PyCharm automatically add a closing bracket for each typed opening bracket, respectively. Insert pair quote.
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 Free
Top 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
@felixfbecker FWIW, I don’t agree - I think it’s perfectly fine just like that.
This is very annoying, we have this all over our codebase for OpenTracing:
And for HTTP header hashes and CSS styles it’s very common too.
Everyone I know agrees that quoting the keys consistently makes the code more readable