678

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?

Henke
  • 4,445
  • 3
  • 31
  • 44
bier hier
  • 20,970
  • 42
  • 97
  • 166

40 Answers40

1085

Try setting the "endOfLine":"auto" in your .prettierrc (or .prettierrc.json) file (inside the object)

Or set

"prettier/prettier": [
  "error",
  {
    "endOfLine": "auto"
  }
]

inside the rules object of the eslintrc file.

If you are using Windows machine endOfLine can be "crlf" basing on your git config.

PerfectM1nd
  • 3
  • 1
  • 1
Vah Run
  • 11,223
  • 2
  • 11
  • 15
  • 128
    Changing the `.eslintrc` file worked for me, but not the `.prettierrc` file. No idea why or what the difference is (I'm new to all the tags on the OP). – Neo Jan 31 '19 at 02:19
  • 11
    My guess is that you might need Prettier extension in the VS Code. The prettierrc will only be valid in that scenario. – Vah Run May 29 '19 at 03:02
  • 14
    changing the end of line sequence from `CRLF` to `LF` worked for me, on a windows machine – Anup Jun 18 '20 at 07:33
  • 110
    For a newbie like me, this is how it is to be done. Open `.eslintrc.json` present in your root directory (`frontend`). After changes it will look as under: `{ "extends": ["react-app", "prettier"], "plugins": ["prettier"], "rules": { "prettier/prettier": ["error", { "endOfLine": "auto" }] } } ` – SimpleGuy Aug 30 '20 at 01:50
  • 21
    FYI: a restart is required for the changes to take effect on VSCode. – Sangimed Aug 18 '21 at 16:40
  • I created a file .prettierrc.json with "endOfLine":"auto", as that is a valid filename and nothing was working. 2 hours later, I decided to rename the file to .prettierrc to rules things out, but I couldn't. -the file already existed! doh. and that gets picked up first! – steve Apr 28 '22 at 02:57
  • for me it worked after a window reload with ```ESlint: fix all auto-fixable problem``` command for eslint file – Taimoor Oct 21 '22 at 17:41
  • In continuation to the comment from @SimpleGuy : after completion of the steps run `npm run lint -- --fix` helps. – Rahul Reddy Jan 05 '23 at 15:40
  • The key as @Sangimed mentioned is to restart VS Code if you place any Prettier rules in the prettierrc file. If the rule are placed in the Eslint file, a restart shouldn't be needed. – Brandon Jun 18 '23 at 21:46
684

Change this setting on VSCode.

An image showing the status bar at the bottom of the VSCode window. An arrow points to the 'LF' indicator; clicking on this option brings up a menu where you can select between LF and CLRF.

Slate
  • 221
  • 5
  • 14
xudong zhang
  • 6,899
  • 1
  • 5
  • 2
  • 37
    This would fix the problem, but only till you opened some other source file with CRLF. Above answer is more effective. – BobHy Jun 07 '19 at 17:55
  • 4
    Besides changing `CRLF` to `LF` within VSCode, `git` might be doing auto conversion under the hood. If you chose `checkout Windows-style` when installing, it converts source code you clone to `CRLF`. So reinstalling `git` and choose `checkout as-is, commit Unix-style` will fix it. – Huy Apr 08 '21 at 10:22
237

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

Brent Woodle
  • 153
  • 4
Jake
  • 2,493
  • 1
  • 7
  • 19
76

Solution

git config --global core.autocrlf false

After global configuration, you need to pull the code again.

Root cause of the problem:

The culprit is git, a configuration property of core.autocrlf

For historical reasons, the line breaks of the text file on windows and linux are different.

  • Windows At the time of line break, carriage return is used at the same time CR(carriage-return character) and line breaks LF(linefeed character)
  • Mac and Linux only use the newline character LF
  • Old version of Mac uses carriage return CR

Therefore, there will be incompatibility problems when text files are created and used in different systems.

When I clone code on Windows, autocrlf is true as default and then each line of the file is automatically converted to CRLF. If you do not make any changes to the file, eslint delete CR by pre-commit since git automatically convert CRLF to LF.

Reference

https://developpaper.com/solution-to-delete-%E2%90%8Deslint-prettier-prettier-error/

koko-js478
  • 1,703
  • 7
  • 17
  • 2
    This solution would break cross-platform development - you'd be able to push a mix or LF/CR/CRLF to the repo. I suggest not to use it unless you work alone, and only ever on one type of OS (Linux/Mac/Windows). A good config for a team is to use autocrlf=true and just configure the linting tools to respect the EOL characters of the platform they run on, as in the other answers ("endOfLine": "auto"). What is worse is that you suggest to set autocrlf=false GLOBALLY, I think if it ever needs to be done, it should always be per-repo, otherwise all your new repos have a problem from the get go. – Jakub Januszkiewicz Jun 02 '22 at 08:12
65

in the file .eslintrc.json in side roles add this code it will solve this issue

      "rules": {
    "prettier/prettier": ["error",{
      "endOfLine": "auto"}
    ]

  }
Mohammed Al-Reai
  • 2,344
  • 14
  • 18
  • This is what I was looking for - ppl didn't mention that it must be inside "rules" otherwise it won't help at all – Rezor Dec 21 '22 at 13:19
45

If the above code is not working for you try these two steps.

1. in the file .eslintrc.json inside rules object add this code it will solve this issue

 "prettier/prettier": ["error",{
      "endOfLine": "auto"}
    ]

2 Change dev server --fix

npm run dev

To

npm run dev --fix

OR

npm run lint -- --fix
yarn run lint -- --fix
naspinski
  • 34,020
  • 36
  • 111
  • 167
Hadayat Niazi
  • 1,991
  • 3
  • 16
  • 28
34

As you can see add this into .eslintrc works!

enter image description here

"prettier/prettier": ["error", {
    "endOfLine": "auto" }
],
Z-100
  • 518
  • 3
  • 19
Frank Guo
  • 547
  • 7
  • 8
31

Fixed - My .eslintrc.js looks like this:

module.exports = {
  root: true,
  extends: '@react-native-community',
  rules: {'prettier/prettier': ['error', {endOfLine: 'auto'}]},
};
Hamza Waleed
  • 1,334
  • 10
  • 12
25

Try this. It works for me:

yarn run lint --fix

or

npm run lint -- --fix

Akif
  • 7,098
  • 7
  • 27
  • 53
Hakan
  • 1,199
  • 1
  • 14
  • 18
21

I know this is old but I just encountered the issue in my team (some mac, some linux, some windows , all vscode).

solution was to set the line ending in vscode's settings:

.vscode/settings.json

{
    "files.eol": "\n",
}

https://qvault.io/2020/06/18/how-to-get-consistent-line-breaks-in-vs-code-lf-vs-crlf/

Radu Luncasu
  • 975
  • 10
  • 17
15

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.

Tri Dawn
  • 540
  • 6
  • 11
13

Fixed: My eslintrc.js some rule look like this:

rules: {
    'prettier/prettier': ['error', { "endOfLine": "auto"}, { usePrettierrc: true }],  // Use our .prettierrc file as source
    'react/react-in-jsx-scope': 'off',
    'react/prop-types': 'off',
    'simple-import-sort/imports': 'error',
    "simple-import-sort/exports": "error"
}
Ashique Ansari
  • 562
  • 4
  • 14
11

I am using git+vscode+windows+vue, and after read the eslint document: https://eslint.org/docs/rules/linebreak-style

Finally fix it by:

add *.js text eol=lf to .gitattributes

then run vue-cli-service lint --fix

Waket Zheng
  • 5,065
  • 2
  • 17
  • 30
11

Add this to your .prettierrc file and open the VSCODE

"endOfLine": "auto"
Vince
  • 776
  • 11
  • 21
11

npm run lint -- --fix

Run this command this worked for me

Shamaz saeed
  • 387
  • 3
  • 8
9

Add these below rule in .eslintrc file and then restart your project.

rules: {
    'prettier/prettier': ['error', { "endOfLine": "auto"}, { usePrettierrc: true }],  
}
zernab hussain
  • 339
  • 3
  • 6
7

I was having the same problem in my nest js app . Adding the below code to .eslintrc.jsrules and then running yarn run lint --fix fixed the issue .

'prettier/prettier': [
  'error',
  {
    endOfLine: 'auto',
  },
],

and my .eslintrc.js rules looks something like this..

 rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'prettier/prettier': [
  'error',
  {
    endOfLine: 'auto',
  },
],

},

