Reputation: 22570
I am using VS Code with Prettier 1.7.2 and ESLint 1.7.0. After every newline I get:
[eslint] Delete `CR` [prettier/prettier]
This is the .eslintrc.json
:
{
"extends": ["airbnb", "plugin:prettier/recommended"],
"env": {
"jest": true,
"browser": true
},
"rules": {
"import/no-extraneous-dependencies": "off",
"import/prefer-default-export": "off",
"no-confusing-arrow": "off",
"linebreak-style": "off",
"arrow-parens": ["error", "as-needed"],
"comma-dangle": [
"error",
{
"arrays": "always-multiline",
"objects": "always-multiline",
"imports": "always-multiline",
"exports": "always-multiline",
"functions": "ignore"
}
],
"no-plusplus": "off"
},
"parser": "babel-eslint",
"plugins": ["react"],
"globals": {
"browser": true,
"$": true,
"before": true,
"document": true
}
}
The .prettierrc
file:
{
"printWidth": 80,
"tabWidth": 2,
"semi": true,
"singleQuote": true,
"trailingComma": "es5",
"bracketSpacing": true,
"jsxBracketSameLine": false,
}
How can I get rid of this error?
Upvotes: 782
Views: 779675
Reputation: 920
const {EndOfLineState} = require('typescript');
module.exports = {
root: true,
extends: '@react-native',
error: {
EndOfLineState: 'auto',
},
};
Resolved for react native.
Upvotes: 0
Reputation: 970
Add below code in the rules object of .eslintrc.js
file
"prettier/prettier": [
"error",
{
"endOfLine": "auto"
}
]
e.g
OR
Add rules object in .eslintrc.js
file
rules: {'prettier/prettier': ['error', {endOfLine: 'auto'}]}
e.g
Upvotes: 19
Reputation: 394
This has been answered already (simply adding "endOfLine": "auto"
to my .prettierrc
file and restarting VSCode fixed it for me) but I wanted to mention that seems to be the fault of Prettier after they decided to set the default value of endOfLine
to LF
in v2.0, which goes against Git's solution to line endings that Windows users should set autocrlf to true (i.e., keep the repo as LF
, and convert to/from CRLF
for Windows users on pull/push). I understand why Prettier concluded that LF
is the superior choice, but it goes against the established standard for cross-platform development with Git, so overriding its settings rather than messing with your Git or editor defaults is the correct solution, IMO.
Upvotes: 1
Reputation: 2480
If the above code is not working for you try these two steps.
In the file .eslintrc.json
inside rules object add this code it will solve this issue:
"prettier/prettier": [ "error",
{ "endOfLine": "auto" }
]
Change dev server --fix
npm run dev
To
npm run dev --fix
# or
npm run lint -- --fix
yarn run lint -- --fix
Upvotes: 62
Reputation: 869
Add this to your .prettierrc
file and open the VSCODE:
"endOfLine": "auto"
Upvotes: 15
Reputation: 1462
Fixed - My .eslintrc.js
looks like this:
module.exports = {
root: true,
extends: '@react-native-community',
rules: {'prettier/prettier': ['error', {endOfLine: 'auto'}]},
};
Upvotes: 39
Reputation: 13429
Try setting the "endOfLine":"auto"
in your .prettierrc (or .prettierrc.json) file (inside the object)
Or set this inside the rules
object of the eslintrc file:
"prettier/prettier": [
"error",
{
"endOfLine": "auto"
}
]
If you are using Windows machine endOfLine
can be "crlf" basing on your git config.
Upvotes: 1301
Reputation: 2951
In my windows machine, I solved this by adding the below code snippet in rules
object of .eslintrc.js
file present in my current project's directory.
"prettier/prettier": [
"error",
{
"endOfLine": "auto"
},
],
This worked on my Mac as well
Upvotes: 281
Reputation: 2816
In the file .eslintrc.json
, add this code and it will solve the issue:
"rules": {
"prettier/prettier": [
"error",
{
"endOfLine": "auto"
}
]
}
Upvotes: 86
Reputation: 622
If you are using vscode, just press ctrl + . and it will fix it
Upvotes: 0
Reputation: 4729
Just run this command: npx eslint --fix user-repository.ts
.
This command will automatically resolved all the issues.
and this will also show the actual warnings, which are not automatically getting resolved. resolve that using the intellisense and [eslint] Delete CR [prettier/prettier]
will diappear.
Upvotes: 1
Reputation: 805
In project your add code here in file .eslintrc.js
:
'prettier/prettier': [
'error',
{
endOfLine: 'auto',
},
],
And it will fix it
Upvotes: 5
Reputation: 157
I tried all these answers given in this question but none of them completely fixed the issue.
But after trying & searching for the solution i got the solution from a youtube video that says, to add the following lines in your .eslintrc.js
(Or whatever es lint config) file...
rules: {
// rules...
"prettier/prettier": 0
}
This setting removed all prettier related errors.
Upvotes: -2
Reputation: 717
As you can see add this into .eslintrc works!
"prettier/prettier": ["error", {
"endOfLine": "auto" }
],
Upvotes: 51
Reputation: 859
rules: {
"prettier/prettier": [
"error",
{
endOfLine: "auto",
},
],
}
RESTART YOUR VSCODE after adding this in your project's '.eslintrc.js' file.
And also add
module.exports = {
endOfLine: 'auto',
// keep other values
}
in your project's '.prettierrc.js'
Upvotes: 6
Reputation: 2377
If you already added the rule
"prettier/prettier": [
"error",
{
"endOfLine": "auto"
},
],
in your .prettierrc.js
but the issue isn't fixed, just restart the node server. npm start
.
Upvotes: 0
Reputation: 3
So you can disable or uninstall the 'eslint' extension for solve this problem, it worked for me.
Upvotes: -4
Reputation: 384
Delete this line from the file .prettierrc
"endOfLine": "crlf"
Upvotes: 2
Reputation: 91
You need add rules the file .eslintrc
"extends": ["plugin:prettier/recommended"],
"plugins": ["prettier"],
"rules": {
"prettier/prettier": ["error"],
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/unbound-method": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-empty-function": "off",
"@angular-eslint/no-empty-lifecycle-method": "off",
"@typescript-eslint/no-unused-vars": ["off"],
"@typescript-eslint/require-await": "off",
"@typescript-eslint/ban-types": "off"
}
Upvotes: 0
Reputation: 3129
The best solution is to use .editorconfig. Especially if you are working with a team with different type OS. So disabling prettier in .eslintrc is not a good option at all.
Install .editorconfig from your vscode extension. Create a .editorconfig file in your project root directory and it to your .gitignore
file so it won't bother your teammates.
Add this to your .editorconfig file or choose what workflow settings you need from the documentation.
[*]
end_of_line = lf
This will save your file automatically to EOL type lf
instead of crlf
in windows. Vise versa if using mac. Or depends on the project workflow setup.
The root cause is windows is default to crlf. So every time you try to create a file you will face this prettier Delete 'cr'
error.
In Addition
If all the files you got from git contains Delete 'cr'
.
Upvotes: 6
Reputation: 654
executing eslint for linting and fixing solved my issue.
eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore
or if you have lint script: npm run lint
Upvotes: 4
Reputation: 86
If you need to use with .prettierrc.js:
module.exports = {
...[config params],
endOfLine: 'auto',
};
Note! Not in rules
or prettier/prettier
.
Info here https://prettier.io/docs/en/options.html#end-of-line
Upvotes: 4
Reputation: 1806
For those using @vue/prettier there may be a conflict between it and eslint which results in this error. Despite being installed along with vue cli, @vue/prettier was a temporary solution until prettier accepted vue natively and that has already been done. The problem can be solved by switching to just 'prettier'
Upvotes: 0
Reputation: 889
if you have already checked out the code
git config --global core.autocrlf input
git rm --cached -r .
git reset --hard
Upvotes: 7
Reputation: 780
In the .eslintrc file add the following:
extends: ['prettier']
and plugins: ['prettier']
rules: {'prettier/prettier': ['error', {endOfLine: 'auto'}]}
In .prettierrc remove this:
endOfLine: 'auto'
It works for me.
Upvotes: 16
Reputation: 479
edit your .eslintrc.json file and update "prettier/prettier" value shown below.
I face same problem and fixed using below changes.
"prettier/prettier": [
"error", {
"singleQuote": true,
"parser": "flow"
}
],
Upvotes: 3
Reputation: 410
Its work for me
step-1 React js root directory find .eslintrc file
Step-2 find in .eslintrc
"prettier/prettier": [
2,
{
"printWidth": 100,
"singleQuote": true,
"trailingComma": "none",
"tabWidth": 2
}
]
replace with
"prettier/prettier": [
"error",
{
"endOfLine": "auto"
}
]
save file and then run
npm start
Upvotes: 1
Reputation: 396
git config --global core.autocrlf false
Upvotes: 4