尝试在 create-react-app 项目中扩展 ESLint 的问题
Issues trying to extend ESLint in a create-react-app project
Create-react-app 允许您扩展 create-react-app 附带的 ESLint 配置:
https://create-react-app.dev/docs/setting-up-your-editor#experimental-extending-the-eslint-config
然而,当我尝试在我自己的项目中这样做时,我得到了这个错误
(Image of error)
错误
Error: Cannot find module 'eslint-config-shared-config'
命令运行
eslint --ignore-path .gitignore --ext .js,.ts,.tsx .
.eslintrc
{
"extends": ["react-app", "shared-config"],
"rules": {
"additional-rule": "warn"
},
"overrides": [
{
"files": ["**/*.ts?(x)"],
"rules": {
"additional-typescript-only-rule": "warn"
}
}
]
}
设置基础 ESLint 配置文件的安全方法是遵循 ESLint usage guide
$ npx eslint --init
# or
$ yarn run eslint --init
就像@jonrsharpe 说的,shared-config
只是一个例子,不能按字面意思使用,文档试图解释你可以使用共享配置。
例如,如果您添加一个带有 shared-config
规则集的 ESLint 插件,那么您可以按照示例所示使用它。
Create-react-app 允许您扩展 create-react-app 附带的 ESLint 配置:
https://create-react-app.dev/docs/setting-up-your-editor#experimental-extending-the-eslint-config
然而,当我尝试在我自己的项目中这样做时,我得到了这个错误 (Image of error)
错误
Error: Cannot find module 'eslint-config-shared-config'
命令运行
eslint --ignore-path .gitignore --ext .js,.ts,.tsx .
.eslintrc
{
"extends": ["react-app", "shared-config"],
"rules": {
"additional-rule": "warn"
},
"overrides": [
{
"files": ["**/*.ts?(x)"],
"rules": {
"additional-typescript-only-rule": "warn"
}
}
]
}
设置基础 ESLint 配置文件的安全方法是遵循 ESLint usage guide
$ npx eslint --init
# or
$ yarn run eslint --init
就像@jonrsharpe 说的,shared-config
只是一个例子,不能按字面意思使用,文档试图解释你可以使用共享配置。
例如,如果您添加一个带有 shared-config
规则集的 ESLint 插件,那么您可以按照示例所示使用它。