Videos
» npm install eslint-plugin-prettier
UPDATE 2023: ESLint is deprecating formatting rules and recommend you use a source code formatter instead.
tl;dr: Use eslint-config-prettier in eslint, and run prettier separately. You can ignore the rest.
From v8.53.0 onwards, you will see a deprecation warning if those formatting rules are enabled in your config. You should still use eslint-config-prettier to disable conflicting rules until the rules are removed in a new major release.
ESLint contains many rules and those that are formatting-related might conflict with Prettier, such as arrow-parens, space-before-function-paren, etc. Hence using them together will cause some issues. The following tools have been created to use ESLint and Prettier together.
prettier-eslint |
eslint-plugin-prettier |
eslint-config-prettier |
|
|---|---|---|---|
| What it is | A JavaScript module exporting a single function. | An ESLint plugin. | An ESLint configuration. |
| What it does | Runs the code (string) through prettier then eslint --fix. The output is also a string. |
Plugins usually contain implementations for additional rules that ESLint will check for. This plugin uses Prettier under the hood and will raise ESLint errors when your code differs from Prettier's expected output. | This config turns off formatting-related rules that might conflict with Prettier, allowing you to use Prettier with other ESLint configs like eslint-config-airbnb. |
| How to use it | Either calling the function in your code or via prettier-eslint-cli if you prefer the command line. |
Add it to your .eslintrc. |
Add it to your .eslintrc. |
| Is the final output Prettier compliant? | Depends on your ESLint config | Yes | Yes |
Do you need to run prettier command separately? |
No | No | Yes |
| Do you need to use anything else? | No | You may want to turn off conflicting rules using eslint-config-prettier. |
No |
For more information, refer to the official Prettier docs.
It's the recommended practice to let Prettier handle formatting and ESLint for non-formatting issues, prettier-eslint is not in the same direction as that practice, hence prettier-eslint is not recommended anymore. You can use eslint-plugin-prettier and eslint-config-prettier together.
- Use
eslint-config-prettierto turn-off eslint rules that are unnecessary or might conflict with Prettier. See 1st line in readme: eslint-config-prettier. - Use
eslint-plugin-prettierto run Prettier as an Eslint-rule. See 1st line in readme: eslint-plugin-prettier - Use both to take advantage of both tools. See recommended configuration: eslint-plugin-prettier.
This way you use
pluginto run Prettier as an Eslint-rule, andconfigto turn-off eslint rules that are unnecessary or might conflict with Prettier. - You can ignore
prettier-eslint
I am working on a project that uses eslint + prettier (and plugins to running both coupled)
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"eslint": "^8.42.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"pre-commit": "^1.2.2",
"prettier": "^3.2.5",
"pretty-quick": "^4.0.0",
"typescript": "^5.1.3"
}And respectively .prettierrc & .eslintrc.js cfg files (in project root), the prettier one with common formatting rules, and the eslint with the prettier integration plugins
module.exports = {
//...
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
//...
};My problem is: neither prettier or eslint both installed through Mason they do not recognize .prettierrc/eslintrc.js config files in cwd. Why the hell is javascript ecosystem the most confusing thing in the world?
I've rtfm (lazyvim) about formatters and linters, but I'm really lost. I also read in some topics that the installation of both coupled is not recommended and requires additional configuration (but I'm just workin in, is not my decision). Please, could you recommend content to understand how to configure it?