Skip to content

Change quote-props rule to "consistent-as-needed" #3

@wincent

Description

@wincent

I just got bitten by this while preparing this PR: liferay/liferay-js-themes-toolkit#247

Basically, given an object containing some version numbers properties:

{
  '6.2': true,
  '7.0': true,
  '7.1': true,
}

we currently have ESLint configured via "quote-props" to require quotes around property names "as-needed"; producing this:

{
  6.2: true,
  '7.0': true,
  7.1: true,
}

This looks pretty terrible. I noticed that Prettier didn't have an opinion on this, so I changed them all to skip the quotes:

{
  6.2: true,
  7.0: true,
  7.1: true,
}

of course, that is wrong too, because 7.0 actually gets stringified to '7', meaning the object is equivalent to:

{
  '6.2': true,
  '7': true,
  '7.1': true,
}

This breaks checks of the form if (object['7.0'] === true). So I added a lint suppression and put strings back on all the keys, but we should just configure ESLint to use "consistent-as-needed" instead. Via the docs:

requires quotes around all object literal property names if any name strictly requires quotes, otherwise disallows quotes around object property names

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions