You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: 'Enforce that public methods return well-defined types (no inline types)',
21
+
category: 'TypeScript',
22
+
recommended: false,
23
+
},
24
+
schema: [],
25
+
messages: {
26
+
inlineReturnType: 'Public method "{{methodName}}" should return a well-defined type, not an inline type. Consider defining an interface or type alias.',
27
+
},
28
+
},
29
+
30
+
create(context){
31
+
/**
32
+
* Check if a node represents an inline type that should be flagged
33
+
*/
34
+
functionisInlineType(typeNode){
35
+
if(!typeNode)returnfalse;
36
+
37
+
switch(typeNode.type){
38
+
// Object type literals: { foo: string, bar: number }
39
+
case'TSTypeLiteral':
40
+
returntrue;
41
+
42
+
// Union types with inline object types: string | { foo: bar }
43
+
case'TSUnionType':
44
+
returntypeNode.types.some(isInlineType);
45
+
46
+
// Intersection types with inline object types: Base & { foo: bar }
47
+
case'TSIntersectionType':
48
+
returntypeNode.types.some(isInlineType);
49
+
50
+
// Tuple types: [string, number]
51
+
case'TSTupleType':
52
+
returntrue;
53
+
54
+
// Mapped types: { [K in keyof T]: U }
55
+
case'TSMappedType':
56
+
returntrue;
57
+
58
+
// Conditional types: T extends U ? X : Y (inline)
59
+
case'TSConditionalType':
60
+
returntrue;
61
+
62
+
default:
63
+
returnfalse;
64
+
}
65
+
}
66
+
67
+
/**
68
+
* Check if a method is public (not private or protected)
69
+
*/
70
+
functionisPublicMethod(node){
71
+
// If no accessibility modifier is specified, it's public by default
72
+
if(!node.accessibility)returntrue;
73
+
returnnode.accessibility==='public';
74
+
}
75
+
76
+
/**
77
+
* Check if a class is exported
78
+
*/
79
+
functionisExportedClass(node){
80
+
// Check if the class declaration itself is exported
0 commit comments