为什么我总是收到 "[eslint] 删除 `CR` [prettier/prettier]" 的提示?

700
我正在使用带有Prettier 1.7.2和ESLint 1.7.0的VS Code。 每次换行后我都会遇到以下问题:
[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
  }
}

.prettierrc文件:

{
  "printWidth": 80,
  "tabWidth": 2,
  "semi": true,
  "singleQuote": true,
  "trailingComma": "es5",
  "bracketSpacing": true,
  "jsxBracketSameLine": false,
}

如何解决这个错误?


13
请查看您的.eslintrc.js文件。从扩展数组中删除“ 'plugin:prettier/recommended'”应该可以解决问题。 - Sanu Soman
4
您可以尝试禁用 ESLint VSCode 扩展。 - Amitesh
42个回答

2

我升级了 "prettier": "^2.2.0",错误消失了。


2

没有必要忽略代码检查工具的规则,只需要自动修复它。

npm install -g prettier
prettier -w .\webpack.config.js # or other file

2
从文件.prettierrc中删除这行。
 "endOfLine": "crlf"

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

在您的项目的.eslintrc.js文件中添加此内容后,请重新启动您的VSCODE
还要添加
module.exports = { 
  endOfLine: 'auto',
  // keep other values 
}

在你的项目的 '.prettierrc.js' 文件中

1
module.exports = { endOfLine: 'auto'} 这个写法是可以的 - undefined
这里有很多种方法可以做到这一点。这个方法在我的RN项目中对我很有效。 - undefined

1

这对我有用

步骤1 在React js根目录中找到.eslintrc文件

步骤2 在.eslintrc文件中查找

"prettier/prettier": [
  2,
  {
    "printWidth": 100,
    "singleQuote": true,
    "trailingComma": "none",
    "tabWidth": 2
  }
]

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

保存文件,然后运行。
npm start

0

你需要在 .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"
}

0
所有上面的答案都是正确的,但是当我使用Windows并且禁用Prettier ESLint扩展rvest.vs-code-prettier-eslint时,问题就会被解决。

0
对于那些使用 @vue/prettier 的人们可能会遇到 eslint 和它之间的冲突,导致出现这个错误。尽管 @vue/prettier 已经和 vue cli 一起安装了,但它只是一个 临时方案,直到 prettier 原生支持 vue,而这已经实现。问题可以通过切换到仅使用 'prettier' 来解决。

0
如果您已经添加了规则。
"prettier/prettier": [
      "error",
      {
        "endOfLine": "auto"
      },
    ],

在你的 .prettierrc.js 中进行修改,但问题并没有得到解决,只需重新启动节点服务器。使用 npm start 命令即可。

0
在项目中,在文件.eslintrc.js中添加你的代码。
 'prettier/prettier': [
        'error',
        {
            endOfLine: 'auto',
        },
    ],

它会修复它

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接