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

Autofixing quote-props should take into account quotes configuration #209

Closed
tbassetto opened this issue Feb 22, 2017 · 1 comment
Closed

Comments

@tbassetto
Copy link

The following bug can be reproduced with VS Code Version 1.9.1 (1.9.1) and its ESLint plugin v1.2.6. Note that I have "eslint.autoFixOnSave": true in my VS Code config.

This is the relevant configuration in my .eslintrc.js:

'quote-props': [2, 'consistent-as-needed'],
'quotes': [2, 'single', { avoidEscape: true }],

It means that quotes should always be single quotes, unless there is one that needs to be escaped in the string. It also means that the properties of an object should never have quotes, unless it's needed. In this case, all the properties of the object should have quotes.

Here is some valid code:

var clusterCache = {
  c_ucmc: {},
  c_cal: {},
};

If I want to add the property c-mgmt, I need to use quotes (otherwise it's not valid JavaScript):

var clusterCache = {
  c_ucmc: {},
  c_cal: {},
  'c-mgmt': {},
};

If I save the file, VS Code autofix it to:

var clusterCache = {
  "c_ucmc": {},
  "c_cal": {},
  'c-mgmt': {},
};

Which then triggers 2 errors for the quotes rule, and it can't fix them!

If I don't use VS Code to autofix and run ./node_modules/.bin/eslint file.js --fix (ESLint v3.16.0) instead, the result is (as expected):

var clusterCache = {
  'c_ucmc': {},
  'c_cal': {},
  'c-mgmt': {},
};

Why is VS Code fixing it differently than barebone ESLint v3.16.0? And why can't it fix the fact that there are double quotes after inserting them? Thanks :)

@dbaeumer
Copy link
Member

ESLint when called with --fix runs the fixing strategy n times until no new fixes are computed. The ESLint plugin currently only runs the fixing strategy once.

Dups #154 which explains the problems around this more deeply.

@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 21, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants