[英]Enable global ESlint config
I want to make a eslint config works globally, so that I don't need to init it in each project.我想让一个 eslint 配置在全球范围内工作,这样我就不需要在每个项目中都初始化它。
then I installed eslint and some config extension globally.然后我在全局安装了 eslint 和一些配置扩展。
npm install -g eslint eslint-config-airbnb eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-react eslint-plugin-react-hooks
And this is my eslint config file ~/.eslintrc.json这是我的 eslint 配置文件~/.eslintrc.json
{
"env": {
"browser": true,
"es6": true,
"node": true
},
"extends": [
"airbnb-base"
],
"rules": {
}
}
But I got error when I lint my js file但是当我检查我的 js 文件时出现错误
ESLint couldn't find the config "airbnb-base" to extend from. Please check that the name of the config is correct.
The config "airbnb-base" was referenced from the config file in "/home/molly/.eslintrc.json".
This is my global installed packages, airbnb is there.这是我的全局安装包,airbnb 就在那里。
Did I miss something?我错过了什么? I don't want to install eslint-plugin** in each of project
我不想在每个项目中安装 eslint-plugin**
Probably a bit late for you but I don't think you can install eslint plugins globally.对你来说可能有点晚了,但我认为你不能在全球范围内安装 eslint 插件。
The way around that worked for me is to create a directory where all my projects go and inside that directory create a package.json
( npm init -y
) and install all the plugins in that directory npm i -D eslint-config-airbnb eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-react eslint-plugin-react-hooks
对我有用的方法是创建一个目录,我的所有项目都在该目录中,并在该目录中创建一个
package.json
( npm init -y
) 并在该目录中安装所有插件npm i -D eslint-config-airbnb eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-react eslint-plugin-react-hooks
Bring your global .eslintrc
file in that directory which will act like a root eslint config for all your projects that's inside that directory now.将您的全局
.eslintrc
文件放入该目录中,该目录现在将充当该目录中所有项目的根 eslint 配置。
Essentially, your directory tree should like the following now:本质上,您的目录树现在应该如下所示:
projects/
package.json
.eslintrc
node_modules/
...
my_cool_project/
...
my_cool_project2/
...
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.