In this guide, I will explain why the error Delete 'CR' eslint(prettier/prettier)
occurs, and provide 4 ways you can fix it.
The Delete 'CR' eslint(prettier/prettier)
error occurs when there are inconsistent line endings in your code.
This is because files created on Linux and macOS typically use LF
(Line Feed) represented as \n
, while files created on Windows often use CRLF
(Carriage Return + Line Feed) represented as \r\n
as line endings.
Let’s now see several ways to fix the error.
🎥 In the mood for a video tutorial instead? Check this out:
Run ESLint
💡Good to know
Running the following command would show you the errors ESLint can fix:
pnpm eslint .
The output should look something similar to this:
To fix the errors in the entire project, run the following:
pnpm eslint --fix .
If you don’t want to run ESLint for all the files in your project and would rather run it only for specific files, you can add a script to the package.json
file:
"scripts": {
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix"
}
The above script tells ESLint to run on all TypeScript files in the src
, apps
, libs
, test
directories and their subdirectories and automatically fix any issue it can.
You can run the script like so:
pnpm lint
Configure .prettierrc
Another way you can fix the error is by configuring the .prettierrc
file.
.prettierrc
is a configuration file for Prettier, a code formatting tool that helps enforce consistent coding styles across a project.
By using this file, you can customize how Prettier should format your code, such as indentation, line length, quotes, and other formatting styles.
Inside the .prettierrc
file add the following line of code:
"endOfLine": "auto" // or "lf", depending on your needs
💡Good to know
CTRL
+ SHIFT
+ P
to open the Command panel and run the Developer: Reload Window command.
That’s it! Let’s move on to the next!
Configure .editorconfig
Keeping the same approach, the .editorconfig
file can help you eliminate the error.
.editorconfig
is used to maintain consistent coding styles across different editors and IDEs.
If you don’t have this file at the root of your project, you can create it manually.
Or, if you’re using the EditorConfig VS Code extension, you can easily create the file by right-clicking in the Explorer section of the VS Code and selecting the Generate .editorconfig option.
This will auto-generate a handful of widely used configurations, one of which is the end_of_line = lf
:
root = true
[*]
indent_style = space
indent_size = 4
end_of_line = lf # 👈 this
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = false
You can choose to remove any auto-generated settings or keep them all.
All you have to do to fix the error is save the file. 💾
Configure VS Code
I’ve mentioned VS Code throughout the guide, so I couldn’t miss bringing it up as a way to fix the error.
Select the End of Line sequence setting from the bottom right of the window, then choose the LF option.
This will only automatically fix the file you currently have open, but it doesn’t fix the other files within the project.
You would have to change each file manually, which is not that great if you’re working on a project that has a lot of files.
Another thing you could do is to set the Files: Eol setting to \n
(Unix style) or auto
.
Additionally, you can use this setting by adding the following line of code into your settings.json
file:
{
"files.eol": "\n" // "auto" is by default
}
Note that this setting will only work for new files you create and not for existing ones.
Mark as ‘Done’
I hope that by reaching the end of this guide, you were able to fix the error and maybe even enjoyed it or learned something new.
If you know other ways to fix the 'Delete CR' eslint(prettier/prettier)
error, or if you’re still having trouble with it, leave me a comment below. I read all the comments and will do my best to help you out.
Happy coding 💜
Let me know what you think about this article in the comments section below.
If you find this article helpful, please share it with others and subscribe to the blog to support me, and receive a bi-monthly-ish e-mail notification on my latest articles.