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.

Consistently add quotes to object keys

See original GitHub issue

While running through the codebase, prettier happens to conflict with the eslint quote props “consistent-as-needed” ( http://eslint.org/docs/rules/quote-props ):

image

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:closed
  • Created 7 years ago
  • Reactions:38
  • Comments:19 (4 by maintainers)

github_iconTop GitHub Comments

41reactions
oliversturmcommented, Nov 30, 2017

@felixfbecker FWIW, I don’t agree - I think it’s perfectly fine just like that.

28reactions
felixfbeckercommented, Nov 5, 2017

This is very annoying, we have this all over our codebase for OpenTracing:

span.log({
    event: 'error',
    'error.object': err,
    message: err.message,
    stack: err.stack,
})

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

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

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