Javascript 预期换行符为“LF”,但发现“CRLF”换行符样式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37826449/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Expected linebreaks to be 'LF' but found 'CRLF' linebreak-style
提问by SaiKiran
When using eslint in the gulp project i have encountered a problem with error like thisExpected linebreaks to be 'LF' but found 'CRLF' linebreak-style
and I am using Windows environment for the running gulp and the entire error log is given below
在 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\
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\js\extra.js
$>Users\Sai\Desktop\web-build-tools\js\extra.js
error Expected linebreaks to be 'LF' but found 'CRLF' linebreak-style
I have also including extra.jsfile as the error indicating possible mistake.
我还包括extra.js文件作为指示可能错误的错误。
function getWindowHeight() {
return window.innerHeight;
}
getWindowHeight();
回答by Dheeraj Vepakomma
Check if you have the linebreak-style
rule configure as below either in your .eslintrc or in source code:
检查linebreak-style
您的 .eslintrc 或源代码中是否有如下规则配置:
/*eslint linebreak-style: ["error", "unix"]*/
Since you're working on Windows, you may want to use this rule instead:
由于您在 Windows 上工作,您可能希望改用此规则:
/*eslint linebreak-style: ["error", "windows"]*/
Refer to the documentationof linebreak-style
:
请参阅文件的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).
当很多人都拥有不同的编辑器、VCS 应用程序和操作系统时,可能会发生不同的行尾由上述任何一个编写(尤其是在同时使用 Windows 和 mac 版本的 SourceTree 时发生)。
Windows 操作系统中使用的换行符(新行)通常是回车 (CR) 后跟换行 (LF),使其成为回车换行 (CRLF),而 Linux 和 Unix 使用简单的换行 (LF)。对应的控制序列是
"\n"
(对于LF)和"\r\n"
对于(CRLF)。
This is a rule that is automatically fixable. The --fix
option on the command line automatically fixes problems reported by this rule.
这是一个可以自动修复的规则。在--fix
命令行上选择自动修复此规则报告的问题。
But if you wish to retain CRLF
line-endings in your code (as you're working on Windows) do not use the fix
option.
但是,如果您希望CRLF
在代码中保留行结尾(因为您在 Windows 上工作)请不要使用该fix
选项。
回答by The Coder
I found it useful (where I wanted to ignore line feeds and not change any files) to ignore them in the .eslintrc using linebreak-style as per this answer: https://stackoverflow.com/a/43008668/1129108
我发现它很有用(我想忽略换行符而不更改任何文件)在 .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
}
};
回答by Mr_Perfect
If you are using vscode and you are on Windowsi would recommend you to click the option at the bottom-right of the window and set it to LF from CRLF. Because we should not turn off the configuration just for sake of removing errors on Windows
如果您使用的是 vscode 并且您在Windows 上,我建议您单击窗口右下角的选项并将其设置为 LF from CRLF。因为我们不应该为了消除Windows 上的错误而关闭配置
If you don't see LF / CLRF, then right click the status bar and select Editor End of Line.
如果您没有看到 LF / CLRF,请右键单击状态栏并选择 Editor End of Line。
回答by vnxyz
Just made autocrlf
param in .gitconfig file false
and recloned the code. It worked!
刚刚autocrlf
在 .gitconfig 文件中创建了paramfalse
并重新克隆了代码。有效!
[core]
autocrlf = false
[core]
autocrlf = false
回答by Abdennour TOUMI
Happen with me because I ran git config core.autocrlf true
and I forgot to rever back.
发生在我身上,因为我跑了git config core.autocrlf true
,我忘了回敬。
After that, when I checkout/pull new code, all LF (break line in Unix) was replaced by CRLF (Break line in Windows).
之后,当我检出/拉取新代码时,所有 LF(Unix 中的断行)都被 CRLF(Windows 中的断行)替换了。
I ran linter, and all error messages are Expected linebreaks to be 'LF' but found 'CRLF'
我跑了 linter,所有的错误信息都是 Expected linebreaks to be 'LF' but found 'CRLF'
To fix the issue, I checked autocrlf
value by running git config --list | grep autocrlf
and I got:
为了解决这个问题,我autocrlf
通过运行检查了 值git config --list | grep autocrlf
,我得到了:
core.autocrlf=true
core.autocrlf=false
I edited the global GIT config ~/.gitconfig
and replaced autocrlf = true
by autocrlf = false
.
我编辑了全局 GIT 配置~/.gitconfig
并替换autocrlf = true
为autocrlf = false
.
After that, I went to my project and do the following (assuming the code in src/
folder):
之后,我转到我的项目并执行以下操作(假设src/
文件夹中的代码):
CURRENT_BRANCH=$(git branch | grep \* | cut -d ' ' -f2);
rm -rf src/*
git checkout $CURRENT_BRANCH src/
回答by Athif Shaffy
If you are using vscode I would recommend you to click the option at the bottom-right of the window and set it to LF from CRLF..this fixed my errors
如果您使用的是 vscode,我建议您单击窗口右下角的选项并将其从 CRLF 设置为 LF..这修复了我的错误
回答by CLUTCHER
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: Eolis set to \r\nand if you're using the Prettier extension, make sure Prettier: End of Lineis set to crlf. Finally, on your eslintrc file, add this rule:
'linebreak-style': ['error', 'windows']
如果您想在crlf(Windows Eol) 中使用它,请转到文件 -> 首选项 -> 设置。在“用户”选项卡中键入“行尾”并确保将Files: Eol设置为\r\n,如果您使用的是 Prettier 扩展名,请确保将Prettier: End of Line设置为crlf。最后,在您的 eslintrc 文件中,添加以下规则:
'linebreak-style': ['error', 'windows']