prettier / eslint-config-prettier

Turns off all rules that are unnecessary or might conflict with Prettier.
MIT License
5.4k stars 254 forks source link

Confused as to What to Extend #177

Closed thecodeclimber closed 3 years ago

thecodeclimber commented 3 years ago

I am trying to figure out how to get eslint, prettier, react and typescript to all work together. I have gone through a number of tutorials as well as the documentation for various different eslint configuration packages and plugins. So far, this is what I have come up with:

  extends: [
    'airbnb',
    'airbnb/hooks',
    'plugin:react/recommended',
    'plugin:@typescript-eslint/recommended',
    'plugin:prettier/recommended',
    'prettier',
  ],
  plugins: ['@typescript-eslint'],

However, I do not know if I am doing this properly. Do I need both 'plugin:prettier/recommended' and 'prettier' or do I just need prettier?

zimme commented 3 years ago

If you use eslint-plugin-prettier you just need to extend plugin:prettier/recommended. If you don't use eslint-plugin-prettier and just eslint-config-prettier you'll just need to extend prettier.

thecodeclimber commented 3 years ago

First of all, thanks for the extremely quick response :).

Secondly, I am wondering (based on your answer) -- if I only use eslint-config-prettier and extend prettier will that automatically add eslint-plugin-prettier and plugin:prettier/recommended?

A related question is whether or not there is anything that adding eslint-plugin-prettier will allow me to do that I can't do simply by adding eslint-config-prettier with extending prettier?

zimme commented 3 years ago

It's the other way around, if you use eslint-plugin-prettier you can install eslint-config-prettier as that's an optional peer dependency. When you have both eslint-plugin-prettier and eslint-config-prettier then eslint-plugin-prettier offers plugin:prettier/recommended which enables eslint-config-prettier as well as sets up eslint-plugin-prettier properly for you.

eslint-plugin-prettier will add eslint rules for prettier formatting, i.e. you get lint warnings from eslint about prettier stuff.

eslint-config-prettier only disables other eslint rules that conflicts with prettier's formatting.

lydell commented 3 years ago

What @zimme said. I had already started writing, so I could just as well post it.

if I only use eslint-config-prettier and extend prettier will that automatically add eslint-plugin-prettier and plugin:prettier/recommended?

No.

A related question is whether or not there is anything that adding eslint-plugin-prettier will allow me to do that I can't do simply by adding eslint-config-prettier with extending prettier?

Yes!

(Also don’t forget to read about the downsides of eslint-plugin-prettier.)

thecodeclimber commented 3 years ago

@zimme and @lydell -- thanks, very helpful.