prettier / eslint-plugin-prettier

ESLint plugin for Prettier formatting
https://npm.im/eslint-plugin-prettier
MIT License
3.33k stars 185 forks source link

Issue when upgrading prettier to 3.3.3 - parenthesis added from prettier break eslint #688

Open rbpimenta opened 3 weeks ago

rbpimenta commented 3 weeks ago

I'm using the following command as a "pretest" on my build CI eslint . --fix && prettier --write ./src ./resource. After upgrading to prettier 3.3.3 I'm receiving the following message on my CI code.

Error:   22:9   error  Insert `(`  prettier/prettier
Error:   23:39  error  Insert `)`  prettier/prettier

It seems that the code is been transformed from this

this.foo = message.method
      ? anotherMethod(bar) ??
        value1
      : value2

to this (it's adding parenthesis on the code )

this.foo = message.method
      ? (anotherMethod(bar) ??
        value1)
      : value2

I believe that the problem is somehow related with the changes on the new prettier 3.3.3 version. More specific these two PRs

What version of eslint are you using? 8.57.0

What version of prettier are you using? 3.3.3

What version of eslint-plugin-prettier are you using? 5.2.1

Please paste any applicable config files that you're using (e.g. .prettierrc or .eslintrc files) .prettierrc.json

{
  "semi": false,
  "tabWidth": 2,
  "useTabs": false,
  "printWidth": 120,
  "singleQuote": true,
  "trailingComma": "none"
}

.eslintrc.json

{
  "env": {
    "commonjs": true,
    "es2021": true,
    "node": true,
    "jest/globals": true
  },
  "extends": [
    "standard",
    "plugin:import/errors",
    "plugin:import/warnings",
    "plugin:jest/recommended",
    "plugin:n/recommended",
    "plugin:prettier/recommended",
    "plugin:promise/recommended"
  ],
  "plugins": [
    "jest",
    "prettier"
  ],
  "parserOptions": {
    "ecmaVersion": 12
  },
  "rules": {
    "space-before-function-paren": 0
  },
  "ignorePatterns": [
    "resource/**"
  ]
}

What source code are you linting?

this.foo = message.method
      ? anotherMethod(bar) ??
        value1
      : value2

What did you expect to happen?

I'd expect the code to pass on CI.

What actually happened?

eslint error

Error:   22:9   error  Insert `(`  prettier/prettier
Error:   23:39  error  Insert `)`  prettier/prettier
GerkinDev commented 1 week ago

Hello, I had this issue too, and found out that I had 2 versions of prettier installed. Properly using a single version solved the issue.

Watch out that bins used in scripts may not be the same as the one used directly in your shell, or by your IDE.