parameters: (filename, line_number, line, file_state, error)
docstring: Checks if identifier names contain any underscores.
  
      As identifiers in libraries we are using have a bunch of
      underscores, we only warn about the declarations of identifiers
      and don't check use of identifiers.
  
      Args:
        filename: The name of the current file.
        line_number: The number of the line to check.
        line: The line of code to check.
        file_state: A _FileState instance which maintains information about
                    the state of things in the file.
        error: The function to call with any errors found.
docstring_summary: Checks if identifier names contain any underscores.
docstring_tokens: Checks if identifier names contain any underscores .
function: def check_identifier_name_in_declaration(filename, line_number, line, file_state, error):
      """Checks if identifier names contain any underscores.
  
      As identifiers in libraries we are using have a bunch of
      underscores, we only warn about the declarations of identifiers
      and don't check use of identifiers.
  
      Args:
        filename: The name of the current file.
        line_number: The number of the line to check.
        line: The line of code to check.
        file_state: A _FileState instance which maintains information about
                    the state of things in the file.
        error: The function to call with any errors found.
      """
      # We don't check a return statement.
      if match(r'\s*(return|delete)\b', line):
          return
  
      # Basically, a declaration is a type name followed by whitespaces
      # followed by an identifier. The type name can be complicated
      # due to type adjectives and templates. We remove them first to
      # simplify the process to find declarations of identifiers.
  
      # Convert "long long", "long double", and "long long int" to
      # simple types, but don't remove simple "long".
      line = sub(r'long (long )?(?=long|double|int)', '', line)
      # Convert unsigned/signed types to simple types, too.
      line = sub(r'(unsigned|signed) (?=char|short|int|long)', '', line)
      line = sub(r'\b(inline|using|static|const|volatile|auto|register|extern|typedef|restrict|struct|class|virtual)(?=\W)', '', line)
  
      # Remove "new" and "new (expr)" to simplify, too.
      line = sub(r'new\s*(\([^)]*\))?', '', line)
  
      # Remove all template parameters by removing matching < and >.
      # Loop until no templates are removed to remove nested templates.
      while True:
          line, number_of_replacements = subn(r'<([\w\s:]|::)+\s*[*&]*\s*>', '', line)
          if not number_of_replacements:
              break
  
      # Declarations of local variables can be in condition expressions
      # of control flow statements (e.g., "if (RenderObject* p = o->parent())").
      # We remove the keywords and the first parenthesis.
      #
      # Declarations in "while", "if", and "switch" are different from
      # other declarations in two aspects:
      #
      # - There can be only one declaration between the parentheses.
      #   (i.e., you cannot write "if (int i = 0, j = 1) {}")
      # - The variable must be initialized.
      #   (i.e., you cannot write "if (int i) {}")
      #
      # and we will need different treatments for them.
      line = sub(r'^\s*for\s*\(', '', line)
      line, control_statement = subn(r'^\s*(while|else if|if|switch)\s*\(', '', line)
  
      # Detect variable and functions.
      type_regexp = r'\w([\w]|\s*[*&]\s*|::)+'
      identifier_regexp = r'(?P<identifier>[\w:]+)'
      maybe_bitfield_regexp = r'(:\s*\d+\s*)?'
      character_after_identifier_regexp = r'(?P<character_after_identifier>[[;()=,])(?!=)'
      declaration_without_type_regexp = r'\s*' + identifier_regexp + r'\s*' + maybe_bitfield_regexp + character_after_identifier_regexp
      declaration_with_type_regexp = r'\s*' + type_regexp + r'\s' + declaration_without_type_regexp
      is_function_arguments = False
      number_of_identifiers = 0
      while True:
          # If we are seeing the first identifier or arguments of a
          # function, there should be a type name before an identifier.
          if not number_of_identifiers or is_function_arguments:
              declaration_regexp = declaration_with_type_regexp
          else:
              declaration_regexp = declaration_without_type_regexp
  
          matched = match(declaration_regexp, line)
          if not matched:
              return
          identifier = matched.group('identifier')
          character_after_identifier = matched.group('character_after_identifier')
  
          # If we removed a non-for-control statement, the character after
          # the identifier should be '='. With this rule, we can avoid
          # warning for cases like "if (val & INT_MAX) {".
          if control_statement and character_after_identifier != '=':
              return
  
          is_function_arguments = is_function_arguments or character_after_identifier == '('
  
          # Remove "m_" and "s_" to allow them.
          modified_identifier = sub(r'(^|(?<=::))[ms]_', '', identifier)
          if not file_state.is_objective_c() and modified_identifier.find('_') >= 0:
              # Various exceptions to the rule: JavaScript op codes functions, const_iterator.
              if (not (filename.find('JavaScriptCore') >= 0 and modified_identifier.find('op_') >= 0)
                  and not modified_identifier.startswith('tst_')
                  and not modified_identifier.startswith('webkit_dom_object_')
                  and not modified_identifier.startswith('NPN_')
                  and not modified_identifier.startswith('NPP_')
                  and not modified_identifier.startswith('NP_')
                  and not modified_identifier.startswith('qt_')
                  and not modified_identifier.startswith('cairo_')
                  and not modified_identifier.find('::qt_') >= 0
                  and not modified_identifier == "const_iterator"
                  and not modified_identifier == "vm_throw"):
                  error(line_number, 'readability/naming', 4, identifier + " is incorrectly named. Don't use underscores in your identifier names.")
  
          # Check for variables named 'l', these are too easy to confuse with '1' in some fonts
          if modified_identifier == 'l':
              error(line_number, 'readability/naming', 4, identifier + " is incorrectly named. Don't use the single letter 'l' as an identifier name.")
  
          # There can be only one declaration in non-for-control statements.
          if control_statement:
              return
          # We should continue checking if this is a function
          # declaration because we need to check its arguments.
          # Also, we need to check multiple declarations.
          if character_after_identifier != '(' and character_after_identifier != ',':
              return
  
          number_of_identifiers += 1
          line = line[matched.end():]
