Lar*_*ger 5 javascript typescript reactjs eslint next.js
我有一个打字稿 NextJS 项目,其中包含以下内容.eslintrc.json:
{
"extends": "next/core-web-vitals"
}
Run Code Online (Sandbox Code Playgroud)
我想添加一些额外的打字稿规则(例如不允许输入 any ( no-explicit-any))。
npm install --save-dev @typescript-eslint/parser @typescript-eslint/eslint-pluginno-explicit-any,更新解析器并添加插件。{
"extends": "next/core-web-vitals",
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint"
],
"rules": {
"@typescript-eslint/no-explicit-any": "warn"
}
}
Run Code Online (Sandbox Code Playgroud)
no-explicit-any作品。然而,所有默认规则都next/core-web-vitals不再起作用。所以我可以使用下一个或使用 typescript-eslint 规则。如何使用展位?
您应该能够将两个预设包含在单个属性的数组中"extends",类似于:
{
"parser": "@typescript-eslint/parser",
"plugins": ["react", "@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"next/core-web-vitals"
],
"parserOptions": {
"project": "./tsconfig.json",
}
}
Run Code Online (Sandbox Code Playgroud)