Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

141
Views
Custom eslint no-restricted-imports for lodash vs. lodash/fp

I'm trying to define a list of certain lodash methods that should be imported from fp. In addition, I'm trying to disallow importing from lodash's top-level. Should disallow destructured imports from lodash.

Here's the goal:

import _ from 'lodash'; // should show message "Import [module] from lodash/[module] instead"
import { isEqual } from 'lodash'; // should show message "Import [module] from lodash/[module] instead"
import isEmpty from 'lodash/isEqual'; // should pass
import set from 'lodash/set'; // should show message "Import [module] from lodash/fp/[module] instead"

eslintrc.json

"no-restricted-imports": [
   "error",
   {
      "patterns": [
         {
            "group": ["lodash/set"],
            "message": "Import [module] from lodash/fp/[module] instead"
         },
         {
            "group": ["lodash", "!lodash/*"],
            "message": "Import [module] from lodash/[module] instead"
         }
      ]
   }
],

These are the flags/patterns I've been working with. I've tried toggling the negative matchers on and off, and switched the order of the group array strings, and the groups themselves. Unable to get the desired eslint errors.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

How about this?

"no-restricted-imports": [
   "error",
   {
      "paths": [
         {
            "name": "lodash",
            "message": "Import [module] from lodash/[module] instead"
         }
      ],
      "patterns": [
         {
            "group": ["lodash/set"],
            "message": "Import [module] from lodash/fp/[module] instead"
         }
      ]
   }
],
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!