代码之家  ›  专栏  ›  技术社区  ›  Dylan Ju

eslint不处理多个包。json

  •  4
  • Dylan Ju  · 技术社区  · 7 年前

    我的项目有两个包。json

    root folder
    
    └ app ---- /public
             └ /styles
             └ /src
             └ package.json
             └ eslintrc.json
             └ webpack.config.js
    
    └ server - /something
             └ /something
    
    └ package.json
    └ ...etc
    

    import React from 'react';
    // 'react' should be listed in the project's dependencies. Run 'npm i -S react' to add it (import/no-extraneous-dependencies)
    

    包装内。json

    "dependencies": {
      "@types/chart.js": "^2.6.8",
      "@types/react": "^16.0.10",
      "@types/react-dom": "^16.0.1",
      "bootstrap": "^4.0.0-beta",
      "chart.js": "2.6.0",
      "font-awesome": "^4.7.0",
      "history": "4.7.2",
      "jwt-decode": "^2.2.0",
      "prop-types": "^15.6.0",
      "react": "^15.6.1",
      "react-chartjs-2": "2.6.1",
      "react-dom": "^15.6.1",
      "react-router-dom": "4.2.2",
      "react-transition-group": "^1.2.0",
      "reactstrap": "^4.8.0",
      "simple-line-icons": "^2.4.1"
    },
    

    在eslintrc中。json

    module.exports = {
      "extends": "airbnb",
    
      "env": {
         "browser": true,
         "node": true
       },
    
      "rules": {
         "no-mixed-operators": [2, { "allowSamePrecedence": true }],
         "react/no-find-dom-node": 1,
         "react/no-string-refs": 1,
         "react/no-unused-prop-types": 1, // TODO: enable
         "jsx-a11y/no-static-element-interactions": 1, // TODO: enable
         "no-plusplus": 1, // TODO: enable
         "no-console": 0, // TODO: enable
         "no-alert": 0,
         "max-len": ["error", 120],
         "no-underscore-dangle": ["error", { "allow": ["_isMounted"] }],
         "import/no-extraneous-dependencies": ["error", {"devDependencies": true}],
      },
    };
    

    我认为eslint能够识别包。根文件夹中的json作为标准。

    我该怎么办?

    2 回复  |  直到 7 年前
        1
  •  4
  •   Community CDub    4 年前

    这可能与此无关,但我要注意的第一点是,您可能需要从 eslintrc.json .eslintrc.json (名称前带点)。可能不是问题的根源,但可能会干扰层次分辨率。您可以在此处查看多种配置扩展格式: https://eslint.org/docs/user-guide/configuring#configuration-file-formats

    关于 import/no-extraneous-dependencies 具体来说,我认为您可能需要的配置选项是 packageDir . 在回购中引用文件:

    还有一个选项叫做 包装目录 ,此选项用于指定包含的文件夹的路径 package.json 和相对于当前工作目录。

    "import/no-extraneous-dependencies": ["error", {"packageDir": './some-dir/'}]

    希望这有帮助!

    资料来源:

    https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-extraneous-dependencies.md

        2
  •  2
  •   Dylan Ju    7 年前

    我自己解决了这个问题。

    在中添加了“packageDir”:“./src”。eslintrc。json

    "rules" : {
       ""import/no-extraneous-dependencies": ["error", {"devDependencies": true, "packageDir": "./src"}],