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

如何消除这个错误?


当前回答

在.eslintrc.json文件中 在侧角色添加此代码将解决这个问题

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

  }

其他回答

您需要在.eslintrc文件中添加规则

"extends": ["plugin:prettier/recommended"],
"plugins": ["prettier"],
"rules": {
 "prettier/prettier": ["error"],
 "@typescript-eslint/no-unsafe-call": "off",
 "@typescript-eslint/unbound-method": "off",
 "@typescript-eslint/no-explicit-any": "off",
 "@typescript-eslint/no-unsafe-member-access": "off",
 "@typescript-eslint/no-unsafe-assignment": "off",
 "@typescript-eslint/no-empty-function": "off",
 "@angular-eslint/no-empty-lifecycle-method": "off",
 "@typescript-eslint/no-unused-vars": ["off"],
 "@typescript-eslint/require-await": "off",
 "@typescript-eslint/ban-types": "off"
}

在根目录下打开。editorconfig文件,修改如下:

End_of_line = lf

to

End_of_line = auto

这应该可以修复新文件。

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

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

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