@@ -141,36 +141,35 @@ export default util.createRule<[Options], MessageIds>({
141141 } ,
142142 VariableDeclarator ( node ) : void {
143143 if (
144- options [ OptionKeys . VariableDeclaration ] &&
145- ! node . id . typeAnnotation
144+ ! options [ OptionKeys . VariableDeclaration ] ||
145+ node . id . typeAnnotation ||
146+ ( node . id . type === AST_NODE_TYPES . ArrayPattern &&
147+ ! options [ OptionKeys . ArrayDestructuring ] ) ||
148+ ( node . id . type === AST_NODE_TYPES . ObjectPattern &&
149+ ! options [ OptionKeys . ObjectDestructuring ] )
146150 ) {
147- // Are we inside a context that does not allow type annotations?
148- let typeAnnotationRequired = true ;
149-
150- let current : TSESTree . Node | undefined = node . parent ;
151- while ( current ) {
152- switch ( current . type ) {
153- case AST_NODE_TYPES . VariableDeclaration :
154- // Keep looking upwards
155- current = current . parent ;
156- break ;
157- case AST_NODE_TYPES . ForOfStatement :
158- case AST_NODE_TYPES . ForInStatement :
159- // Stop traversing and don't report an error
160- typeAnnotationRequired = false ;
161- current = undefined ;
162- break ;
163- default :
164- // Stop traversing
165- current = undefined ;
166- break ;
167- }
168- }
151+ return ;
152+ }
169153
170- if ( typeAnnotationRequired ) {
171- report ( node , getNodeName ( node . id ) ) ;
154+ let current : TSESTree . Node | undefined = node . parent ;
155+ while ( current ) {
156+ switch ( current . type ) {
157+ case AST_NODE_TYPES . VariableDeclaration :
158+ // Keep looking upwards
159+ current = current . parent ;
160+ break ;
161+ case AST_NODE_TYPES . ForOfStatement :
162+ case AST_NODE_TYPES . ForInStatement :
163+ // Stop traversing and don't report an error
164+ return ;
165+ default :
166+ // Stop traversing
167+ current = undefined ;
168+ break ;
172169 }
173170 }
171+
172+ report ( node , getNodeName ( node . id ) ) ;
174173 } ,
175174 } ;
176175 } ,
0 commit comments