Skip to main content

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

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

This is a Problematic Default!

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

The auto setting preserves the existing line endings of a file but will normalize a file with mixed line endings to match the first line's ending.

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

This tells the ESLint Prettier plugin not to flag CRLF line endings as an error. After applying this change, you may need to restart your code editor's ESLint server for it to take effect.

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

This is a good quick fix but does not solve the underlying project-wide configuration issue.

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.

# Set Git to not automatically convert line endings
git config --global core.autocrlf input

# Or, for existing projects, add a .gitattributes file
# This is the most robust solution for a team project.
# Create a file named .gitattributes in your project root:
* text=auto eol=lf
note

The .gitattributes file is the most professional solution, as it enforces the setting for everyone who clones the repository.

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.