Logo

dev-resources.site

for different kinds of informations.

Eslint rule to restrict imports

Published at
12/18/2022
Categories
eslint
linting
javascript
lodash
Author
kzuraw
Categories
4 categories in total
eslint
open
linting
open
javascript
open
lodash
open
Author
6 person written this
kzuraw
open
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

Featured ones: