@@ -18,89 +18,19 @@ module.exports = {
18
18
extraDescription : [ util . tslintRule ( "no-any" ) ] ,
19
19
category : "TypeScript" ,
20
20
url :
21
- "https://github.com/nzakas /eslint-plugin-typescript/blob/master/docs/rules/no-explicit-any.md" ,
21
+ "https://github.com/bradzacher /eslint-plugin-typescript/blob/master/docs/rules/no-explicit-any.md" ,
22
22
} ,
23
23
schema : [ ] ,
24
24
} ,
25
25
26
26
create ( context ) {
27
- //----------------------------------------------------------------------
28
- // Helpers
29
- //----------------------------------------------------------------------
30
-
31
- /**
32
- * Checks if the node has a type annotation of type any.
33
- * @param {ASTNode } node The node being validated.
34
- * @returns {void }
35
- * @private
36
- */
37
- function checkGenericNodeForAnnotation ( node ) {
38
- if ( node . type === "TSAnyKeyword" ) {
27
+ return {
28
+ TSAnyKeyword ( node ) {
39
29
context . report ( {
40
30
node,
41
31
message : "Unexpected any. Specify a different type." ,
42
32
} ) ;
43
- } else if ( node . type === "TSArrayType" ) {
44
- checkGenericNodeForAnnotation ( node . elementType ) ;
45
- } else if (
46
- node . type === "TSUnionType" ||
47
- node . type === "TSIntersectionType"
48
- ) {
49
- node . types . forEach ( type => {
50
- checkGenericNodeForAnnotation ( type ) ;
51
- } ) ;
52
- } else if ( node . type === "TSTypeReference" ) {
53
- if ( node . typeParameters ) {
54
- // handles generics
55
- node . typeParameters . params . forEach ( param => {
56
- checkGenericNodeForAnnotation ( param ) ;
57
- } ) ;
58
- } else if ( node . typeName ) {
59
- // handles non generics
60
- checkGenericNodeForAnnotation ( node . typeName ) ;
61
- }
62
- } else if ( node . type === "GenericTypeAnnotation" ) {
63
- if ( node . typeParameters ) {
64
- node . typeParameters . params . forEach ( param => {
65
- checkGenericNodeForAnnotation ( param ) ;
66
- } ) ;
67
- } else {
68
- checkGenericNodeForAnnotation ( node . id ) ;
69
- }
70
- }
71
- }
72
-
73
- /**
74
- * Checks if a function node used the any type
75
- * @param {ASTNode } node The node representing a function.
76
- * @returns {void }
77
- * @private
78
- */
79
- function checkFunctionReturnTypeForAnnotation ( node ) {
80
- if ( node . returnType ) {
81
- checkGenericNodeForAnnotation ( node . returnType . typeAnnotation ) ;
82
- }
83
- }
84
-
85
- //----------------------------------------------------------------------
86
- // Public
87
- //----------------------------------------------------------------------
88
- return {
89
- Identifier ( node ) {
90
- if ( node . typeAnnotation ) {
91
- checkGenericNodeForAnnotation (
92
- node . typeAnnotation . typeAnnotation
93
- ) ;
94
- }
95
- } ,
96
- TSTypeAnnotation ( node ) {
97
- if ( node . typeAnnotation ) {
98
- checkGenericNodeForAnnotation ( node . typeAnnotation ) ;
99
- }
100
33
} ,
101
- FunctionDeclaration : checkFunctionReturnTypeForAnnotation ,
102
- FunctionExpression : checkFunctionReturnTypeForAnnotation ,
103
- ArrowFunctionExpression : checkFunctionReturnTypeForAnnotation ,
104
34
} ;
105
35
} ,
106
36
} ;
0 commit comments