Sai*_*ran 130 javascript line-endings eslint gulp
当在gulp项目中使用eslint时,我遇到了这样的错误问题,
Expected linebreaks to be 'LF' but found 'CRLF' linebreak-style我使用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
Run Code Online (Sandbox Code Playgroud)
我还包括extra.js文件作为指示可能的错误的错误.
function getWindowHeight() {
return window.innerHeight;
}
getWindowHeight();
Run Code Online (Sandbox Code Playgroud)
Dhe*_*.S. 175
检查linebreak-style您的.eslintrc或源代码中是否配置了以下规则:
/*eslint linebreak-style: ["error", "unix"]*/
Run Code Online (Sandbox Code Playgroud)
由于您正在使用Windows,因此您可能希望使用此规则:
/*eslint linebreak-style: ["error", "windows"]*/
Run Code Online (Sandbox Code Playgroud)
请参阅文件的linebreak-style:
当开发时很多人都有不同的编辑器,VCS应用程序和操作系统,可能会出现不同的行结尾都是由上述任何一个编写的(当使用Windows和Mac版本的SourceTree时可能会发生这种情况).
Windows操作系统中使用的换行符(新行)通常是回车符(CR),后跟换行符(LF),使其成为回车换行符(CRLF),而Linux和Unix使用简单的换行符(LF).相应的控制序列是
"\n"(用于LF)和"\r\n"用于(CRLF).
这是一个可自动修复的规则.在--fix命令行上选择自动修复此规则报告的问题.
但是,如果您希望CRLF在代码中保留行尾(当您在Windows上工作时),请不要使用该fix选项.
The*_*der 108
我发现它很有用(我想忽略换行符而不是更改任何文件)在.eslintrc中使用linebreak-style忽略它们,如下所示:https://stackoverflow.com/a/43008668/1129108
module.exports = {
extends: 'google',
quotes: [2, 'single'],
globals: {
SwaggerEditor: false
},
env: {
browser: true
},
rules:{
"linebreak-style": 0
}
};
Run Code Online (Sandbox Code Playgroud)
Mr_*_*ect 60
如果您使用的是vscode而且您使用的是Windows,我建议您单击窗口右下角的选项并将其从CRLF设置为LF.因为我们不应该为了在Windows上删除错误而关闭配置
小智 23
在 Vue js 的 .eslintrc 文件 'linebreak-style':0 中添加我们的规则
rules: {
'linebreak-style':0,
}
Run Code Online (Sandbox Code Playgroud)
CLU*_*HER 20
If you want it in crlf (Windows Eol), go to File -> Preferences -> Settings. Type "end of line" in the User tab and make sure Files: Eol is set to \r\n and if you're using the Prettier extension, make sure Prettier: End of Line is set to crlf.
Finally, on your eslintrc file, add this rule: 'linebreak-style': ['error', 'windows'] 
har*_*nat 19
这是管理此错误的一个非常好的方法。您可以将以下行放在 .eslintrc.js 文件中。
根据操作系统,它将采用适当的行尾。
rules: {
'linebreak-style': ['error', process.platform === 'win32' ? 'windows' : 'unix'],
}
Run Code Online (Sandbox Code Playgroud)
小智 17
git config core.autocrlf false
git rm --cached -r 。
git重置——硬
当我将 VSCode 与 eslint 一起使用时,也发生了同样的情况。如果你使用 VSCode,
1 - 单击位于 VScode 右下角的名称可以是 LF 或 CRLF 的区域。
2 - 从下拉菜单中选择 LF。
这对我有用。
和我一起发生是因为我跑步了git config core.autocrlf true,我忘记了回来。
之后,当我签出/拉出新代码时,所有的LF(Unix中的换行)都被CRLF(Windows中的换行)代替。
我跑了linter,所有错误消息都是 Expected linebreaks to be 'LF' but found 'CRLF'
要解决此问题,我autocrlf通过运行检查了 值,git config --list | grep autocrlf并得到:
core.autocrlf=true
core.autocrlf=false
Run Code Online (Sandbox Code Playgroud)
我编辑了全局GIT配置,~/.gitconfig并替换autocrlf = true为autocrlf = false。
之后,我去了我的项目并执行以下操作(假设src/文件夹中的代码):
CURRENT_BRANCH=$(git branch | grep \* | cut -d ' ' -f2);
rm -rf src/*
git checkout $CURRENT_BRANCH src/
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
152594 次 |
| 最近记录: |