import-js/eslint-plugin-import

no-extraneous-dependencies not checking dependencies

Aperta

#1177 aperta il 1 ott 2018

 (12 commenti) (0 reazioni) (0 assegnatari)JavaScript (1549 fork)batch import
bughelp wanted

Metriche repository

Star
 (5940 stelle)
Metriche merge PR
 (Merge medio 138g 22h) (3 PR mergiate in 30 g)

Descrizione

The same question on stackoverflow https://stackoverflow.com/questions/52554918/eslint-no-extraneous-dependencies-issue

I have a problem with eslint rule import/no-extraneous-dependencies

What needs to do. If js file has import with a package which not present in closest parent package.json - show error.

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

Project very simple: Structure of folders:

    ./
    ├── eslintrc.js
    ├── index.html
    ├── index.js
    └── package.json
    
    0 directories, 4 files

Package.json:

    {
      "name": "test",
      "version": "1.0.0",
      "main": "index.js",
      "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1"
      },
      "license": "ISC",
      "dependencies": {
        "jquery": "^3.3.1"
      },
      "devDependencies": {
        "eslint": "^5.6.0",
        "eslint-config-airbnb": "^17.1.0",
        "eslint-plugin-import": "^2.14.0",
        "eslint-plugin-jsx-a11y": "^6.1.1",
        "eslint-plugin-react": "^7.11.1"
      }
    }

My eslintrc.js

    module.exports = {
      parserOptions: {
      	ecmaVersion: 6
      },
      extends: 'airbnb',
      plugins: ['import'],
      // custom rules
      'rules': {
        'import/no-unresolved': 0,
        'import/extensions': 0,
        "import/no-extraneous-dependencies": ["error",
          {
            "devDependencies": false, 
            "optionalDependencies": false, 
            "peerDependencies": false,
          }
         ]
      }
    };

my index.js

    import moment from 'moment';
    
    moment();

moment is not present in package.json, but when I run eslint with my config, it's not showing errors:

./node_modules/eslint/bin/eslint.js -c ./eslintrc.js ./index.js

Result - nothing, but when I change eslintrc.js line "devDependencies": true,, then add to index.js import 'eslint'; and rerun CLI command, all works as expected, and error is showing.

What I'm doing wrong?

Guida contributor