Today pull the code for development, a run, saw this nearly a thousand warnings, meng, hurriedly find a solution, the following to introduce it.
Cause of the problem
I checked the Internet and found that the cause of the problem is that the newline characters of text files in Windows and Linux are inconsistent.
Windows: CRLF (use the carriage return newline at the end of the sentence, i.e. in Windows “\r\ N “newline)
Linux: LF (indicates the end of a sentence, use newline only, i.e. the end is “\n”)
MAC: CR (using carriage return only, i.e. ending with “\r”)
The solution
Plan 1: Manually change the CRLF to LF
Yarn Run Lint –fix
Disadvantages: ESLint errors disappear, but n more file changes are recorded in the temporary storage.
yarn run lint --fix
Copy the code
I use YARN, or if I use NPM
npm run lint --fix
Copy the code
Solution 3: Modify the. Prettierrc file
"Prettier /prettier": ["error", {.. "endOfLine":"auto"// Doesn't let Prettier detect the end of a line...}],Copy the code
Best practices
The trigger for creating git clone code (for Windows) automatically changes the end of the file to CRLF (for example, by default), and then the trigger for removing CR will be triggered at the end of esLint if nothing is done to the file.
The ultimate solution is to change the trigger LF configuration property in Git. Run the following code from the command line:
Note: After git global configuration, the new pull code is ready.
git config --global core.autocrlf false
Copy the code
Trigger lf (core. Trigger lf) is a variable in Git that processes line ending and has three values: true, false, and input.
(1) change the change to true (config –global core. Autocrat
When set to true, this means that any time you add a file to a Git repository, Git treats it as a text file. It will change CRLF into LF.
(2) change the value to false (config –global core. Autocrat false)
When set to false, the line Hamid does not switch. The text file remains as it was.
(3) When set to input, add file git repository, git program CRLF lf. Lf when someone checks code. Therefore, do not use this setting on Windows.
Refer to the article
Delete ␍
Eslint (prettier/prettier) error