const forbiddenPackages = [ /^@(?:radix-ui|floating-ui|lobehub|headlessui|mui|material-ui|chakra-ui)\//, /^@douyinfe\/semi-/, /^(?:leva|antd-style|react-layout-kit)(?:[/?#]|$)/, ]; function isForbiddenUiDependency(specifier) { return ( typeof specifier === 'string' && forbiddenPackages.some((pattern) => pattern.test(specifier)) ); } const rule = { meta: { schema: [], messages: { forbidden: 'Use Ant Design or the audited local brand assets instead of {{specifier}}.', }, }, create(context) { const inspect = (node) => { const specifier = node?.type === 'Literal' ? node.value : node?.type === 'TemplateLiteral' && node.expressions.length === 0 ? node.quasis[0].value.cooked : null; if (isForbiddenUiDependency(specifier)) { context.report({ node, messageId: 'forbidden', data: { specifier } }); } }; return { ImportDeclaration: (node) => inspect(node.source), ExportNamedDeclaration: (node) => inspect(node.source), ExportAllDeclaration: (node) => inspect(node.source), ImportExpression: (node) => inspect(node.source), CallExpression: (node) => { const { callee } = node; const isRequire = callee.type === 'Identifier' && callee.name === 'require'; const isRequireResolve = callee.type === 'MemberExpression' && !callee.computed && callee.object.type === 'Identifier' && callee.object.name === 'require' && callee.property.name === 'resolve'; if (isRequire || isRequireResolve) inspect(node.arguments[0]); }, }; }, }; const uiDependencyConfig = { files: ['**/*.{js,jsx,cjs,mjs}'], languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, plugins: { 'ui-dependencies': { rules: { 'no-legacy-ui': rule } } }, rules: { 'ui-dependencies/no-legacy-ui': 'error' }, }; module.exports = { isForbiddenUiDependency, uiDependencyConfig };