25

我有一个像这样的文件夹结构

parentFolder > componentA
             > componentB
             > componentC

每个组件都有一个 package.json,它定义了一个 yarn lint 命令(eslint "myFilter" --no-error-on-unmatched-pattern)。每个组件都有自己的 .eslintrc 和 .prettierrc

当我在 componentA/B/C 文件夹中并运行 yarn lint 时,它按预期工作。

由于每个组件文件夹中的所有 .eslintrc 都相同,因此我将文件移动到 parentFolder 下,并删除了组件文件夹中的副本。当我调用 yarn lint 时,它使用了 parentFolder 中的 .eslintrc,但是,我得到了一个错误。

哎呀!出问题了!:(

ESLint:6.8.0。

ESLint 找不到要扩展的配置“prettier/@typescript-eslint”。请检查配置名称是否正确。

我将 .prettierrc 移动到父文件夹,但是找不到它。我应该怎么办?谢谢

更新:我注意到如果我在父文件夹中的 package.json 添加更漂亮的并运行 yarn install,它就可以工作。但是,我不知道这是否是正确的方法。

4

4 回答 4

63

prettier/@typescript-eslint已在v8.0.0中删除。eslint-config-prettier只需从您的 ESLint 配置文件中删除它即可。为了使 Prettier 和 ESLint 不发生冲突,现在唯一需要的条目extends"prettier"(确保它是 中的最后一个extends)。

于 2021-02-23T23:39:15.010 回答
9

当我更新到 eslint-config-prettier 8.0.0 时,我遇到了同样的错误,我通过将 .eslintrc.js 更改为:

    "plugins": ['@typescript-eslint'],
    "extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"]

确保您的 package.json 包括:

 @typescript-eslint/eslint-plugin
 @typescript-eslint/parser

您当然可以包含其他插件和其他扩展,您可以找到所有选项:https ://www.npmjs.com/package/@typescript-eslint/eslint-plugin

于 2021-02-23T08:03:06.393 回答
7

prettier/@typescript-eslint was removed in eslint-config-prettier v8.0.0

see https://github.com/prettier/eslint-config-prettier/issues/173

From v8, there is simpler configuration. Unfortunately there are still many How-Tos on the Internet that mention old config files that are all gone now.

于 2021-02-24T18:08:44.430 回答
0

只需在包 .josn 中将此包添加为 dev

 "@typescript-eslint/eslint-plugin": "^4.30.0",
    "@typescript-eslint/parser": "^4.30.0",
   "eslint-config-prettier": "^8.3.0",
    "eslint-plugin-prettier": "^4.0.0",

在 eslint.js 中查看此文件添加以尝试检查它是否相同

module.exports = {
parser: '@typescript-eslint/parser',
extends: [
    'plugin:react/recommended',
    'plugin:@typescript-eslint/recommended',
    'plugin:react-hooks/recommended',
    'plugin:prettier/recommended',  
    'plugin:react-hooks/recommended',
    'eslint:recommended'
        
],
"plugins": ['@typescript-eslint'],

parserOptions: {
    ecmaVersion: 2020,
    sourceType: 'module',
    ecmaFeatures: {
        jsx: true,
    },
},
rules: {
    'react/react-in-jsx-scope': 'off',

},
settings: {
    react: {
        version: 'detect',
    },
},

};

于 2021-09-01T09:44:54.773 回答