[英]Expected linebreaks to be 'LF' but found 'CRLF' linebreak-style
When using eslint in the gulp project i have encountered a problem with error like this在 gulp 项目中使用 eslint 时,我遇到了这样的错误问题
Expected 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 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
I have also including extra.js file as the error indicating possible mistake.我还包括extra.js文件作为指示可能错误的错误。
function getWindowHeight() {
return window.innerHeight;
}
getWindowHeight();
Check if you have the linebreak-style
rule configure as below either in your .eslintrc or in source code:检查您的 .eslintrc 或源代码中是否有如下配置的换
linebreak-style
规则:
/*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 documentation of 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).
当与很多人一起开发时,他们都拥有不同的编辑器、VCS 应用程序和操作系统,可能会出现由上述任何一个编写的不同行尾(尤其是在同时使用 Windows 和 Mac 版本的 SourceTree 时可能会发生)。
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).
Windows 操作系统中使用的换行符(新行)通常是回车符(CR)后跟换行符(LF),使其成为回车换行符(CRLF),而 Linux 和 Unix 使用简单的换行符(LF)。 The corresponding control sequences are
"\n"
(for LF) and"\r\n"
for (CRLF).对应的控制序列是
"\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
选项。
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 中使用换行样式忽略它们,按照这个答案: https ://stackoverflow.com/a/43008668/1129108
module.exports = {
extends: 'google',
quotes: [2, 'single'],
globals: {
SwaggerEditor: false
},
env: {
browser: true
},
rules:{
"linebreak-style": 0
}
};
If you are using vscode and you are on Windows i would recommend you to click the option at the bottom-right of the window and set it to LF from CRLF .如果您使用的是 vscode 并且您在Windows上,我建议您单击窗口右下角的选项并将其设置为 LF 从 CRLF 。 Because we should not turn off the configuration just for sake of removing errors on Windows
因为我们不应该仅仅为了消除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。
Here is a really good way to manage this error.这是管理此错误的一种非常好的方法。 You can put the below line in .eslintrc.js file.
您可以将以下行放入 .eslintrc.js 文件中。
Based on the operating system, it will take appropriate line endings.根据操作系统,它将采用适当的行尾。
rules: {
'linebreak-style': ['error', process.platform === 'win32' ? 'windows' : 'unix'],
}
If you want it in crlf (Windows Eol), go to File -> Preferences -> Settings.如果您想在crlf (Windows Eol) 中使用它,请转到文件 -> 首选项 -> 设置。 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 .
在“用户”选项卡中键入“行尾”并确保将Files: Eol设置为\r\n ,如果您使用的是 Prettier 扩展,请确保Prettier: End of Line设置为crlf 。
Finally, on your eslintrc file, add this rule:
'linebreak-style': ['error', 'windows']
最后,在您的 eslintrc 文件中,添加以下规则:
'linebreak-style': ['error', 'windows']
Just made autocrlf
param in .gitconfig file false
and recloned the code.刚刚将
autocrlf
文件中的 autocrlf 参数设置为false
并重新克隆了代码。 It worked!有效!
[core] autocrlf = false
The same situation occurred when I was using VSCode with eslint.当我将 VSCode 与 eslint 一起使用时,也发生了同样的情况。 If you use VSCode,
如果你使用 VSCode,
1 - Click area that name can be both LF or CRLF where at the bottom right of the VScode. 1 - 单击名称可以是 LF 或 CRLF 的区域,位于 VScode 的右下角。
2 - Select LF from the drop-down menu. 2 - 从下拉菜单中选择 LF。
That's worked for me.这对我有用。
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
为了解决这个问题,我通过运行
git config --list | grep autocrlf
检查了autocrlf
值。 git config --list | grep autocrlf
and I got: 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/
如果您使用的是 vscode,我建议您单击窗口右下角的选项并将其从 CRLF 设置为 LF ..这修复了我的错误
git config core.autocrlf false git config core.autocrlf 假
git rm --cached -r . git rm --cached -r 。
git reset --hard git reset --hard
In my case (vue.js project, created using vue-cli) the lint problem Expected linebreaks to be 'LF' but found 'CRLF' linebreak-style
was related to Prettier.就我而言(vue.js 项目,使用 vue-cli 创建),lint 问题
Expected linebreaks to be 'LF' but found 'CRLF' linebreak-style
与 Prettier 有关。 From version >= 2 Prettier replace all line endings with "lf": https://prettier.io/docs/en/options.html#end-of-line从版本 >= 2 Prettier 用“lf”替换所有行尾: https ://prettier.io/docs/en/options.html#end-of-line
Since I'm using Windows to develop I set these 3 (git, eslint, prettier) configuration to avoid line endings problems:由于我使用 Windows 进行开发,因此我设置了这 3 个(git、eslint、prettier)配置以避免行尾问题:
git config --global core.autocrlf true
git config --global core.autocrlf true
module.exports = {
rules: {
'linebreak-style': ['error', 'windows'],
},
};
prettier.config.js
:prettier.config.js
中:module.exports = {
endOfLine: "crlf",
};
Tips: Make sure you have installed Git as the picture if not do that first.提示:如果没有先安装,请确保您已经安装了 Git 。 You can take other features as default, You can choose visual studio code as the default editor .
您可以将其他功能作为默认设置,您可以选择 Visual Studio 代码作为默认编辑器。 helps you a lot later.
以后对你有很大帮助。
Windows Users: Uninstall Visual Studio Code then reinstalled it again and EditorConfig should work just fine. Windows 用户:卸载 Visual Studio Code 然后重新安装它,EditorConfig 应该可以正常工作。
NOTE => Uninstalling Visual Studio Code still leaves the old settings and extensions!注意 => 卸载 Visual Studio Code 仍然保留旧设置和扩展! remove Visual Studio Code on Windows completely
完全删除 Windows 上的 Visual Studio Code
Try using the linter's --fix flag to resolve the issue.尝试使用 linter 的 --fix 标志来解决问题。
eslint filePath --fix
eslint 文件路径 --fix
I set linebreak-style to 0, but not working.我将换行样式设置为 0,但不起作用。
rules: {
"linebreak-style": 0,
},
so then I found out need to change every files from "CRLF" to "LF", and that take lots time.所以后来我发现需要将每个文件从“CRLF”更改为“LF”,这需要很多时间。
so this help所以这个帮助
git config core.autocrlf false
git rm --cached -r .
git reset --hard
The "endOfLine": "auto"
setting in .eslintrc.js
and .prettierrc
files worked for me. .eslintrc.js
和.prettierrc
文件中的"endOfLine": "auto"
设置对我有用。
File .eslintrc.js
should have:文件
.eslintrc.js
应该有:
rules: {
/* ...the other code is omitted for the brevity */
'arrow-body-style': [1, 'as-needed'],
'import/extensions': 'off',
'prettier/prettier': [
'error',
{
semi: false,
singleQuote: true,
useTabs: true,
endOfLine: 'auto', /* this setting should be included */
},
],
File .prettierrc
should have:文件
.prettierrc
应该有:
{
"semi": false,
"trailingComma": "all",
"singleQuote": true,
"useTabs": true,
"tabWidth": 2,
"endOfLine": "auto" /* this setting should be included */
}
对我来说,我通过在 .prettierrc 文件中设置 "endOfLine": "lf" 解决了这个问题。
In my case, the LF rule
was set in a file read by the maven-checkstyle-plugin
in pom.xml
.在我的例子中,
LF rule
是在pom.xml
中的maven-checkstyle-plugin
读取的文件中设置的。 The ${skipCheckstyle}
environment variable was not set.未设置
${skipCheckstyle}
环境变量。 This way I skipped the whole check.这样我就跳过了整个检查。
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<skip>${skipCheckstyle}</skip>
<configLocation>${top.dir}/src/main/config/checkstyle/checker.xml</configLocation>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.