private void checkForUnusedLocalVar ( Var v , Reference unusedAssignment ) { if ( ! v . isLocal ( ) ) { return ; } JSDocInfo jsDoc = NodeUtil . getBestJSDocInfo ( unusedAssignment . getNode ( ) ) ; if ( jsDoc != null && jsDoc . hasTypedefType ( ) ) { return ; } boolean inGoogScope = false ; Scope s = v . getScope ( ) ; if ( s . isFunctionBlockScope ( ) ) { Node function = s . getRootNode ( ) . getParent ( ) ; Node callee = function . getPrevious ( ) ; inGoogScope = callee != null && callee . matchesQualifiedName ( "goog.scope" ) ; } if ( inGoogScope ) { // No warning. return ; } if ( s . isModuleScope ( ) ) { Node statement = NodeUtil . getEnclosingStatement ( v . getNode ( ) ) ; if ( NodeUtil . isNameDeclaration ( statement ) ) { Node lhs = statement . getFirstChild ( ) ; Node rhs = lhs . getFirstChild ( ) ; if ( rhs != null && ( NodeUtil . isCallTo ( rhs , "goog.forwardDeclare" ) || NodeUtil . isCallTo ( rhs , "goog.requireType" ) || NodeUtil . isCallTo ( rhs , "goog.require" ) || rhs . isQualifiedName ( ) ) ) { // No warning. module imports will be caught by the unused-require check, and if the // right side is a qualified name then this is likely an alias used in type annotations. return ; } } } compiler . report ( JSError . make ( unusedAssignment . getNode ( ) , UNUSED_LOCAL_ASSIGNMENT , v . name ) ) ; }
that we can run it after goog . scope processing and get rid of the inGoogScope check .