如何在 eslint.config.js 中启用推荐的 ESLint 规则?

Mag*_*ero 5 javascript eslint

I\xe2\x80\x99m 尝试使用新的 ESLint 配置文件eslint.config.js (因为旧的 ESLint 配置文件.eslintrc.* 和 package.json 将在 ESLint 9.0.0 中弃用)。推荐的 ESLint 规则是由"extends": "eslint:recommended"旧配置文件中的属性启用的,但该属性在依赖于语句的新配置文件中不再存在import

\n

所以我import在 eslint.config.js 中尝试了这个:

\n
import config from \'eslint-config-standard\';\n\nexport default [\n  {\n    rules: config.rules\n  }\n];\n
Run Code Online (Sandbox Code Playgroud)\n

但我得到了这个TypeError

\n
$ npm exec eslint .\nOops! Something went wrong! :(\n\nESLint: 8.39.0\n\nTypeError: Key "rules": Key "import/export": Could not find plugin "import".\n
Run Code Online (Sandbox Code Playgroud)\n

如何解决这个问题呢?

\n

Auk*_*tis 2

\xe2\x80\x9c使用预定义配置\xe2\x80\x9d 部分对此进行了描述:

\n
import eslint from "@eslint/js";\n\nexport default [\n    eslint.configs.recommended\n];\n
Run Code Online (Sandbox Code Playgroud)\n