Delete '␍' eslint(prettier/prettier) error solution
problem background
Windows
After pulling the code on the notebook, when executing it , pre-commit
the following error occurs:
Delete `␍`eslint(prettier/prettier)
Here are a few solutions I've personally tried:
solution
1. Crtl+S to save the file
Press Crtl+S
Save the current error report file, eslint
the error disappears, but Git
there is an additional file change record in the temporary storage area, and Working tree
no difference is found in the comparison.
Disadvantages: You can't save all files one by one, which is troublesome and commit
redundant.
二、yarn run lint --fix
It is easier than the above, and eslint
the error disappears, but there are more n
file change records in the temporary storage area, and Working tree
no difference is found in the comparison.
Cons: Needs commit
all files, redundant.
Reference: "error Delete ⏎ prettier/prettier" in .vue files ``
3. Configure the .prettierrc file
.prettierrc
Just write in the file in the root directory of the project . In fact, it is prettier
the format that does not allow the detection of the end of each line of the file.
"endOfLine": "auto"
Disadvantages: It is not compatible with cross-platform development, and it is not perfect in terms of front-end engineering.
参考资料:Why do I keep getting Delete ‘cr’ [prettier/prettier]?
4. One-key switching through IDE
[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-UQxZMB7g-1673344596978)(https://segmentfault.com/img/bVcPuZP “image”)]
This is the method provided by Nuggets in the comment area. Generally, the status bar below the IDE will provide a tool to "switch the line ending sequence". As shown in the figure above, you can switch to the correct line ending sequence with one click.
Disadvantage: It can only repair the current file, but cannot solve the problem of error reporting for the entire project.
Five, the best solution
Root cause of the problem:
The culprit is git
a configuration property of:core.autocrlf
For historical reasons, the text files windows
below and below have inconsistent line breaks.linux
Windows
When changing the line, both carriage returnCR(carriage-return character)
and line feed are usedLF(linefeed character
)- And
Mac
theLinux
system, just use the newline characterLF
- Older versions of
Mac
the system used the carriage return characterCR
Windows | Linux/Mac | Old Mac(pre-OSX) |
---|---|---|
CRLF | LF | CR |
‘\n\r’ | ‘\n’ | ‘\r’ |
Therefore, there will be incompatibility problems when text files are created and used under different systems.
Linux
The code submitted in the environment is the default in my project warehouse , and the file ends with LF
the default (engineering needs, unified standards).
When I use windows
computer git clone
code, if mine autocrlf
(installed windows
below git
, this option defaults to true
) true
, then each line of the file will be automatically converted to CRLF
end with , if no modification is made to the file, it will prompt you when pre-commit
executing eslint
delete CR
.
Now you can understand why ctrl+s
and yarn run lint --fix
the program can fix eslint
the error, because it will be converted Git
automatically .CRLF
LF
Best Practices:
Now VScode
, Notepad++
the editor can automatically recognize whether the line break of the file is LF or CRLF
.
If you are using windows
, the file encoding is UTF-8
and contains Chinese, it is best to autocrlf
set it globally false
.
git config --global core.autocrlf false
Note: git
After global configuration, you need to pull the code again.
Summarize
I searched a lot of information, stackoverflow
and github
there are corresponding discussions and solutions to this problem on website and online, but none of them can touch the soul. Write this article for future reading. If it is helpful to friends who are in trouble, the author will never tire of it!