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
* ESLint rule to enforce that public methods in exported classes return well-defined types.
10
+
* This rule ensures that no inline type (object literal, anonymous type, etc.) is returned
11
+
* from any public method.
12
+
*/
13
+
14
+
module.exports={
15
+
meta: {
16
+
type: 'problem',
17
+
docs: {
18
+
description: 'Enforce that public methods return well-defined types (no inline types)',
19
+
category: 'TypeScript',
20
+
recommended: false,
21
+
},
22
+
schema: [],
23
+
messages: {
24
+
inlineReturnType: 'Public method "{{methodName}}" should return a well-defined type, not an inline type. Consider defining an interface or type alias.',
25
+
},
26
+
},
27
+
28
+
create(context){
29
+
/**
30
+
* Check if a node represents an inline type that should be flagged
31
+
*/
32
+
functionisInlineType(typeNode){
33
+
if(!typeNode)returnfalse;
34
+
35
+
switch(typeNode.type){
36
+
// Object type literals: { foo: string, bar: number }
37
+
case'TSTypeLiteral':
38
+
returntrue;
39
+
40
+
// Union types with inline object types: string | { foo: bar }
41
+
case'TSUnionType':
42
+
returntypeNode.types.some(isInlineType);
43
+
44
+
// Intersection types with inline object types: Base & { foo: bar }
45
+
case'TSIntersectionType':
46
+
returntypeNode.types.some(isInlineType);
47
+
48
+
// Tuple types: [string, number]
49
+
case'TSTupleType':
50
+
returntrue;
51
+
52
+
// Mapped types: { [K in keyof T]: U }
53
+
case'TSMappedType':
54
+
returntrue;
55
+
56
+
// Conditional types: T extends U ? X : Y (inline)
57
+
case'TSConditionalType':
58
+
returntrue;
59
+
60
+
// Type references with inline type arguments: Promise<{x: string}>, Array<{y: number}>
61
+
case'TSTypeReference':
62
+
// Check if any type arguments contain inline types
0 commit comments