295
295
'build/include' ,
296
296
'build/include_subdir' ,
297
297
'build/include_alpha' ,
298
+ 'build/include_inline' ,
298
299
'build/include_order' ,
299
300
'build/include_what_you_use' ,
300
301
'build/namespaces_headers' ,
310
311
'readability/constructors' ,
311
312
'readability/fn_size' ,
312
313
'readability/inheritance' ,
314
+ 'readability/pointer_notation' ,
313
315
'readability/multiline_comment' ,
314
316
'readability/multiline_string' ,
315
317
'readability/namespace' ,
316
318
'readability/nolint' ,
317
319
'readability/nul' ,
320
+ 'readability/null_usage' ,
318
321
'readability/strings' ,
319
322
'readability/todo' ,
320
323
'readability/utf8' ,
334
337
'runtime/string' ,
335
338
'runtime/threadsafe_fn' ,
336
339
'runtime/vlog' ,
340
+ 'runtime/v8_persistent' ,
337
341
'whitespace/blank_line' ,
338
342
'whitespace/braces' ,
339
343
'whitespace/comma' ,
842
846
'Missing space after ,' : r's/,\([^ ]\)/, \1/g' ,
843
847
}
844
848
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
+
845
857
_regexp_compile_cache = {}
846
858
847
859
# {str, set(int)}: a map from error categories to sets of linenumbers
@@ -1082,10 +1094,11 @@ class _IncludeState(object):
1082
1094
# needs to move backwards, CheckNextIncludeOrder will raise an error.
1083
1095
_INITIAL_SECTION = 0
1084
1096
_MY_H_SECTION = 1
1085
- _C_SECTION = 2
1086
- _CPP_SECTION = 3
1087
- _OTHER_SYS_SECTION = 4
1088
- _OTHER_H_SECTION = 5
1097
+ _OTHER_H_SECTION = 2
1098
+ _OTHER_SYS_SECTION = 3
1099
+ _C_SECTION = 4
1100
+ _CPP_SECTION = 5
1101
+
1089
1102
1090
1103
_TYPE_NAMES = {
1091
1104
_C_SYS_HEADER : 'C system header' ,
@@ -2521,6 +2534,21 @@ def CheckForBadCharacters(filename, lines, error):
2521
2534
error (filename , linenum , 'readability/nul' , 5 , 'Line contains NUL byte.' )
2522
2535
2523
2536
2537
+ def CheckInlineHeader (filename , include_state , error ):
2538
+ """Logs an error if both a header and its inline variant are included."""
2539
+
2540
+ all_headers = dict (item for sublist in include_state .include_list
2541
+ for item in sublist )
2542
+ bad_headers = set ('%s.h' % name [:- 6 ] for name in all_headers .keys ()
2543
+ if name .endswith ('-inl.h' ))
2544
+ bad_headers &= set (all_headers .keys ())
2545
+
2546
+ for name in bad_headers :
2547
+ err = '%s includes both %s and %s-inl.h' % (filename , name , name )
2548
+ linenum = all_headers [name ]
2549
+ error (filename , linenum , 'build/include_inline' , 5 , err )
2550
+
2551
+
2524
2552
def CheckForNewlineAtEOF (filename , lines , error ):
2525
2553
"""Logs an error if there is no newline char at the end of the file.
2526
2554
@@ -3544,7 +3572,7 @@ def CheckForFunctionLengths(filename, clean_lines, linenum,
3544
3572
"""Reports for long function bodies.
3545
3573
3546
3574
For an overview why this is done, see:
3547
- https://google-styleguide.googlecode.com/svn/trunk/ cppguide.xml #Write_Short_Functions
3575
+ https://google.github.io/styleguide/ cppguide.html #Write_Short_Functions
3548
3576
3549
3577
Uses a simplistic algorithm assuming other style guidelines
3550
3578
(especially spacing) are followed.
@@ -4771,6 +4799,71 @@ def CheckAltTokens(filename, clean_lines, linenum, error):
4771
4799
'Use operator %s instead of %s' % (
4772
4800
_ALT_TOKEN_REPLACEMENT [match .group (1 )], match .group (1 )))
4773
4801
4802
+ def CheckNullTokens (filename , clean_lines , linenum , error ):
4803
+ """Check NULL usage.
4804
+
4805
+ Args:
4806
+ filename: The name of the current file.
4807
+ clean_lines: A CleansedLines instance containing the file.
4808
+ linenum: The number of the line to check.
4809
+ error: The function to call with any errors found.
4810
+ """
4811
+ line = clean_lines .elided [linenum ]
4812
+
4813
+ # Avoid preprocessor lines
4814
+ if Match (r'^\s*#' , line ):
4815
+ return
4816
+
4817
+ if line .find ('/*' ) >= 0 or line .find ('*/' ) >= 0 :
4818
+ return
4819
+
4820
+ for match in _NULL_TOKEN_PATTERN .finditer (line ):
4821
+ error (filename , linenum , 'readability/null_usage' , 2 ,
4822
+ 'Use nullptr instead of NULL' )
4823
+
4824
+ def CheckV8PersistentTokens (filename , clean_lines , linenum , error ):
4825
+ """Check v8::Persistent usage.
4826
+
4827
+ Args:
4828
+ filename: The name of the current file.
4829
+ clean_lines: A CleansedLines instance containing the file.
4830
+ linenum: The number of the line to check.
4831
+ error: The function to call with any errors found.
4832
+ """
4833
+ line = clean_lines .elided [linenum ]
4834
+
4835
+ # Avoid preprocessor lines
4836
+ if Match (r'^\s*#' , line ):
4837
+ return
4838
+
4839
+ if line .find ('/*' ) >= 0 or line .find ('*/' ) >= 0 :
4840
+ return
4841
+
4842
+ for match in _V8_PERSISTENT_PATTERN .finditer (line ):
4843
+ error (filename , linenum , 'runtime/v8_persistent' , 2 ,
4844
+ 'Use v8::Global instead of v8::Persistent' )
4845
+
4846
+ def CheckLeftLeaningPointer (filename , clean_lines , linenum , error ):
4847
+ """Check for left-leaning pointer placement.
4848
+
4849
+ Args:
4850
+ filename: The name of the current file.
4851
+ clean_lines: A CleansedLines instance containing the file.
4852
+ linenum: The number of the line to check.
4853
+ error: The function to call with any errors found.
4854
+ """
4855
+ line = clean_lines .elided [linenum ]
4856
+
4857
+ # Avoid preprocessor lines
4858
+ if Match (r'^\s*#' , line ):
4859
+ return
4860
+
4861
+ if '/*' in line or '*/' in line :
4862
+ return
4863
+
4864
+ for match in _RIGHT_LEANING_POINTER_PATTERN .finditer (line ):
4865
+ error (filename , linenum , 'readability/pointer_notation' , 2 ,
4866
+ 'Use left leaning pointer instead of right leaning' )
4774
4867
4775
4868
def GetLineWidth (line ):
4776
4869
"""Determines the width of the line in column positions.
@@ -4925,6 +5018,9 @@ def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state,
4925
5018
CheckSpacingForFunctionCall (filename , clean_lines , linenum , error )
4926
5019
CheckCheck (filename , clean_lines , linenum , error )
4927
5020
CheckAltTokens (filename , clean_lines , linenum , error )
5021
+ CheckNullTokens (filename , clean_lines , linenum , error )
5022
+ CheckV8PersistentTokens (filename , clean_lines , linenum , error )
5023
+ CheckLeftLeaningPointer (filename , clean_lines , linenum , error )
4928
5024
classinfo = nesting_state .InnermostClass ()
4929
5025
if classinfo :
4930
5026
CheckSectionSpacing (filename , clean_lines , classinfo , linenum , error )
@@ -5110,11 +5206,10 @@ def CheckIncludeLine(filename, clean_lines, linenum, include_state, error):
5110
5206
include_state .include_list [- 1 ].append ((include , linenum ))
5111
5207
5112
5208
# We want to ensure that headers appear in the right order:
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
5209
+ # 1) for foo.cc, foo.h
5210
+ # 2) other project headers
5211
+ # 3) c system files
5212
+ # 4) cpp system files
5118
5213
#
5119
5214
# We classify each include statement as one of those 5 types
5120
5215
# using a number of techniques. The include_state object keeps
@@ -5377,7 +5472,7 @@ def CheckLanguage(filename, clean_lines, linenum, file_extension,
5377
5472
and line [- 1 ] != '\\ ' ):
5378
5473
error (filename , linenum , 'build/namespaces_headers' , 4 ,
5379
5474
'Do not use unnamed namespaces in header files. See '
5380
- 'https://google-styleguide.googlecode.com/svn/trunk/ cppguide.xml #Namespaces'
5475
+ 'https://google.github.io/styleguide/ cppguide.html #Namespaces'
5381
5476
' for more information.' )
5382
5477
5383
5478
@@ -6499,6 +6594,8 @@ def ProcessFileData(filename, file_extension, lines, error,
6499
6594
6500
6595
CheckForNewlineAtEOF (filename , lines , error )
6501
6596
6597
+ CheckInlineHeader (filename , include_state , error )
6598
+
6502
6599
def ProcessConfigOverrides (filename ):
6503
6600
""" Loads the configuration files and processes the config overrides.
6504
6601
@@ -6517,7 +6614,7 @@ def ProcessConfigOverrides(filename):
6517
6614
if not base_name :
6518
6615
break # Reached the root directory.
6519
6616
6520
- cfg_file = os .path .join (abs_path , "CPPLINT.cfg " )
6617
+ cfg_file = os .path .join (abs_path , ".cpplint " )
6521
6618
abs_filename = abs_path
6522
6619
if not os .path .isfile (cfg_file ):
6523
6620
continue
0 commit comments