None of the answers above really worked for me.
All of them are temporary solutions that are going to work for you but not for the team, like changing the linting rule or totally disabling it.
If the team agreed to have a linting rule with line-ending LF and you have a windows machine, then you must implement a set of steps so that everything works on your machine without touching the linting rule.
First of all, check your global settings:
git config --global --list
You want to make sure that you have the value
core.autocrlf=false
If that's not the case, then run:
git config --global core.autocrlf false
This command disables automatic line ending conversion, ensuring that Git will not automatically change line endings when you commit or check out files.
In the terminal, move to your solution folder, example:
C:\git\my_project>
and run the following command:
git config core.eol lf
This will set the line ending type to use in the working directory for files that are marked as text
In your solution folder you should find a file named .gitattributes, open it and make sure you have the following instruction into it:
* text eol=lf
If not there, create it.
This will tell Git to always convert line endings to LF on checkout. You should use this for files that must keep LF endings, even on Windows.
Finally you need to refresh your repository (Stash or discard you local changes).
To update all files on the current branch to reflect the new configuration, run the following commands:
git rm -rf --cached .
git reset --hard HEAD
To display the rewritten, normalized files, run the following command.
git status
Optionally, to commit any outstanding changes in your repository, run the following command.
git commit -m "Normalize all the line endings"
Additionally, if you are using VS Code, you can enforce the LF line ending:
File -> Preferences -> Settings
References: