我使用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.js一些规则看起来像这样:

rules: {
    'prettier/prettier': ['error', { "endOfLine": "auto"}, { usePrettierrc: true }],  // Use our .prettierrc file as source
    'react/react-in-jsx-scope': 'off',
    'react/prop-types': 'off',
    'simple-import-sort/imports': 'error',
    "simple-import-sort/exports": "error"
}

其他回答

我在我的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',
  },
],

},

对于那些使用@vue/prettier的人来说,它和eslint之间可能存在冲突,从而导致此错误。尽管@vue/prettier是与vue cli一起安装的,但它只是一个临时解决方案,直到prettier原生地接受vue,而这已经完成了。问题可以通过“更漂亮”来解决。

对我有用的是:

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

NPM更新更漂亮

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

NPM运行lint -- --fix

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

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

git config --global core.autocrlf input

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

在.eslintrc文件中添加以下内容:

Extends: ['prettier']和plugins: ['prettier'] 规则:{'更漂亮/更漂亮':['错误',{endoline: 'auto'}]}

在. pretierrc中删除:

endOfLine:’auto’

这对我很管用。