DEV Community

Krzysztof Żuraw
Krzysztof Żuraw

Posted on • Originally published at krzysztofzuraw.com on

Eslint rule to restrict imports

I recently learned that there is a way to restrict imports of certain libraries in Eslint. This is useful for example when you want to restrict the use of a certain library. For example, you might want to restrict the use of lodash.js in your codebase. You can do this by adding the following rule to your Eslint config:

rules: {
  'no-restricted-imports': [
    'error',
    {
      paths: [
        {
          name: 'lodash',
          message: 'Please use the native implementation instead.',
        },
      ],
    },
  ],
},
Enter fullscreen mode Exit fullscreen mode

Top comments (0)