u
This commit is contained in:
@@ -2,6 +2,67 @@ import js from '@eslint/js';
|
||||
import globals from 'globals';
|
||||
import reactHooks from 'eslint-plugin-react-hooks';
|
||||
|
||||
const banMuiTooltipRule = {
|
||||
meta: {
|
||||
type: 'problem',
|
||||
docs: {
|
||||
description: 'Ban MUI Tooltip component',
|
||||
},
|
||||
messages: {
|
||||
badDesign: '<Tooltip> is bad design',
|
||||
},
|
||||
},
|
||||
create(context) {
|
||||
const muiTooltipIdentifiers = new Set();
|
||||
|
||||
return {
|
||||
ImportDeclaration(node) {
|
||||
if (node.source.value === '@mui/material/Tooltip') {
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'badDesign',
|
||||
});
|
||||
for (const specifier of node.specifiers) {
|
||||
if (specifier.local?.name) {
|
||||
muiTooltipIdentifiers.add(specifier.local.name);
|
||||
}
|
||||
}
|
||||
} else if (node.source.value === '@mui/material') {
|
||||
for (const specifier of node.specifiers) {
|
||||
if (
|
||||
specifier.type === 'ImportSpecifier' &&
|
||||
specifier.imported?.name === 'Tooltip'
|
||||
) {
|
||||
context.report({
|
||||
node: specifier,
|
||||
messageId: 'badDesign',
|
||||
});
|
||||
if (specifier.local?.name) {
|
||||
muiTooltipIdentifiers.add(specifier.local.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
JSXOpeningElement(node) {
|
||||
let tagName = '';
|
||||
if (node.name.type === 'JSXIdentifier') {
|
||||
tagName = node.name.name;
|
||||
} else if (node.name.type === 'JSXMemberExpression') {
|
||||
tagName = node.name.property.name;
|
||||
}
|
||||
|
||||
if (muiTooltipIdentifiers.has(tagName) || tagName === 'Tooltip') {
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'badDesign',
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
export default [
|
||||
{
|
||||
ignores: [
|
||||
@@ -32,10 +93,16 @@ export default [
|
||||
},
|
||||
plugins: {
|
||||
'react-hooks': reactHooks,
|
||||
react: {
|
||||
rules: {
|
||||
'no-mui-tooltip': banMuiTooltipRule,
|
||||
},
|
||||
},
|
||||
},
|
||||
rules: {
|
||||
'react-hooks/rules-of-hooks': 'error',
|
||||
'react-hooks/exhaustive-deps': 'warn',
|
||||
'react/no-mui-tooltip': 'error',
|
||||
'no-unused-vars': [
|
||||
'warn',
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user