r4k3sh
  • 121
  • 2
  • 4
7

Solution

1. Disable auto conversion git setting

git --global config core.autocrlf false

2. Remove old cache data

git rm --cached -r .

3. Reset git files

git reset --hard

Shraddha Goel
  • 869
  • 7
  • 18
6

In my case I am using windows OS and git code supports in Mac and getting converted to CRLF run below Command in cmd prompt to stop files getting converted to CRLF: enter image description here

git config --global core.autocrlf input

Checkout the code again and open Visual Studio Code again and run your scripts again. It worked for me.

Elias
  • 664
  • 2
  • 11
  • 23
6

I tried everything here and for me, I needed to manage prettier config extension through icon extensions > prettier > small engine > extensions settings > Prettier: End Of Line > set to auto.

After adding these two lines in my settings.json

"eslint.run": "onSave",
"editor.formatOnSave": true,

I was able to use the config below inside .eslintrc.js rule.

"prettier/prettier": ["error", {
    "endOfLine":"auto"
}],
shaedrich
  • 5,457
  • 3
  • 26
  • 42
6

Check the right-hand side of VS Code's status bar at the bottom where it shows information such as line and column, spaces, text encoding (UTF-8 etc). You should see a Select End Of Line Sequence status display (either LF or CRLF) that you can click on to change. Make sure you haven't manually changed this to something that conflicts with what you wish Prettier to use.

