I have a project that has both prettier and eslint installed. The problem is that when I save a file eslint automatically changes the format of the file and it seems some rules conflict with prettier. What is the solution?
This is prettier formatting:
When saved, the file changes to:
Also this is eslintrc file
{
"parser": "@typescript-eslint/parser",
"extends": [
"plugin:react/recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended",
"prettier/@typescript-eslint"
],
"rules": {
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/ban-ts-ignore": "off",
"@typescript-eslint/interface-name-prefix": "off",
"@typescript-eslint/no-unused-vars": ["warn", { "argsIgnorePattern": "^_" }]
},
"overrides": [
{
"files": ["**/*.tsx"],
"rules": {
"react/prop-types": "off"
}
}
],
"settings": {
"react": {
"version": "detect"
}
},
"ignorePatterns": ["coverage/", "node_modules/", "src/serviceWorker.ts"]
}
This error is related to Windows Line endings being different from Unix ones. Try running npx prettier --write . on your project's directory. This command will tell prettier to fix simple errors (such as this one) when found.
Print WidthSpecify the line length that the printer will wrap on. For readability we recommend against using more than 80 characters: In code styleguides, maximum line length rules are often set to 100 or 120. However, when humans write code, they don't strive to reach the maximum number of columns on every line.
Not fully configuring ESlint and Prettier can cause a myriad of issues. To avoid all of them follow the steps mentioned in How to use Prettier with ESLint and TypeScript in VSCode , also remove any extra setting in config files for ESlint, Prettier and setting.json for VScod that might override other rules.
Important: Based on the answer here: Uninstall prettier-eslint
extension.
.prettierrc
{
"printWidth": 160
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With