r0skar
r0skar

Reputation: 8696

ESLint - Override rules from eslint-plugin-prettier

I am using ESLint with the prettier plugin and configuration:

// eslintrc.js
extends: [
  `eslint:recommended`,
  `plugin:react/recommended`,
  `plugin:@typescript-eslint/recommended`,
  `plugin:prettier/recommended`,
  `prettier/react`,
  `prettier/@typescript-eslint`
]

This works great, but I would like to disable a certain prettier rule, which is removing "unneeded" parentheses (removing them actually breaks my code):

// Replace `(state.counter)` with `state.counter` eslint(prettier/prettier)
return <div>{(state.counter)}</div>

As you can see from the message above, it doesn't state which rule exactly is causing this behavior and therefore I don't know which one to override.

I have tried to override all rules found in eslint-prettier-config, but nothing worked and I don't want to keep using // eslint-disable-next-line prettier/prettier.

Upvotes: 23

Views: 25836

Answers (2)

Vladislav Zaynchkovsky
Vladislav Zaynchkovsky

Reputation: 3319

Prettier is not so configurable. You can try configuration they have: https://prettier.io/docs/en/configuration.html

Put .prettierrc file, or eslint config like this:

{
  rules: {
   'prettier/prettier': [
      'error',
      {
        trailingComma: 'all',
        tabWidth: 2,
        semi: false,
        singleQuote: true,
        bracketSpacing: true,
        eslintIntegration: true,
        printWidth: 120,
      },
    ],
  }
}

Upvotes: 25

eikooc
eikooc

Reputation: 2578

It is not currently possible to disable that specific rule from prettier through configuration, but to override rules in eslint that come from the extends block, you can either write in the rule like this:

"rules": {
  "prettier/prettier": "off"
  "@typescript-eslint/no-use-before-define": [
    "error",
    { "functions": false, "variables": true, "classes": true },
  ],
}

Or to only override it for a specific file pattern you can override it in the overrides block.

"overrides": [
  {
    "files": ["*.html"],
    "rules": {
      "prettier/prettier": "off",
      "@typescript-eslint/unbound-method": "off"
    }
  }
]

Here I am showing both the config you were looking for, and an inherited rule from a nested package to show future visitors how to do it.

Upvotes: 15

Related Questions