我使用VS Code与漂亮的1.7.2和ESLint 1.7.0。 在每个换行符之后:

[eslint] Delete `CR` [prettier/prettier]

这是.eslintrc.json:

{
  "extends": ["airbnb", "plugin:prettier/recommended"],
  "env": {
    "jest": true,
    "browser": true
  },
  "rules": {
    "import/no-extraneous-dependencies": "off",
    "import/prefer-default-export": "off",
    "no-confusing-arrow": "off",
    "linebreak-style": "off",
    "arrow-parens": ["error", "as-needed"],
    "comma-dangle": [
      "error",
      {
        "arrays": "always-multiline",
        "objects": "always-multiline",
        "imports": "always-multiline",
        "exports": "always-multiline",
        "functions": "ignore"
      }
    ],
    "no-plusplus": "off"
  },
  "parser": "babel-eslint",
  "plugins": ["react"],
  "globals": {
    "browser": true,
    "$": true,
    "before": true,
    "document": true
  }
}

. pretierrc文件:

{
  "printWidth": 80,
  "tabWidth": 2,
  "semi": true,
  "singleQuote": true,
  "trailingComma": "es5",
  "bracketSpacing": true,
  "jsxBracketSameLine": false,
}

如何消除这个错误?


当前回答

我升级到“更漂亮”:“^2.2.0”,错误消失了

其他回答

NPM运行lint -- --fix

运行这个命令,这对我有用

在我的情况下,我使用windows操作系统和git代码支持Mac和转换为CRLF 在cmd提示符下运行命令停止文件转换为CRLF:

git config --global core.autocrlf input

再次签出代码并再次打开Visual Studio code并再次运行脚本。这对我很管用。

对我有用的是:

按照Roberto LL的建议,更新到2.2.1版本(目前的最新版本)。要执行它

NPM更新更漂亮

按照Hakan的建议执行lint修复(这将修改项目中的所有文件,将行结束转换为LF)。

NPM运行lint -- --fix

没有必要更改.eslintrc和.prettierrc文件!

我知道这是旧的,但我刚刚在我的团队(一些mac,一些linux,一些windows,所有的vscode)遇到了这个问题。

解决方案是在vscode的设置中设置行结束:

.vscode/settings.json

{
    "files.eol": "\n",
}

https://qvault.io/2020/06/18/how-to-get-consistent-line-breaks-in-vs-code-lf-vs-crlf/

最好的解决方案是使用.editorconfig。特别是当您与不同类型操作系统的团队一起工作时。因此,在.eslintrc中禁用prettier根本不是一个好的选择。

从vscode扩展安装.editorconfig。在你的项目根目录下创建一个。editorconfig文件,并把它放到你的。gitignore文件中,这样就不会打扰你的队友了。

将其添加到您的.editorconfig文件中,或者从文档中选择您需要的工作流设置。

[*]
end_of_line = lf

这将自动保存您的文件到EOL类型lf,而不是在windows中的crlf。反之亦然,如果使用mac。或取决于项目工作流程设置。

根本原因是windows默认为crlf。所以每次你尝试创建一个文件,你将面对这个漂亮的删除'cr'错误。

除了

如果你从git中获得的所有文件都包含删除'cr'。

删除项目 重新安装git并选择按原样结帐,提交unix风格的行结束符 再次从回购中克隆您的项目 使用上面设置的.editorconfig