parameters: (self, token, state)
return_statement: return indentation_errors
docstring: Checks a token for indentation errors.
  
      Args:
        token: The current token under consideration
        state: Additional information about the current tree state
  
      Returns:
        An error array [error code, error string, error token] if the token is
        improperly indented, or None if indentation is correct.
docstring_summary: Checks a token for indentation errors.
docstring_tokens: Checks a token for indentation errors .
function: def CheckToken(self, token, state):
      """Checks a token for indentation errors.
  
      Args:
        token: The current token under consideration
        state: Additional information about the current tree state
  
      Returns:
        An error array [error code, error string, error token] if the token is
        improperly indented, or None if indentation is correct.
      """
  
      token_type = token.type
      indentation_errors = []
      stack = self._stack
      is_first = self._IsFirstNonWhitespaceTokenInLine(token)
  
      # Add tokens that could decrease indentation before checking.
      if token_type == Type.END_PAREN:
        self._PopTo(Type.START_PAREN)
  
      elif token_type == Type.END_PARAMETERS:
        self._PopTo(Type.START_PARAMETERS)
  
      elif token_type == Type.END_BRACKET:
        self._PopTo(Type.START_BRACKET)
  
      elif token_type == Type.END_BLOCK:
        self._PopTo(Type.START_BLOCK)
  
      elif token_type == Type.KEYWORD and token.string in ('case', 'default'):
        self._Add(self._PopTo(Type.START_BLOCK))
  
      elif is_first and token.string == '.':
        # This token should have been on the previous line, so treat it as if it
        # was there.
        info = TokenInfo(token)
        info.line_number = token.line_number - 1
        self._Add(info)
  
      elif token_type == Type.SEMICOLON:
        self._PopTransient()
  
      not_binary_operator = (token_type != Type.OPERATOR or
                             token.metadata.IsUnaryOperator())
      not_dot = token.string != '.'
      if is_first and not_binary_operator and not_dot and token.type not in (
          Type.COMMENT, Type.DOC_PREFIX, Type.STRING_TEXT):
        if flags.FLAGS.debug_indentation:
          print 'Line #%d: stack %r' % (token.line_number, stack)
  
        # Ignore lines that start in JsDoc since we don't check them properly yet.
        # TODO(robbyw): Support checking JsDoc indentation.
        # Ignore lines that start as multi-line strings since indentation is N/A.
        # Ignore lines that start with operators since we report that already.
        # Ignore lines with tabs since we report that already.
        expected = self._GetAllowableIndentations()
        actual = self._GetActualIndentation(token)
  
        # Special case comments describing else, case, and default.  Allow them
        # to outdent to the parent block.
        if token_type in Type.COMMENT_TYPES:
          next_code = tokenutil.SearchExcept(token, Type.NON_CODE_TYPES)
          if next_code and next_code.type == Type.END_BLOCK:
            next_code = tokenutil.SearchExcept(next_code, Type.NON_CODE_TYPES)
          if next_code and next_code.string in ('else', 'case', 'default'):
            # TODO(robbyw): This almost certainly introduces false negatives.
            expected |= self._AddToEach(expected, -2)
  
        if actual >= 0 and actual not in expected:
          expected = sorted(expected)
          indentation_errors.append([
              errors.WRONG_INDENTATION,
              'Wrong indentation: expected any of {%s} but got %d' % (
                  ', '.join(
                      ['%d' % x for x in expected]), actual),
              token,
              Position(actual, expected[0])])
          self._start_index_offset[token.line_number] = expected[0] - actual
  
      # Add tokens that could increase indentation.
      if token_type == Type.START_BRACKET:
        self._Add(TokenInfo(token=token,
            is_block=token.metadata.context.type == Context.ARRAY_LITERAL))
  
      elif token_type == Type.START_BLOCK or token.metadata.is_implied_block:
        self._Add(TokenInfo(token=token, is_block=True))
  
      elif token_type in (Type.START_PAREN,  Type.START_PARAMETERS):
        self._Add(TokenInfo(token=token, is_block=False))
  
      elif token_type == Type.KEYWORD and token.string == 'return':
        self._Add(TokenInfo(token))
  
      elif not token.IsLastInLine() and (
          token.IsAssignment() or token.IsOperator('?')):
        self._Add(TokenInfo(token=token))
  
      # Handle implied block closes.
      if token.metadata.is_implied_block_close:
        self._PopToImpliedBlock()
  
      # Add some tokens only if they appear at the end of the line.
      is_last = self._IsLastCodeInLine(token)
      if is_last:
        if token_type == Type.OPERATOR:
          if token.string == ':':
            if (stack and stack[-1].token.string == '?'):
              # When a ternary : is on a different line than its '?', it doesn't
              # add indentation.
              if (token.line_number == stack[-1].token.line_number):
                self._Add(TokenInfo(token))
            elif token.metadata.context.type == Context.CASE_BLOCK:
              # Pop transient tokens from say, line continuations, e.g.,
              # case x.
              #     y:
              # Want to pop the transient 4 space continuation indent.
              self._PopTransient()
              # Starting the body of the case statement, which is a type of
              # block.
              self._Add(TokenInfo(token=token, is_block=True))
            elif token.metadata.context.type == Context.LITERAL_ELEMENT:
              # When in an object literal, acts as operator indicating line
              # continuations.
              self._Add(TokenInfo(token))
              pass
            else:
              # ':' might also be a statement label, no effect on indentation in
              # this case.
              pass
  
          elif token.string != ',':
            self._Add(TokenInfo(token))
          else:
            # The token is a comma.
            if token.metadata.context.type == Context.VAR:
              self._Add(TokenInfo(token))
            elif token.metadata.context.type != Context.PARAMETERS:
              self._PopTransient()
  
        elif (token.string.endswith('.')
              and token_type in (Type.IDENTIFIER, Type.NORMAL)):
          self._Add(TokenInfo(token))
        elif token_type == Type.PARAMETERS and token.string.endswith(','):
          # Parameter lists.
          self._Add(TokenInfo(token))
        elif token.metadata.is_implied_semicolon:
          self._PopTransient()
      elif token.IsAssignment():
        self._Add(TokenInfo(token))
  
      return indentation_errors
