当在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();

当前回答

在我的例子中,LF规则是在pom.xml中的maven-checkstyle-plugin读取的文件中设置的。 未设置环境变量${skipCheckstyle}。 这样我就跳过了整个检查。

<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>

其他回答

我发现它很有用(我想忽略换行而不改变任何文件),在.eslintrc中使用换行样式忽略它们,按照这个答案:https://stackoverflow.com/a/43008668/1129108

module.exports = {
  extends: 'google',
  quotes: [2, 'single'],
  globals: {
    SwaggerEditor: false
  },
  env: {
    browser: true
  },
  rules:{
    "linebreak-style": 0
  }
};

发生在我身上,因为我运行git配置核心。这是真的,我忘记了回头。

在那之后,当我签出/提取新代码时,所有LF (Unix中的换行符)都被CRLF (Windows中的换行符)所取代。

我运行linter,所有错误消息都是预期换行符为“LF”,但发现“CRLF”

为了解决这个问题,我通过运行git config——list | grep selflf检查了selflf的值,我得到:

core.autocrlf=true
core.autocrlf=false

我编辑了全局GIT配置~/。Gitconfig,并将selflf = true替换为selflf = false。

之后,我进入我的项目并执行以下操作(假设代码在src/文件夹中):

CURRENT_BRANCH=$(git branch | grep \* | cut -d ' ' -f2);
rm -rf src/*
git checkout $CURRENT_BRANCH src/

对我来说,我通过设置“endoline”:“lf”在。prettierrc文件。

这里有一个非常好的方法来管理这个错误。你可以把下面的代码放到.eslintrc.js文件中。

根据操作系统,它将使用适当的行结束符。

rules: {
        'linebreak-style': ['error', process.platform === 'win32' ? 'windows' : 'unix'],
 }

如果你正在使用vscode,我会建议你点击窗口右下角的选项,并将其从CRLF设置为LF.这修正了我的错误