I’m working in a project that’s in Nextjs 14 with Material UI 5 components for styling. I want to know if there’s a ESLint custom rule to restrict the way of importing the components, probably with no-restricted-imports.
// This should trigger an error
import { Box } from "@material-ui/material";
// This should be allowed
import Box from "@material-ui/material/Button";
Is there a custom ESLint rule that would satisfy my needs instead that I can easily put into the rules
section? Plugins that are not deprecated are also welcome.
I already tried various configs with no-restricted-imports
but couldn’t hack it. Maybe someone with more experience on ESLint can help me.
2
Answers
Just made it work using some propper regex:
playground
As an alternative to the approach shown by @vzsoares, you can use the
paths
option of theno-restricted-imports
rule with a simple string value. That will do what you want by default.