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

如何消除这个错误?


当前回答

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

End_of_line = lf

to

End_of_line = auto

这应该可以修复新文件。

其他回答

错误出现时,我拉代码从git,这为我工作:

步骤1:

Git配置——全局核心。autocrlf假

步骤2:

删除当前文件夹

步骤3:

再次从git中提取代码 尝试再次运行命令

我在我的nest js应用程序中也有同样的问题。将下面的代码添加到.eslintrc.jsrules中,然后运行yarn run lint——fix修复了这个问题。

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

我的.eslintrc.js规则看起来是这样的。

 rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'prettier/prettier': [
  'error',
  {
    endOfLine: 'auto',
  },
],

},

编辑.eslintrc.json文件并更新如下所示的"prettier/prettier"值。

我也面临同样的问题,并修改了使用下面的更改。

"prettier/prettier": [
    "error", {
         "singleQuote": true,
         "parser": "flow" 
    }
],

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

在VSCode上改变这个设置。