Eslint-plugin-import: Allow import 'lodash/get', but disallow import 'lodash'

Created on 25 Apr 2017  路  2Comments  路  Source: benmosher/eslint-plugin-import

In our project, I would like to disallow to use import {get} from 'lodash';.
The reason behind this is that import {get} from 'lodash' will load all of lodash functions (even if unused).
But when we use import 'lodash/get', only the specific needed functions are required (which minimizes our built files with webpack a lot).

However, after a while, someone will start to use import {get} from 'lodash'.

So I'm searching for a way to disallow that.

A suggestion that I would have is to have a import blacklist, that would be a list of regexes, and we could for example write :

importBlackList: [/^lodash$/]

What do you think ?

Is there another way to achieve this ?

question

Most helpful comment

This can be done with the core rule no-restricted-imports: http://eslint.org/docs/rules/no-restricted-imports

[2, { "paths": ["lodash"] }]

All 2 comments

This can be done with the core rule no-restricted-imports: http://eslint.org/docs/rules/no-restricted-imports

[2, { "paths": ["lodash"] }]

what about local import ?

import some form `./thing`;
Was this page helpful?
0 / 5 - 0 ratings