简体   繁体   中英

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.

then I installed eslint and some config extension globally.

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

{
 "env": {
 "browser": true,
 "es6": true,
 "node": true
 },
 "extends": [
 "airbnb-base"
 ],
 "rules": {
 }
}

But I got error when I lint my js file

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. 在此处输入图像描述

Did I miss something? I don't want to install eslint-plugin** in each of project

Probably a bit late for you but I don't think you can install eslint plugins globally.
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

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.

Essentially, your directory tree should like the following now:

projects/
  package.json
  .eslintrc
  node_modules/
    ...
  my_cool_project/
    ...
  my_cool_project2/
    ...
  ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM