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

当前回答

我只是想添加一个更简单的方法。在VScode的右下角单击LF或CRLF来在它们之间切换。见图

其他回答

如果你正在使用WebStorm并且你在Windows上,我建议你点击设置/编辑器/代码样式/常规选项卡,并从下拉菜单中选择“Windows (\r\n)”。这些步骤也适用于Rider。

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

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

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

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

我将换行样式设置为0,但不工作。

rules: {
    "linebreak-style": 0,
 },

所以后来我发现需要把每个文件从“CRLF”改为“LF”,这需要很多时间。

这很有帮助

git config core.autocrlf false 
git rm --cached -r . 
git reset --hard

.eslintrc.js和.prettierrc文件中的“endoline”:“auto”设置对我来说很有效。

文件.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 */
        },
    ],

文件.prettierrc应该有:

{
    "semi": false,
    "trailingComma": "all",
    "singleQuote": true,
    "useTabs": true,
    "tabWidth": 2,
    "endOfLine": "auto" /* this setting should be included */
}