5959# if empty, use defaults
6060_valid_extensions = set ([])
6161
62- __VERSION__ = '1.5.4 '
62+ __VERSION__ = '1.5.5 '
6363
6464try :
6565 xrange # Python 2
127127 error messages whose category names pass the filters will be printed.
128128 (Category names are printed with the message and look like
129129 "[whitespace/indent]".) Filters are evaluated left to right.
130- "-FOO" and "FOO" means "do not print categories that start with FOO".
130+ "-FOO" means "do not print categories that start with FOO".
131131 "+FOO" means "do print categories that start with FOO".
132132
133133 Examples: --filter=-whitespace,+whitespace/braces
134- --filter=whitespace,runtime/printf,+runtime/printf_format
134+ --filter=- whitespace,- runtime/printf,+runtime/printf_format
135135 --filter=-,+build/include_what_you_use
136136
137137 To see a list of all the categories used in cpplint, pass no arg:
295295 'build/include' ,
296296 'build/include_subdir' ,
297297 'build/include_alpha' ,
298- 'build/include_inline' ,
299298 'build/include_order' ,
300299 'build/include_what_you_use' ,
301300 'build/namespaces_headers' ,
311310 'readability/constructors' ,
312311 'readability/fn_size' ,
313312 'readability/inheritance' ,
314- 'readability/pointer_notation' ,
315313 'readability/multiline_comment' ,
316314 'readability/multiline_string' ,
317315 'readability/namespace' ,
318316 'readability/nolint' ,
319317 'readability/nul' ,
320- 'readability/null_usage' ,
321318 'readability/strings' ,
322319 'readability/todo' ,
323320 'readability/utf8' ,
337334 'runtime/string' ,
338335 'runtime/threadsafe_fn' ,
339336 'runtime/vlog' ,
340- 'runtime/v8_persistent' ,
341337 'whitespace/blank_line' ,
342338 'whitespace/braces' ,
343339 'whitespace/comma' ,
846842 'Missing space after ,' : r's/,\([^ ]\)/, \1/g' ,
847843}
848844
849- _NULL_TOKEN_PATTERN = re .compile (r'\bNULL\b' )
850-
851- _V8_PERSISTENT_PATTERN = re .compile (r'\bv8::Persistent\b' )
852-
853- _RIGHT_LEANING_POINTER_PATTERN = re .compile (r'[^=|(,\s><);&?:}]'
854- r'(?<!(sizeof|return))'
855- r'\s\*[a-zA-Z_][0-9a-zA-Z_]*' )
856-
857845_regexp_compile_cache = {}
858846
859847# {str, set(int)}: a map from error categories to sets of linenumbers
@@ -1094,11 +1082,10 @@ class _IncludeState(object):
10941082 # needs to move backwards, CheckNextIncludeOrder will raise an error.
10951083 _INITIAL_SECTION = 0
10961084 _MY_H_SECTION = 1
1097- _OTHER_H_SECTION = 2
1098- _OTHER_SYS_SECTION = 3
1099- _C_SECTION = 4
1100- _CPP_SECTION = 5
1101-
1085+ _C_SECTION = 2
1086+ _CPP_SECTION = 3
1087+ _OTHER_SYS_SECTION = 4
1088+ _OTHER_H_SECTION = 5
11021089
11031090 _TYPE_NAMES = {
11041091 _C_SYS_HEADER : 'C system header' ,
@@ -2350,7 +2337,8 @@ def StripListPrefix(lst, prefix):
23502337
23512338 # --root=.. , will prepend the outer directory to the header guard
23522339 full_path = fileinfo .FullName ()
2353- root_abspath = os .path .abspath (_root )
2340+ # adapt slashes for windows
2341+ root_abspath = os .path .abspath (_root ).replace ('\\ ' , '/' )
23542342
23552343 maybe_path = StripListPrefix (PathSplitToList (full_path ),
23562344 PathSplitToList (root_abspath ))
@@ -2533,21 +2521,6 @@ def CheckForBadCharacters(filename, lines, error):
25332521 error (filename , linenum , 'readability/nul' , 5 , 'Line contains NUL byte.' )
25342522
25352523
2536- def CheckInlineHeader (filename , include_state , error ):
2537- """Logs an error if both a header and its inline variant are included."""
2538-
2539- all_headers = dict (item for sublist in include_state .include_list
2540- for item in sublist )
2541- bad_headers = set ('%s.h' % name [:- 6 ] for name in all_headers .keys ()
2542- if name .endswith ('-inl.h' ))
2543- bad_headers &= set (all_headers .keys ())
2544-
2545- for name in bad_headers :
2546- err = '%s includes both %s and %s-inl.h' % (filename , name , name )
2547- linenum = all_headers [name ]
2548- error (filename , linenum , 'build/include_inline' , 5 , err )
2549-
2550-
25512524def CheckForNewlineAtEOF (filename , lines , error ):
25522525 """Logs an error if there is no newline char at the end of the file.
25532526
@@ -3499,7 +3472,7 @@ def CheckSpacingForFunctionCall(filename, clean_lines, linenum, error):
34993472 # Note that we assume the contents of [] to be short enough that
35003473 # they'll never need to wrap.
35013474 if ( # Ignore control structures.
3502- not Search (r'\b(if|for|while|switch|return|new|delete|catch|sizeof)\b' ,
3475+ not Search (r'\b(if|elif| for|while|switch|return|new|delete|catch|sizeof)\b' ,
35033476 fncall ) and
35043477 # Ignore pointers/references to functions.
35053478 not Search (r' \([^)]+\)\([^)]*(\)|,$)' , fncall ) and
@@ -3571,7 +3544,7 @@ def CheckForFunctionLengths(filename, clean_lines, linenum,
35713544 """Reports for long function bodies.
35723545
35733546 For an overview why this is done, see:
3574- https://google.github.io/styleguide/ cppguide.html #Write_Short_Functions
3547+ https://google-styleguide.googlecode.com/svn/trunk/ cppguide.xml #Write_Short_Functions
35753548
35763549 Uses a simplistic algorithm assuming other style guidelines
35773550 (especially spacing) are followed.
@@ -4798,71 +4771,6 @@ def CheckAltTokens(filename, clean_lines, linenum, error):
47984771 'Use operator %s instead of %s' % (
47994772 _ALT_TOKEN_REPLACEMENT [match .group (1 )], match .group (1 )))
48004773
4801- def CheckNullTokens (filename , clean_lines , linenum , error ):
4802- """Check NULL usage.
4803-
4804- Args:
4805- filename: The name of the current file.
4806- clean_lines: A CleansedLines instance containing the file.
4807- linenum: The number of the line to check.
4808- error: The function to call with any errors found.
4809- """
4810- line = clean_lines .elided [linenum ]
4811-
4812- # Avoid preprocessor lines
4813- if Match (r'^\s*#' , line ):
4814- return
4815-
4816- if line .find ('/*' ) >= 0 or line .find ('*/' ) >= 0 :
4817- return
4818-
4819- for match in _NULL_TOKEN_PATTERN .finditer (line ):
4820- error (filename , linenum , 'readability/null_usage' , 2 ,
4821- 'Use nullptr instead of NULL' )
4822-
4823- def CheckV8PersistentTokens (filename , clean_lines , linenum , error ):
4824- """Check v8::Persistent usage.
4825-
4826- Args:
4827- filename: The name of the current file.
4828- clean_lines: A CleansedLines instance containing the file.
4829- linenum: The number of the line to check.
4830- error: The function to call with any errors found.
4831- """
4832- line = clean_lines .elided [linenum ]
4833-
4834- # Avoid preprocessor lines
4835- if Match (r'^\s*#' , line ):
4836- return
4837-
4838- if line .find ('/*' ) >= 0 or line .find ('*/' ) >= 0 :
4839- return
4840-
4841- for match in _V8_PERSISTENT_PATTERN .finditer (line ):
4842- error (filename , linenum , 'runtime/v8_persistent' , 2 ,
4843- 'Use v8::Global instead of v8::Persistent' )
4844-
4845- def CheckLeftLeaningPointer (filename , clean_lines , linenum , error ):
4846- """Check for left-leaning pointer placement.
4847-
4848- Args:
4849- filename: The name of the current file.
4850- clean_lines: A CleansedLines instance containing the file.
4851- linenum: The number of the line to check.
4852- error: The function to call with any errors found.
4853- """
4854- line = clean_lines .elided [linenum ]
4855-
4856- # Avoid preprocessor lines
4857- if Match (r'^\s*#' , line ):
4858- return
4859-
4860- if '/*' in line or '*/' in line :
4861- return
4862-
4863- for match in _RIGHT_LEANING_POINTER_PATTERN .finditer (line ):
4864- error (filename , linenum , 'readability/pointer_notation' , 2 ,
4865- 'Use left leaning pointer instead of right leaning' )
48664774
48674775def GetLineWidth (line ):
48684776 """Determines the width of the line in column positions.
@@ -5017,9 +4925,6 @@ def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state,
50174925 CheckSpacingForFunctionCall (filename , clean_lines , linenum , error )
50184926 CheckCheck (filename , clean_lines , linenum , error )
50194927 CheckAltTokens (filename , clean_lines , linenum , error )
5020- CheckNullTokens (filename , clean_lines , linenum , error )
5021- CheckV8PersistentTokens (filename , clean_lines , linenum , error )
5022- CheckLeftLeaningPointer (filename , clean_lines , linenum , error )
50234928 classinfo = nesting_state .InnermostClass ()
50244929 if classinfo :
50254930 CheckSectionSpacing (filename , clean_lines , classinfo , linenum , error )
@@ -5205,10 +5110,11 @@ def CheckIncludeLine(filename, clean_lines, linenum, include_state, error):
52055110 include_state .include_list [- 1 ].append ((include , linenum ))
52065111
52075112 # We want to ensure that headers appear in the right order:
5208- # 1) for foo.cc, foo.h
5209- # 2) other project headers
5210- # 3) c system files
5211- # 4) cpp system files
5113+ # 1) for foo.cc, foo.h (preferred location)
5114+ # 2) c system files
5115+ # 3) cpp system files
5116+ # 4) for foo.cc, foo.h (deprecated location)
5117+ # 5) other google headers
52125118 #
52135119 # We classify each include statement as one of those 5 types
52145120 # using a number of techniques. The include_state object keeps
@@ -5471,7 +5377,7 @@ def CheckLanguage(filename, clean_lines, linenum, file_extension,
54715377 and line [- 1 ] != '\\ ' ):
54725378 error (filename , linenum , 'build/namespaces_headers' , 4 ,
54735379 'Do not use unnamed namespaces in header files. See '
5474- 'https://google.github.io/styleguide/ cppguide.html #Namespaces'
5380+ 'https://google-styleguide.googlecode.com/svn/trunk/ cppguide.xml #Namespaces'
54755381 ' for more information.' )
54765382
54775383
@@ -5846,7 +5752,7 @@ def CheckCasts(filename, clean_lines, linenum, error):
58465752
58475753 if not expecting_function :
58485754 CheckCStyleCast (filename , clean_lines , linenum , 'static_cast' ,
5849- r'\((int|float|double|bool|char|u?int(16|32|64))\)' , error )
5755+ r'\((int|float|double|bool|char|u?int(16|32|64)|size_t )\)' , error )
58505756
58515757 # This doesn't catch all cases. Consider (const char * const)"hello".
58525758 #
@@ -6593,8 +6499,6 @@ def ProcessFileData(filename, file_extension, lines, error,
65936499
65946500 CheckForNewlineAtEOF (filename , lines , error )
65956501
6596- CheckInlineHeader (filename , include_state , error )
6597-
65986502def ProcessConfigOverrides (filename ):
65996503 """ Loads the configuration files and processes the config overrides.
66006504
@@ -6613,7 +6517,7 @@ def ProcessConfigOverrides(filename):
66136517 if not base_name :
66146518 break # Reached the root directory.
66156519
6616- cfg_file = os .path .join (abs_path , ".cpplint " )
6520+ cfg_file = os .path .join (abs_path , "CPPLINT.cfg " )
66176521 abs_filename = abs_path
66186522 if not os .path .isfile (cfg_file ):
66196523 continue
@@ -6783,10 +6687,10 @@ def PrintUsage(message):
67836687 Args:
67846688 message: The optional error message.
67856689 """
6786- sys .stderr .write (_USAGE % (list (GetAllExtensions ()),
6787- ',' .join (list (GetAllExtensions ())),
6788- GetHeaderExtensions (),
6789- ',' .join (GetHeaderExtensions ())))
6690+ sys .stderr .write (_USAGE % (sorted ( list (GetAllExtensions () )),
6691+ ',' .join (sorted ( list (GetAllExtensions () ))),
6692+ sorted ( GetHeaderExtensions () ),
6693+ ',' .join (sorted ( GetHeaderExtensions () ))))
67906694
67916695 if message :
67926696 sys .exit ('\n FATAL ERROR: ' + message )
0 commit comments