在gulp项目中使用eslint的时候遇到了这样的错误
预期换行符为“LF”,但发现换行符样式为“CRLF”
,我正在使用 Windows 环境运行 gulp,整个错误日志如下所示
Kiran (master *) Lesson 4 $ gulp
Using gulpfile c:\Users\Sai\Desktop\web-build-tools\4\
gulpfile.js
Starting 'styles'...
Finished 'styles' after 17 ms
Starting 'lint'...
'lint' errored after 1.14 s
ESLintError in plugin 'gulp-eslint'
sage: Expected linebreaks to be 'LF' but found 'CRLF'.
ails: fileName: c:\Users\Sai\Desktop\web-build-tools\4\js\extra.js
$>Users\Sai\Desktop\web-build-tools\4\js\extra.js
error Expected linebreaks to be 'LF' but found 'CRLF' linebreak-style
我还包括 extra.js 文件作为指示可能错误的错误。
function getWindowHeight() {
return window.innerHeight;
}
getWindowHeight();
最佳答案
检查您的 .eslintrc 或源代码中是否有 linebreak-style
规则配置如下:
/*eslint linebreak-style: ["error", "unix"]*/
由于您在 Windows 上工作,您可能希望改用此规则:
/*eslint linebreak-style: ["error", "windows"]*/
引用documentation linebreak-style
:
When developing with a lot of people all having different editors, VCS applications and operating systems it may occur that different line endings are written by either of the mentioned (might especially happen when using the windows and mac versions of SourceTree together).
The linebreaks (new lines) used in windows operating system are usually carriage returns (CR) followed by a line feed (LF) making it a carriage return line feed (CRLF) whereas Linux and Unix use a simple line feed (LF). The corresponding control sequences are
"\n"
(for LF) and"\r\n"
for (CRLF).
这是一条可自动修复的规则。命令行上的 --fix
选项会自动修复此规则报告的问题。
但是,如果您希望在代码中保留 CRLF
行尾(因为您在 Windows 上工作),请不要使用 fix
选项。
关于javascript - 预期换行符为 'LF' 但发现 'CRLF' 换行符样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37826449/