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

如何消除这个错误?


当前回答

检查VS Code底部状态栏的右侧,在那里它显示了诸如行和列,空格,文本编码(UTF-8等)等信息。您应该看到一个Select End Of Line Sequence状态显示(LF或CRLF),您可以单击它进行更改。请确保您没有手动更改它,使其与您希望pretty使用的内容冲突。

其他回答

我知道这是旧的,但我刚刚在我的团队(一些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/

正如你所看到的,将此添加到.eslintrc工作!

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

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

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

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

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

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

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

"endOfLine": "auto"