Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New rule suggestion: Object key names should only be quoted if necessary #503

Closed
scouten opened this issue Apr 27, 2016 · 7 comments

Comments

@scouten
Copy link

commented Apr 27, 2016

Good:

let response = {id: 'foo', ok: true}

Bad:

let response = {'id': 'foo', 'ok': true}
@LinusU

This comment has been minimized.

Copy link
Member

commented Apr 28, 2016

How do we feel about objects where some keys require quoting? I think it's more readable if they are all quoted:

const map = {
  'test-1': 73,
  'normal': 843,
  'other-key': 386,
  '1pass': 284,
  'sword': 83,
  'heavy-sword': 738
}
@yoshuawuyts

This comment has been minimized.

Copy link
Contributor

commented Apr 28, 2016

I think quotes in keys should only be allowed for escaping, the same way we apply the rule to double quotes for strings.

@feross

This comment has been minimized.

Copy link
Member

commented Apr 28, 2016

The reason that I initially did not enable this rule is because of the case that @LinusU points out.

As with all new rule proposals, the first step is to see how many repos would fail with it enabled.

@scouten

This comment has been minimized.

Copy link
Author

commented Apr 30, 2016

@LinusU: That works, too. I guess I thought part of the purpose of this standard was to reduce wiggle room. I recently came across a case in my own code where I had been inconsistent in my use of quoting and it seemed like something that fit neatly into what standard was trying to accomplish.

@dcousens

This comment has been minimized.

Copy link
Member

commented Apr 30, 2016

I think quote only if necessary is fine. It is consistent with our other idiosyncrasies (e.g semicolons).

@feross

This comment has been minimized.

Copy link
Member

commented Jul 13, 2016

Adding the rule:

    "quote-props": [2, "as-needed"]

Results in the following failures:

1..423
# tests 423
# pass  388
# fail  35

which seems fairly high for a purely stylistic rule addition. Maybe we can add it once the rule is automatically fixable with ESLint's --fix feature?

@feross feross added the blocked label Jul 13, 2016

@feross

This comment has been minimized.

Copy link
Member

commented Aug 19, 2016

Let's re-open this issue once ESLint makes quote-props fixable. Right now there's nothing actionable for us to do.

@feross feross closed this Aug 19, 2016

@lock lock bot locked as resolved and limited conversation to collaborators May 10, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
5 participants
You can’t perform that action at this time.