当在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或源代码中配置了如下换行样式的规则:
/*eslint linebreak-style: ["error", "unix"]*/
因为你在Windows上工作,你可能想要使用这个规则:
/*eslint linebreak-style: ["error", "windows"]*/
请参阅换行样式的文档:
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选项。
在我的情况下(vue.js项目,使用vue-cli创建),lint问题预期换行符是“LF”,但发现“CRLF”换行风格与pretty相关。
从版本>= 2更漂亮的替换所有行结尾“lf”:https://prettier.io/docs/en/options.html#end-of-line
由于我使用Windows开发,我设置了这3个(git, eslint,更漂亮)配置,以避免行结束问题:
Git:我设置了Git配置全局核心。autocrlf真实
eslint:在.eslintrc.js文件中配置:
module.exports = {
rules: {
'linebreak-style': ['error', 'windows'],
},
};
最后在prettier.config.js中:
module.exports = {
endOfLine: "crlf",
};