Darren Evans
  • 665
  • 10
  • 17
6

if you have already checked out the code

git config --global core.autocrlf input 


git rm --cached -r . 


git reset --hard
Keerthi Reddy Yeruva
  • 861
  • 1
  • 16
  • 43
5

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'.

  1. Delete your project
  2. Reinstall your git and choose checkout as-is, commit Unix-style line endings
  3. Clone your project from repo again
  4. Use the .editorconfig set up above
ßiansor Å. Ålmerol
  • 2,849
  • 3
  • 22
  • 24
4

Error appears when I pull code from git, and this work for me:

STEP 1:

git config --global core.autocrlf false

STEP 2:

  • delete your current folder

STEP 3:

  • pull code from git again
  • try running command again
Peppers
  • 270
  • 3
  • 5
  • git config --global core.autocrlf false this command works very well, solving the LF issue on vs code – Frank Guo Jan 24 '22 at 04:57
  • If you're working on different projects with different configurations you can set the flag locally for that repo by omitting the `--global` flag. Also, you don't need to delete the entire repo and clone it again, just resetting the branch to origin should work. – aitorllj93 Feb 03 '22 at 10:18
4

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

4

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

M. Emre Yalçın
  • 608
  • 1
  • 7
  • 10
  • Alternatively to this, you can use `npm run lint` if your project haves npm linting setup, for some reason on my vue 3 project vscode just get bugged ocasionally with these kind of errors as mention by OP – Gediminas Oct 31 '22 at 10:28
3

In the root open the .editorconfig file and change:

end_of_line = lf

to

end_of_line = auto

This should fix it for new files.

richardwhatever
  • 4,564
  • 5
  • 23
  • 26
3

What worked for me was:

  1. Update prettier to version 2.2.1 (latest version at the moment) as Roberto LL suggested. To do it execute

npm update prettier

  1. Execute lint fix as Hakan suggested (This will modify all files in the project to convert line ending to LF).

npm run lint -- --fix

It was not necessary to change .eslintrc and .prettierrc files!

Cláudio
  • 484
  • 1
  • 4
  • 18
3

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" 
    }
],
Srilal Sachintha
  • 1,335
  • 1
  • 12
  • 18
sudhanshu
  • 409
  • 1
  • 5
  • 12
2

I upgraded to "prettier": "^2.2.0" and error went away

Roberto LL
  • 97
  • 2
2

There is no need to ignore linter's rule. Just auto-fix it

npm install -g prettier
prettier -w .\webpack.config.js # or other file
Petr Tripolsky
  • 1,419
  • 15
  • 23
2

Delete this line from the file .prettierrc

 "endOfLine": "crlf"
1

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
hariom nagar
  • 370
  • 3
  • 5
0

All the answers above are correct, but when I use windows and disable the Prettier ESLint extension rvest.vs-code-prettier-eslint the issue will be fixed.

AndriyFM
  • 1,389
  • 14
  • 11
0

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'

Mithsew
  • 1,129
  • 8
  • 20
0

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"
}
0

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.

user3856437
  • 2,071
  • 4
  • 22
  • 27
0
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'

Bilal Ahmad
  • 781
  • 8
  • 10
-1

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.

Rohit Kumar
  • 87
  • 1
  • 5
-3

So you can disable or uninstall the 'eslint' extension for solve this problem, it worked for me.