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

Conflict with prettier #14858

Closed
strrife opened this issue Jul 30, 2021 · 6 comments
Closed

Conflict with prettier #14858

strrife opened this issue Jul 30, 2021 · 6 comments
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion autofix This change is related to ESLint's autofixing capabilities bug ESLint is working incorrectly rule Relates to ESLint's core rules
Projects

Comments

@strrife
Copy link

strrife commented Jul 30, 2021

Tell us about your environment

  • ESLint Version: 7.31.0 (was reproducible on 7.29.0 too)
  • Node Version: v14.17.2
  • npm Version: 6.14.13

What parser (default, @babel/eslint-parser, @typescript-eslint/parser, etc.) are you using? babel-eslint@10.1.0

Please show your full configuration:

package.json
{
  "scripts": {
    "lint-fix": "eslint --fix problem.js"
  },
  "devDependencies": {
    "eslint": "^7.31.0",
    "eslint-config-prettier": "^8.3.0",
    "eslint-plugin-prettier": "^3.4.0",
    "prettier": "^2.3.2",
    "prettier-eslint": "^13.0.0"
  },
  "dependencies": {
    "babel-eslint": "^10.1.0"
  }
}
Configuration
module.exports = {
  plugins: ['prettier'],
  extends: [
    'eslint:recommended',
    "plugin:prettier/recommended"
  ],
  parser: 'babel-eslint'
};
.prettierrc
{
  "singleQuote": true,
  "jsxSingleQuote": true,
  "semi": true,
  "printWidth": 120,
  "tabWidth": 2
}

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

I'm trying to run eslint --fix problem.js to fix following code:

if (true) {
  const isReproducible = !!1 ?
    ['apple', 'banana', 'orange', 'pineapple', 'apple', 'banana', 'orange', 'pineapple']
    : ['apple', 'banana', 'orange', 'pineapple'];
}

What did you expect to happen?

I expected eslint --fix to not add syntax errors to the file

What actually happened? Please include the actual, raw output from ESLint.

if (true) {
  const isReproducible = 1 ?
    ? ['apple', 'banana', 'orange', 'pineapple', 'apple', 'banana', 'orange', 'pineapple']
    : ['apple', 'banana', 'orange', 'pineapple'];
}
eslint --fix output

/home/strrife/Projects/eslint-repro/problem.js
  3:5  error  Parsing error: Unexpected token

  1 | if (true) {
  2 |   const isReproducible = 1 ?
> 3 |     ? ['apple', 'banana', 'orange', 'pineapple', 'apple', 'banana', 'orange', 'pineapple']
    |     ^
  4 |     : ['apple', 'banana', 'orange', 'pineapple'];
  5 | }
  6 | 

✖ 1 problem (1 error, 0 warnings)

It looks like the no-extra-boolean-cast somehow conflicts with the prettier config. I have experienced similar issues previously when formatting rules were conflicting with prettier. Disablign them made sense, but it is not the case here since prettier would not be fixing no-extra-boolean-cast.

Fixing the file manually and running esling --fix again works just fine.

Also, fixing the following piece of code:

const isReproducible = !!1 ?
  ['apple', 'banana', 'orange', 'pineapple', 'apple', 'banana', 'orange', 'pineapple']
  : ['apple', 'banana', 'orange', 'pineapple'];

does not create syntax errors.

Thanks, best regards, Alexander

@eslint-github-bot eslint-github-bot bot added this to Needs Triage in Triage Jul 30, 2021
@eslint-github-bot eslint-github-bot bot added the triage An ESLint team member will look at this issue soon label Jul 30, 2021
@nzakas
Copy link
Member

nzakas commented Jul 31, 2021

Can you disable prettier and see if you get the same result?

@nzakas nzakas moved this from Needs Triage to Triaging in Triage Jul 31, 2021
@nzakas nzakas added autofix This change is related to ESLint's autofixing capabilities bug ESLint is working incorrectly rule Relates to ESLint's core rules and removed triage An ESLint team member will look at this issue soon labels Jul 31, 2021
@strrife
Copy link
Author

strrife commented Aug 6, 2021

@nzakas apologies for the delayed feedback, it works fine without prettier. And it works fine with no-extra-boolean-cast disabled.

@nzakas
Copy link
Member

nzakas commented Aug 6, 2021

Okay, in that case, this seems like it's most likely a problem with Prettier and not with ESLint. I can't reproduce introducing the syntax error just with ESLint.

@strrife
Copy link
Author

strrife commented Aug 6, 2021

If I understand correctly, in this context prettier acts just another eslint plugin, and it looks like 2 plugins make changes in the code ignoring each other

@nzakas
Copy link
Member

nzakas commented Aug 7, 2021

Rules don’t know what other rules are doing. We can’t possibly guarantee that every rule created by a third party will work correctly with core ESLint rules. I’d suggest following up with the prettier folks.

@mdjermanovic
Copy link
Member

This looks like a known bug in eslint-plugin-prettier. ESLint prevents conflicts by not applying overlapping fixes, but each individual fix should be complete (should produce valid code after applying) and thus independent of other fixes, which isn't always the case with fixes that eslint-plugin-prettier provides: prettier/eslint-plugin-prettier#65 (comment).

@strrife strrife closed this as completed Aug 9, 2021
Triage automation moved this from Triaging to Complete Aug 9, 2021
@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Feb 6, 2022
@eslint-github-bot eslint-github-bot bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion autofix This change is related to ESLint's autofixing capabilities bug ESLint is working incorrectly rule Relates to ESLint's core rules
Projects
Archived in project
Triage
Complete
Development

No branches or pull requests

3 participants