bier hier
bier hier

Reputation: 22570

Why do I keep getting "[eslint] Delete `CR` [prettier/prettier]"?

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

Answers (30)

Baris Senyerli
Baris Senyerli

Reputation: 920

const {EndOfLineState} = require('typescript');

module.exports = {
  root: true,
  extends: '@react-native',
  error: {
    EndOfLineState: 'auto',
  },
};

Resolved for react native.

Upvotes: 0

Muhammad Faraz Ali
Muhammad Faraz Ali

Reputation: 970

Add below code in the rules object of .eslintrc.js file

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

e.g

enter image description here

OR

Add rules object in .eslintrc.js file

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

e.g

enter image description here

Upvotes: 19

Tom
Tom

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

Hadayat Niazi
Hadayat Niazi

Reputation: 2480

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

  1. Change dev server --fix

    npm run dev
    

    To

    npm run dev --fix
    # or
    npm run lint -- --fix
    yarn run lint -- --fix
    

Upvotes: 62

Vince
Vince

Reputation: 869

Add this to your .prettierrc file and open the VSCODE:

"endOfLine": "auto"

Upvotes: 15

Hamza Waleed
Hamza Waleed

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

Vah Run
Vah Run

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

Jake
Jake

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

Mohammed Al-Reai
Mohammed Al-Reai

Reputation: 2816

In the file .eslintrc.json, add this code and it will solve the issue:

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

Upvotes: 86

Hammad Hassan
Hammad Hassan

Reputation: 622

If you are using vscode, just press ctrl + . and it will fix it

Upvotes: 0

KushalSeth
KushalSeth

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

Trinh Hieu
Trinh Hieu

Reputation: 805

In project your add code here in file .eslintrc.js:

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

And it will fix it

enter image description here

Upvotes: 5

Rohit Kumar
Rohit Kumar

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

xudong zhang
xudong zhang

Reputation: 7969

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.

Upvotes: 791

Frank Guo
Frank Guo

Reputation: 717

As you can see add this into .eslintrc works!

enter image description here

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

Upvotes: 51

Bilal Ahmad
Bilal Ahmad

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

user3856437
user3856437

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

Sina Kordestani
Sina Kordestani

Reputation: 3

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

Upvotes: -4

Komail Fayazbakhsh
Komail Fayazbakhsh

Reputation: 384

Delete this line from the file .prettierrc

 "endOfLine": "crlf"

Upvotes: 2

Washington Santos
Washington Santos

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

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

Upvotes: 6

M. Emre Yalçın
M. Emre Yalçın

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

Sergey Barabanov
Sergey Barabanov

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

pxeba
pxeba

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

Shamaz saeed
Shamaz saeed

Reputation: 446

npm run lint -- --fix

Run this command this worked for me

Upvotes: 14

Keerthi Reddy Yeruva
Keerthi Reddy Yeruva

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

Tri Dawn
Tri Dawn

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

sudhanshu
sudhanshu

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

hariom nagar
hariom nagar

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

Peppers
Peppers

Reputation: 396

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

Upvotes: 4

Related Questions