function_tokens: def check_identifier_name_in_declaration ( filename , line_number , line , file_state , error ) : # We don't check a return statement. if match ( r'\s*(return|delete)\b' , line ) : return # Basically, a declaration is a type name followed by whitespaces # followed by an identifier. The type name can be complicated # due to type adjectives and templates. We remove them first to # simplify the process to find declarations of identifiers. # Convert "long long", "long double", and "long long int" to # simple types, but don't remove simple "long". line = sub ( r'long (long )?(?=long|double|int)' , '' , line ) # Convert unsigned/signed types to simple types, too. line = sub ( r'(unsigned|signed) (?=char|short|int|long)' , '' , line ) line = sub ( r'\b(inline|using|static|const|volatile|auto|register|extern|typedef|restrict|struct|class|virtual)(?=\W)' , '' , line ) # Remove "new" and "new (expr)" to simplify, too. line = sub ( r'new\s*(\([^)]*\))?' , '' , line ) # Remove all template parameters by removing matching < and >. # Loop until no templates are removed to remove nested templates. while True : line , number_of_replacements = subn ( r'<([\w\s:]|::)+\s*[*&]*\s*>' , '' , line ) if not number_of_replacements : break # Declarations of local variables can be in condition expressions # of control flow statements (e.g., "if (RenderObject* p = o->parent())"). # We remove the keywords and the first parenthesis. # # Declarations in "while", "if", and "switch" are different from # other declarations in two aspects: # # - There can be only one declaration between the parentheses. #   (i.e., you cannot write "if (int i = 0, j = 1) {}") # - The variable must be initialized. #   (i.e., you cannot write "if (int i) {}") # # and we will need different treatments for them. line = sub ( r'^\s*for\s*\(' , '' , line ) line , control_statement = subn ( r'^\s*(while|else if|if|switch)\s*\(' , '' , line ) # Detect variable and functions. type_regexp = r'\w([\w]|\s*[*&]\s*|::)+' identifier_regexp = r'(?P<identifier>[\w:]+)' maybe_bitfield_regexp = r'(:\s*\d+\s*)?' character_after_identifier_regexp = r'(?P<character_after_identifier>[[;()=,])(?!=)' declaration_without_type_regexp = r'\s*' + identifier_regexp + r'\s*' + maybe_bitfield_regexp + character_after_identifier_regexp declaration_with_type_regexp = r'\s*' + type_regexp + r'\s' + declaration_without_type_regexp is_function_arguments = False number_of_identifiers = 0 while True : # If we are seeing the first identifier or arguments of a # function, there should be a type name before an identifier. if not number_of_identifiers or is_function_arguments : declaration_regexp = declaration_with_type_regexp else : declaration_regexp = declaration_without_type_regexp matched = match ( declaration_regexp , line ) if not matched : return identifier = matched . group ( 'identifier' ) character_after_identifier = matched . group ( 'character_after_identifier' ) # If we removed a non-for-control statement, the character after # the identifier should be '='. With this rule, we can avoid # warning for cases like "if (val & INT_MAX) {". if control_statement and character_after_identifier != '=' : return is_function_arguments = is_function_arguments or character_after_identifier == '(' # Remove "m_" and "s_" to allow them. modified_identifier = sub ( r'(^|(?<=::))[ms]_' , '' , identifier ) if not file_state . is_objective_c ( ) and modified_identifier . find ( '_' ) >= 0 : # Various exceptions to the rule: JavaScript op codes functions, const_iterator. if ( not ( filename . find ( 'JavaScriptCore' ) >= 0 and modified_identifier . find ( 'op_' ) >= 0 ) and not modified_identifier . startswith ( 'tst_' ) and not modified_identifier . startswith ( 'webkit_dom_object_' ) and not modified_identifier . startswith ( 'NPN_' ) and not modified_identifier . startswith ( 'NPP_' ) and not modified_identifier . startswith ( 'NP_' ) and not modified_identifier . startswith ( 'qt_' ) and not modified_identifier . startswith ( 'cairo_' ) and not modified_identifier . find ( '::qt_' ) >= 0 and not modified_identifier == "const_iterator" and not modified_identifier == "vm_throw" ) : error ( line_number , 'readability/naming' , 4 , identifier + " is incorrectly named. Don't use underscores in your identifier names." ) # Check for variables named 'l', these are too easy to confuse with '1' in some fonts if modified_identifier == 'l' : error ( line_number , 'readability/naming' , 4 , identifier + " is incorrectly named. Don't use the single letter 'l' as an identifier name." ) # There can be only one declaration in non-for-control statements. if control_statement : return # We should continue checking if this is a function # declaration because we need to check its arguments. # Also, we need to check multiple declarations. if character_after_identifier != '(' and character_after_identifier != ',' : return number_of_identifiers += 1 line = line [ matched . end ( ) : ]