簡體   English   中英

啟用全局 ESlint 配置

[英]Enable global ESlint config

我想讓一個 eslint 配置在全球范圍內工作,這樣我就不需要在每個項目中都初始化它。

然后我在全局安裝了 eslint 和一些配置擴展。

npm install -g eslint eslint-config-airbnb eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-react eslint-plugin-react-hooks

這是我的 eslint 配置文件~/.eslintrc.json

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

但是當我檢查我的 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".

這是我的全局安裝包,airbnb 就在那里。 在此處輸入圖像描述

我錯過了什么? 我不想在每個項目中安裝 eslint-plugin**

對你來說可能有點晚了,但我認為你不能在全球范圍內安裝 eslint 插件。
對我有用的方法是創建一個目錄,我的所有項目都在該目錄中,並在該目錄中創建一個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

將您的全局.eslintrc文件放入該目錄中,該目錄現在將充當該目錄中所有項目的根 eslint 配置。

本質上,您的目錄樹現在應該如下所示:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM