0

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

What need to do. If js file has import with 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 am I doing wrong?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
volos
  • 399
  • 5
  • 19
  • bug on github https://github.com/benmosher/eslint-plugin-import/issues/1177#issuecomment-428331605 – volos Oct 30 '18 at 08:36

0 Answers0