Skip to content

JavaScript ESLint: How to Fix the 'Delete CR' Error in ESLint (prettier/prettier)

Learn how to resolve the ESLint 'Delete CR' error caused by inconsistent line endings (CRLF vs. LF) across Windows, macOS, and Linux systems with Prettier, ESLint, and Git configurations.

When working in a team with developers on different operating systems (Windows, macOS, Linux), you will inevitably encounter the ESLint error: Delete CR (prettier/prettier). This error occurs because of a disagreement about line endings. Windows uses a "Carriage Return" (CR) and a "Line Feed" (LF) for each line break, while macOS and Linux use only a "Line Feed".

This guide will explain the root cause of this error and provide several clear, step-by-step solutions, from configuring ESLint and Prettier to setting your Git configuration and editor settings correctly, ensuring a consistent and error-free development experience for your entire team.

Understanding the Root Cause: CRLF vs. LF

Different operating systems mark the end of a line in a text file differently.

  • Windows: Uses a Carriage Return and Line Feed (\r\n), often called CRLF.
  • macOS & Linux: Use only a Line Feed (\n), often called LF.

The Delete CR error is Prettier telling you that a file contains a Windows-style CRLF ending, but it has been configured to expect a Linux-style LF ending. This often happens when a developer on Windows checks in a file, and another developer on a Mac (or a CI/CD pipeline running on Linux) lints it.

The best solution is to tell Prettier to be flexible and not enforce a single line-ending style, especially in a mixed-OS environment. This is done by setting the endOfLine option to auto.

By default, Prettier often enforces lf.

{
  "endOfLine": "lf"
}

Solution: .prettierrc

Add the following to your .prettierrc or .prettierrc.json file. This is the recommended approach as it sets the rule for the entire project.

{
  "endOfLine": "auto"
}

Solution 2: Configure ESLint to Ignore Line Endings

If you cannot change the project's Prettier configuration, you can tell ESLint to ignore the line-ending rule from Prettier.

Example of the error message:

error  Delete `CR`  prettier/prettier

Solution: .eslintrc.js or .eslintrc.json

Modify the prettier/prettier rule in your ESLint configuration to set endOfLine to auto.

For .eslintrc.js:

module.exports = {
  // ...other config
  rules: {
    'prettier/prettier': [
      'error',
      {
        endOfLine: 'auto',
      },
    ],
    // ...other rules
  },
};

For .eslintrc.json:

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

Solution 3: Fix Line Endings in Your Code Editor (VS Code)

You can also fix the problem directly in your editor for the specific file that is causing the error.

Follow these steps to fix in VS Code:

  1. Open the file that is showing the Delete CR error.
  2. In the bottom-right corner of the status bar, you will see a label that says CRLF or LF.
  3. Click on it. A menu will appear at the top.
  4. Select LF. This will immediately change the file's line endings and resolve the error for that file.

Solution 4: Standardize Line Endings with Git

Git has its own configuration for handling line endings, which can automatically convert them during commits and checkouts. Incorrect settings here are a common cause of this issue.

The best practice is to configure Git to store files with LF line endings in the repository, regardless of the user's OS.

The Problematic Git Default on Windows

By default, Git for Windows sets core.autocrlf to true. This means when you check out a file, it converts LF to CRLF. When you commit, it converts CRLF back to LF. This can cause Prettier to see the CRLF and report an error before you commit.

Solution: Configure Git

You can tell Git to check out files "as-is" without conversion.

git config --global core.autocrlf input

* text=auto eol=lf

Conclusion

The Delete CR error is a common but easily solvable issue caused by different line-ending conventions between operating systems.

  • The best and simplest solution is to configure Prettier to be flexible by setting "endOfLine": "auto" in your .prettierrc file.
  • Alternatively, you can configure the same endOfLine: 'auto' setting inside your .eslintrc file.
  • For a robust, team-wide solution, enforce line endings at the source with a .gitattributes file in your project.

By standardizing how your tools and version control handle line endings, you can eliminate this error for good.

Navigation