我使用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,
}

如何消除这个错误?


当前回答

将此添加到.prettierrc文件并打开VSCODE

"endOfLine": "auto"

其他回答

上面所有的答案都是正确的,但当我使用窗口并禁用更漂亮的ESLint扩展投资。Vs-code-prettier-eslint的问题将被修复。

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

git config --global core.autocrlf input

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

最好的解决方案是使用.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

我在这里尝试了所有的东西,对我来说,我需要管理更漂亮的配置扩展通过图标扩展>更漂亮>小引擎>扩展设置>更漂亮:结束>设置为自动。

在我的settings.json中添加这两行之后

"eslint.run": "onSave",
"editor.formatOnSave": true,

我可以在.eslintrc.js规则中使用下面的配置。

"prettier/prettier": ["error", {
    "endOfLine":"auto"
}],

试试这个。这对我来说很管用:

纱线跑线——固定

or

NPM运行lint -- --fix