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

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

Open
rbpimenta opened this issue Oct 17, 2024 · 1 comment

Comments

@rbpimenta
Copy link

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants