@blumintinc/eslint-plugin-blumint 1.1.4 → 1.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js
CHANGED
|
@@ -56,19 +56,31 @@ module.exports = (0, createRule_1.createRule)({
|
|
|
56
56
|
// Check if type is a React component type
|
|
57
57
|
const isComponent = symbol.declarations?.some((decl) => {
|
|
58
58
|
const declaration = decl;
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
// Check for JSX element types
|
|
60
|
+
if (ts.isTypeAliasDeclaration(declaration)) {
|
|
61
|
+
const typeText = declaration.type.getText();
|
|
62
|
+
return typeText.includes('JSX.Element') || typeText.includes('ReactElement');
|
|
63
|
+
}
|
|
64
|
+
// Check for class/interface component patterns
|
|
65
|
+
if (ts.isClassDeclaration(declaration) || ts.isInterfaceDeclaration(declaration)) {
|
|
61
66
|
const name = declaration.name?.text ?? '';
|
|
62
|
-
return (
|
|
63
|
-
// Check for common React component patterns
|
|
64
|
-
name.includes('Component') ||
|
|
67
|
+
return (name.includes('Component') ||
|
|
65
68
|
name.includes('Element') ||
|
|
66
69
|
name.includes('FC') ||
|
|
67
70
|
name.includes('FunctionComponent'));
|
|
68
71
|
}
|
|
69
72
|
return false;
|
|
70
73
|
});
|
|
71
|
-
|
|
74
|
+
// Check if the type itself is a component or element type
|
|
75
|
+
const typeString = checker.typeToString(type);
|
|
76
|
+
const isComponentType = (typeString.includes('JSX.Element') ||
|
|
77
|
+
typeString.includes('ReactElement') ||
|
|
78
|
+
typeString.includes('Component') ||
|
|
79
|
+
typeString.includes('FC'));
|
|
80
|
+
return isComponent || isComponentType;
|
|
81
|
+
}
|
|
82
|
+
function isPascalCase(str) {
|
|
83
|
+
return /^[A-Z][a-zA-Z0-9]*$/.test(str);
|
|
72
84
|
}
|
|
73
85
|
function isFunctionType(node) {
|
|
74
86
|
const tsNode = parserServices.esTreeNodeToTSNodeMap.get(node);
|
|
@@ -85,6 +97,10 @@ module.exports = (0, createRule_1.createRule)({
|
|
|
85
97
|
if (propName?.match(/^on[A-Z]/)) {
|
|
86
98
|
return;
|
|
87
99
|
}
|
|
100
|
+
// Skip PascalCase props as they typically represent components or component-related props
|
|
101
|
+
if (propName && isPascalCase(propName)) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
88
104
|
// Check if the value is a function type and not a React component
|
|
89
105
|
if (isFunctionType(node.value.expression) &&
|
|
90
106
|
propName &&
|