eslint-plugin-prettier vs eslint-config-prettier
This article clearly unvails the difference between eslint-plugin-prettier and eslint-config-prettier.
eslint-plugin-prettier
- add
linting
- load
prettier config
- and execute
formatting
througheslint
eslint-config-prettier
▪️ provide rules
that
- disable
conflicting
rules
ofeslint
withprettier
◌ intended so that you useprettier
separately fromeslint
◌ And not haveeslint
screwprettier formatting
and conflicting - How does eslint-config-prettier works ? 🔥
▪️ Does also provide a CLI
to check if there are any conflicts
between
prettier
config- and actual
eslint
config
So mmmm what !!!
- If you count to use
prettier
separately fromeslint
✨ use onlyeslint-config-prettier
- If you count to use
prettier
througheslint
withlinting prettier problems
, andformating
througheslint
byfixes
, or by settingeslint
asformatter
✨ Then you should useeslint-plugin-prettier
- ( which does internally useeslint-config-prettier
to disable theconflicting
rules
)
eslint-plugin-prettier
does use eslint-config-prettier
eslint-plugin-prettier
provideplugin:prettier/recommended
config forextends
which is
{
"extends": ["prettier"],
"plugins": ["prettier"],
"rules": {
"prettier/prettier": "error",
"arrow-body-style": "off",
"prefer-arrow-callback": "off"
}
}
"extends": ["prettier"],
=> eslint-config-prettier
"plugins": ["prettier"],
=> eslint-plugin-prettier
This is the eslint
string resolution algorithms
eslint strings resolution
✨ plugins
▪️ plugins
=> whatever string
that doesn't have the prefix
yet. prefix it with eslint-plugin-
- ex:
plugins: ["dragon/crazy"]
===> eslint-plugin-dragon/crazy
Which will be resolved through nodejs module resolution
to
node_modules/eslint-plugin-dragon/crazy.js
◌ theeslint-plugin-dragon
npmpackage
should exposecrazy.js
atroot
◌ or through npmmodule resolution
inpackage.json
✨ extends
- similarly
- prefix with
eslint-config-
instead
extends: ["dragon/crazy"]
===> eslint-config-dragon/crazy
Which will be resolved through nodejs module resolution
to
node_modules/eslint-config-dragon/crazy.js
◌ theeslint-config-dragon
npmpackage
should exposecrazy.js
atroot
◌ or through npmmodule resolution
inpackage.json
✨ what if package doesn’t exist ?
- fail with a
not found error
❌
My Other Eslint
related Articles
- Flat config: Setting up Eslint and Prettier with eslint-prettier-plugin 🔥
- How does eslint-config-prettier works ? 🔥
Helpful