def _CheckUnusedLocalVariables(self, token, state):
    # We don't use state.InFunction because that disregards scope functions.
    in_function = state.FunctionDepth() > 0
    if token.type == Type.SIMPLE_LVALUE or token.type == Type.IDENTIFIER:
      if in_function:
        identifier = token.string
        # Check whether the previous token was var.
        previous_code_token = tokenutil.CustomSearch(
            token,
            lambda t: t.type not in Type.NON_CODE_TYPES,
            reverse=True)
        if previous_code_token and previous_code_token.IsKeyword('var'):
          # Add local variable declaration to the top of the unused locals
          # stack.
          self._unused_local_variables_by_scope[-1][identifier] = token
        elif token.type == Type.IDENTIFIER:
          # This covers most cases where the variable is used as an identifier.
          self._MarkLocalVariableUsed(token.string)
        elif token.type == Type.SIMPLE_LVALUE and '.' in identifier:
          # This covers cases where a value is assigned to a property of the
          # variable.
          self._MarkLocalVariableUsed(token.string)
    elif token.type == Type.START_BLOCK:
      if in_function and state.IsFunctionOpen():
        # Push a new map onto the stack
        self._unused_local_variables_by_scope.append({})
    elif token.type == Type.END_BLOCK:
      if state.IsFunctionClose():
        # Pop the stack and report any remaining locals as unused.
        unused_local_variables = self._unused_local_variables_by_scope.pop()
        for unused_token in unused_local_variables.values():
          self._HandleError(
              errors.UNUSED_LOCAL_VARIABLE,
              'Unused local variable: %s.' % unused_token.string,
              unused_token)
    elif token.type == Type.DOC_FLAG:
      # Flags that use aliased symbols should be counted.
      flag = token.attached_object
      js_type = flag and flag.jstype
      if flag and flag.flag_type in state.GetDocFlag().HAS_TYPE and js_type:
        self._MarkAliasUsed(js_type)
Checks for unused local variables in function blocks.
dataset/ETHPy150Open google/closure-linter/closure_linter/javascriptlintrules.py/JavaScriptLintRules._CheckUnusedLocalVariables