function_tokens: def CheckToken ( self , token , state ) : token_type = token . type indentation_errors = [ ] stack = self . _stack is_first = self . _IsFirstNonWhitespaceTokenInLine ( token ) # Add tokens that could decrease indentation before checking. if token_type == Type . END_PAREN : self . _PopTo ( Type . START_PAREN ) elif token_type == Type . END_PARAMETERS : self . _PopTo ( Type . START_PARAMETERS ) elif token_type == Type . END_BRACKET : self . _PopTo ( Type . START_BRACKET ) elif token_type == Type . END_BLOCK : self . _PopTo ( Type . START_BLOCK ) elif token_type == Type . KEYWORD and token . string in ( 'case' , 'default' ) : self . _Add ( self . _PopTo ( Type . START_BLOCK ) ) elif is_first and token . string == '.' : # This token should have been on the previous line, so treat it as if it # was there. info = TokenInfo ( token ) info . line_number = token . line_number - 1 self . _Add ( info ) elif token_type == Type . SEMICOLON : self . _PopTransient ( ) not_binary_operator = ( token_type != Type . OPERATOR or token . metadata . IsUnaryOperator ( ) ) not_dot = token . string != '.' if is_first and not_binary_operator and not_dot and token . type not in ( Type . COMMENT , Type . DOC_PREFIX , Type . STRING_TEXT ) : if flags . FLAGS . debug_indentation : print 'Line #%d: stack %r' % ( token . line_number , stack ) # Ignore lines that start in JsDoc since we don't check them properly yet. # TODO(robbyw): Support checking JsDoc indentation. # Ignore lines that start as multi-line strings since indentation is N/A. # Ignore lines that start with operators since we report that already. # Ignore lines with tabs since we report that already. expected = self . _GetAllowableIndentations ( ) actual = self . _GetActualIndentation ( token ) # Special case comments describing else, case, and default.  Allow them # to outdent to the parent block. if token_type in Type . COMMENT_TYPES : next_code = tokenutil . SearchExcept ( token , Type . NON_CODE_TYPES ) if next_code and next_code . type == Type . END_BLOCK : next_code = tokenutil . SearchExcept ( next_code , Type . NON_CODE_TYPES ) if next_code and next_code . string in ( 'else' , 'case' , 'default' ) : # TODO(robbyw): This almost certainly introduces false negatives. expected |= self . _AddToEach ( expected , - 2 ) if actual >= 0 and actual not in expected : expected = sorted ( expected ) indentation_errors . append ( [ errors . WRONG_INDENTATION , 'Wrong indentation: expected any of {%s} but got %d' % ( ', ' . join ( [ '%d' % x for x in expected ] ) , actual ) , token , Position ( actual , expected [ 0 ] ) ] ) self . _start_index_offset [ token . line_number ] = expected [ 0 ] - actual # Add tokens that could increase indentation. if token_type == Type . START_BRACKET : self . _Add ( TokenInfo ( token = token , is_block = token . metadata . context . type == Context . ARRAY_LITERAL ) ) elif token_type == Type . START_BLOCK or token . metadata . is_implied_block : self . _Add ( TokenInfo ( token = token , is_block = True ) ) elif token_type in ( Type . START_PAREN , Type . START_PARAMETERS ) : self . _Add ( TokenInfo ( token = token , is_block = False ) ) elif token_type == Type . KEYWORD and token . string == 'return' : self . _Add ( TokenInfo ( token ) ) elif not token . IsLastInLine ( ) and ( token . IsAssignment ( ) or token . IsOperator ( '?' ) ) : self . _Add ( TokenInfo ( token = token ) ) # Handle implied block closes. if token . metadata . is_implied_block_close : self . _PopToImpliedBlock ( ) # Add some tokens only if they appear at the end of the line. is_last = self . _IsLastCodeInLine ( token ) if is_last : if token_type == Type . OPERATOR : if token . string == ':' : if ( stack and stack [ - 1 ] . token . string == '?' ) : # When a ternary : is on a different line than its '?', it doesn't # add indentation. if ( token . line_number == stack [ - 1 ] . token . line_number ) : self . _Add ( TokenInfo ( token ) ) elif token . metadata . context . type == Context . CASE_BLOCK : # Pop transient tokens from say, line continuations, e.g., # case x. #     y: # Want to pop the transient 4 space continuation indent. self . _PopTransient ( ) # Starting the body of the case statement, which is a type of # block. self . _Add ( TokenInfo ( token = token , is_block = True ) ) elif token . metadata . context . type == Context . LITERAL_ELEMENT : # When in an object literal, acts as operator indicating line # continuations. self . _Add ( TokenInfo ( token ) ) pass else : # ':' might also be a statement label, no effect on indentation in # this case. pass elif token . string != ',' : self . _Add ( TokenInfo ( token ) ) else : # The token is a comma. if token . metadata . context . type == Context . VAR : self . _Add ( TokenInfo ( token ) ) elif token . metadata . context . type != Context . PARAMETERS : self . _PopTransient ( ) elif ( token . string . endswith ( '.' ) and token_type in ( Type . IDENTIFIER , Type . NORMAL ) ) : self . _Add ( TokenInfo ( token ) ) elif token_type == Type . PARAMETERS and token . string . endswith ( ',' ) : # Parameter lists. self . _Add ( TokenInfo ( token ) ) elif token . metadata . is_implied_semicolon : self . _PopTransient ( ) elif token . IsAssignment ( ) : self . _Add ( TokenInfo ( token ) ) return indentation_errors