300300 'build/include' ,
301301 'build/include_subdir' ,
302302 'build/include_alpha' ,
303+ 'build/include_inline' ,
303304 'build/include_order' ,
304305 'build/include_what_you_use' ,
305306 'build/namespaces_headers' ,
315316 'readability/constructors' ,
316317 'readability/fn_size' ,
317318 'readability/inheritance' ,
319+ 'readability/pointer_notation' ,
318320 'readability/multiline_comment' ,
319321 'readability/multiline_string' ,
320322 'readability/namespace' ,
321323 'readability/nolint' ,
322324 'readability/nul' ,
325+ 'readability/null_usage' ,
323326 'readability/strings' ,
324327 'readability/todo' ,
325328 'readability/utf8' ,
339342 'runtime/string' ,
340343 'runtime/threadsafe_fn' ,
341344 'runtime/vlog' ,
345+ 'runtime/v8_persistent' ,
342346 'whitespace/blank_line' ,
343347 'whitespace/braces' ,
344348 'whitespace/comma' ,
847851 'Missing space after ,' : r's/,\([^ ]\)/, \1/g' ,
848852}
849853
854+ _NULL_TOKEN_PATTERN = re .compile (r'\bNULL\b' )
855+
856+ _V8_PERSISTENT_PATTERN = re .compile (r'\bv8::Persistent\b' )
857+
858+ _RIGHT_LEANING_POINTER_PATTERN = re .compile (r'[^=|(,\s><);&?:}]'
859+ r'(?<!(sizeof|return))'
860+ r'\s\*[a-zA-Z_][0-9a-zA-Z_]*' )
861+
850862_regexp_compile_cache = {}
851863
852864# {str, set(int)}: a map from error categories to sets of linenumbers
@@ -1087,10 +1099,11 @@ class _IncludeState(object):
10871099 # needs to move backwards, CheckNextIncludeOrder will raise an error.
10881100 _INITIAL_SECTION = 0
10891101 _MY_H_SECTION = 1
1090- _C_SECTION = 2
1091- _CPP_SECTION = 3
1092- _OTHER_SYS_SECTION = 4
1093- _OTHER_H_SECTION = 5
1102+ _OTHER_H_SECTION = 2
1103+ _OTHER_SYS_SECTION = 3
1104+ _C_SECTION = 4
1105+ _CPP_SECTION = 5
1106+
10941107
10951108 _TYPE_NAMES = {
10961109 _C_SYS_HEADER : 'C system header' ,
@@ -2527,6 +2540,21 @@ def CheckForBadCharacters(filename, lines, error):
25272540 error (filename , linenum , 'readability/nul' , 5 , 'Line contains NUL byte.' )
25282541
25292542
2543+ def CheckInlineHeader (filename , include_state , error ):
2544+ """Logs an error if both a header and its inline variant are included."""
2545+
2546+ all_headers = dict (item for sublist in include_state .include_list
2547+ for item in sublist )
2548+ bad_headers = set ('%s.h' % name [:- 6 ] for name in all_headers .keys ()
2549+ if name .endswith ('-inl.h' ))
2550+ bad_headers &= set (all_headers .keys ())
2551+
2552+ for name in bad_headers :
2553+ err = '%s includes both %s and %s-inl.h' % (filename , name , name )
2554+ linenum = all_headers [name ]
2555+ error (filename , linenum , 'build/include_inline' , 5 , err )
2556+
2557+
25302558def CheckForNewlineAtEOF (filename , lines , error ):
25312559 """Logs an error if there is no newline char at the end of the file.
25322560
@@ -3550,7 +3578,7 @@ def CheckForFunctionLengths(filename, clean_lines, linenum,
35503578 """Reports for long function bodies.
35513579
35523580 For an overview why this is done, see:
3553- https://google-styleguide.googlecode.com/svn/trunk/ cppguide.xml #Write_Short_Functions
3581+ https://google.github.io/styleguide/ cppguide.html #Write_Short_Functions
35543582
35553583 Uses a simplistic algorithm assuming other style guidelines
35563584 (especially spacing) are followed.
@@ -4777,6 +4805,71 @@ def CheckAltTokens(filename, clean_lines, linenum, error):
47774805 'Use operator %s instead of %s' % (
47784806 _ALT_TOKEN_REPLACEMENT [match .group (1 )], match .group (1 )))
47794807
4808+ def CheckNullTokens (filename , clean_lines , linenum , error ):
4809+ """Check NULL usage.
4810+
4811+ Args:
4812+ filename: The name of the current file.
4813+ clean_lines: A CleansedLines instance containing the file.
4814+ linenum: The number of the line to check.
4815+ error: The function to call with any errors found.
4816+ """
4817+ line = clean_lines .elided [linenum ]
4818+
4819+ # Avoid preprocessor lines
4820+ if Match (r'^\s*#' , line ):
4821+ return
4822+
4823+ if line .find ('/*' ) >= 0 or line .find ('*/' ) >= 0 :
4824+ return
4825+
4826+ for match in _NULL_TOKEN_PATTERN .finditer (line ):
4827+ error (filename , linenum , 'readability/null_usage' , 2 ,
4828+ 'Use nullptr instead of NULL' )
4829+
4830+ def CheckV8PersistentTokens (filename , clean_lines , linenum , error ):
4831+ """Check v8::Persistent usage.
4832+
4833+ Args:
4834+ filename: The name of the current file.
4835+ clean_lines: A CleansedLines instance containing the file.
4836+ linenum: The number of the line to check.
4837+ error: The function to call with any errors found.
4838+ """
4839+ line = clean_lines .elided [linenum ]
4840+
4841+ # Avoid preprocessor lines
4842+ if Match (r'^\s*#' , line ):
4843+ return
4844+
4845+ if line .find ('/*' ) >= 0 or line .find ('*/' ) >= 0 :
4846+ return
4847+
4848+ for match in _V8_PERSISTENT_PATTERN .finditer (line ):
4849+ error (filename , linenum , 'runtime/v8_persistent' , 2 ,
4850+ 'Use v8::Global instead of v8::Persistent' )
4851+
4852+ def CheckLeftLeaningPointer (filename , clean_lines , linenum , error ):
4853+ """Check for left-leaning pointer placement.
4854+
4855+ Args:
4856+ filename: The name of the current file.
4857+ clean_lines: A CleansedLines instance containing the file.
4858+ linenum: The number of the line to check.
4859+ error: The function to call with any errors found.
4860+ """
4861+ line = clean_lines .elided [linenum ]
4862+
4863+ # Avoid preprocessor lines
4864+ if Match (r'^\s*#' , line ):
4865+ return
4866+
4867+ if '/*' in line or '*/' in line :
4868+ return
4869+
4870+ for match in _RIGHT_LEANING_POINTER_PATTERN .finditer (line ):
4871+ error (filename , linenum , 'readability/pointer_notation' , 2 ,
4872+ 'Use left leaning pointer instead of right leaning' )
47804873
47814874def GetLineWidth (line ):
47824875 """Determines the width of the line in column positions.
@@ -4931,6 +5024,9 @@ def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state,
49315024 CheckSpacingForFunctionCall (filename , clean_lines , linenum , error )
49325025 CheckCheck (filename , clean_lines , linenum , error )
49335026 CheckAltTokens (filename , clean_lines , linenum , error )
5027+ CheckNullTokens (filename , clean_lines , linenum , error )
5028+ CheckV8PersistentTokens (filename , clean_lines , linenum , error )
5029+ CheckLeftLeaningPointer (filename , clean_lines , linenum , error )
49345030 classinfo = nesting_state .InnermostClass ()
49355031 if classinfo :
49365032 CheckSectionSpacing (filename , clean_lines , classinfo , linenum , error )
@@ -5118,11 +5214,10 @@ def CheckIncludeLine(filename, clean_lines, linenum, include_state, error):
51185214 include_state .include_list [- 1 ].append ((include , linenum ))
51195215
51205216 # We want to ensure that headers appear in the right order:
5121- # 1) for foo.cc, foo.h (preferred location)
5122- # 2) c system files
5123- # 3) cpp system files
5124- # 4) for foo.cc, foo.h (deprecated location)
5125- # 5) other google headers
5217+ # 1) for foo.cc, foo.h
5218+ # 2) other project headers
5219+ # 3) c system files
5220+ # 4) cpp system files
51265221 #
51275222 # We classify each include statement as one of those 5 types
51285223 # using a number of techniques. The include_state object keeps
@@ -5385,7 +5480,7 @@ def CheckLanguage(filename, clean_lines, linenum, file_extension,
53855480 and line [- 1 ] != '\\ ' ):
53865481 error (filename , linenum , 'build/namespaces_headers' , 4 ,
53875482 'Do not use unnamed namespaces in header files. See '
5388- 'https://google-styleguide.googlecode.com/svn/trunk/ cppguide.xml #Namespaces'
5483+ 'https://google.github.io/styleguide/ cppguide.html #Namespaces'
53895484 ' for more information.' )
53905485
53915486
@@ -6507,6 +6602,8 @@ def ProcessFileData(filename, file_extension, lines, error,
65076602
65086603 CheckForNewlineAtEOF (filename , lines , error )
65096604
6605+ CheckInlineHeader (filename , include_state , error )
6606+
65106607def ProcessConfigOverrides (filename ):
65116608 """ Loads the configuration files and processes the config overrides.
65126609
@@ -6525,7 +6622,7 @@ def ProcessConfigOverrides(filename):
65256622 if not base_name :
65266623 break # Reached the root directory.
65276624
6528- cfg_file = os .path .join (abs_path , "CPPLINT.cfg " )
6625+ cfg_file = os .path .join (abs_path , ".cpplint " )
65296626 abs_filename = abs_path
65306627 if not os .path .isfile (cfg_file ):
65316628 continue
0 commit comments