将 .eslintrc 重定位到父级后,ESLint 找不到配置 "prettier/@typescript-eslint"

ESLint couldn't find the config "prettier/@typescript-eslint" after relocating .eslintrc to parent

我的文件夹结构类似于

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,但是,我收到一个错误。

Oops! Something went wrong! :(

ESLint: 6.8.0.

ESLint couldn't find the config "prettier/@typescript-eslint" to extend from. Please check that the name of the config is correct.

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

更新: 我注意到如果我在父文件夹的 package.json 上添加 prettier 并且 运行 安装纱线,它会起作用。但是,我不知道这样做是否正确。

我更新到 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

prettier/@typescript-eslinteslint-config-prettier v8.0.0 中已 removed。只需将其从 ESLint 配置文件中删除即可。 extends 中唯一需要 Prettier 和 ESLint 不冲突的条目是 "prettier"(确保它是 extends 中的最后一个)。

prettier/@typescript-eslint 已在 eslint-config-prettier v8.0.0

中删除

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

从 v8 开始,配置更简单。不幸的是,Internet 上仍然有许多 How-Tos 提到现在已经全部消失的旧配置文件。

只需在包 .json 中添加此包 作为开发者

 "@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',
    },
},

};