import-js/eslint-plugin-import

no-extraneous-dependencies not checking dependencies

Open

#1,177 opened on Oct 1, 2018

 (12 comments) (0 reactions) (0 assignees)JavaScript (1,549 forks)batch import
bughelp wanted

Repository metrics

Stars
 (5,940 stars)
PR merge metrics
 (Avg merge 138d 22h) (3 merged PRs in 30d)

Description

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?

Contributor guide