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

当前回答

只是在.gitconfig文件中的自专制参数为假,并重新克隆了代码。它工作!

(核心) 独裁者= false

其他回答

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

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

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

如果你想在crlf (Windows Eol),去文件->首选项->设置。在User选项卡中输入“line end of line”,并确保Files: Eol设置为\r\n,如果您使用的是Prettier扩展,请确保Prettier: line end of line设置为crlf。最后,在你的eslintrc文件中,添加以下规则:'linebreak-style': ['error', 'windows']

在我的例子中,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>

如果你想要更改为LF,并且你正在使用VS Code,你可以这样逐个文件执行:

在我的情况下(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",
};