Created
April 2, 2025 15:47
-
-
Save Illyism/52adc3a6e4d5a6cd830450518191206f to your computer and use it in GitHub Desktop.
Prevent <Link> imports from lucide-react
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const enforceCorrectLinkImports = { | |
meta: { | |
type: 'suggestion', | |
fixable: 'code', | |
messages: { | |
incorrectLinkImport: 'Use next/link instead.', | |
}, | |
}, | |
create(context) { | |
return { | |
ImportDeclaration(node) { | |
if (node.source.value !== 'lucide-react') return | |
const linkImport = node.specifiers.find(s => | |
s.type === 'ImportSpecifier' && | |
s.imported.name === 'Link' && | |
s.local.name === 'Link' | |
) | |
if (linkImport) { | |
context.report({ | |
node, | |
messageId: 'incorrectLinkImport', | |
fix: fixer => fixer.replaceText(node, `import Link from 'next/link'`) | |
}) | |
} | |
} | |
} | |
} | |
} | |
export const linkRules = { | |
rules: { 'enforce-correct-link-imports': enforceCorrectLinkImports } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment