300
300
'build/include' ,
301
301
'build/include_subdir' ,
302
302
'build/include_alpha' ,
303
+ 'build/include_inline' ,
303
304
'build/include_order' ,
304
305
'build/include_what_you_use' ,
305
306
'build/namespaces_headers' ,
315
316
'readability/constructors' ,
316
317
'readability/fn_size' ,
317
318
'readability/inheritance' ,
319
+ 'readability/pointer_notation' ,
318
320
'readability/multiline_comment' ,
319
321
'readability/multiline_string' ,
320
322
'readability/namespace' ,
321
323
'readability/nolint' ,
322
324
'readability/nul' ,
325
+ 'readability/null_usage' ,
323
326
'readability/strings' ,
324
327
'readability/todo' ,
325
328
'readability/utf8' ,
339
342
'runtime/string' ,
340
343
'runtime/threadsafe_fn' ,
341
344
'runtime/vlog' ,
345
+ 'runtime/v8_persistent' ,
342
346
'whitespace/blank_line' ,
343
347
'whitespace/braces' ,
344
348
'whitespace/comma' ,
847
851
'Missing space after ,' : r's/,\([^ ]\)/, \1/g' ,
848
852
}
849
853
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
+
850
862
_regexp_compile_cache = {}
851
863
852
864
# {str, set(int)}: a map from error categories to sets of linenumbers
@@ -1087,10 +1099,11 @@ class _IncludeState(object):
1087
1099
# needs to move backwards, CheckNextIncludeOrder will raise an error.
1088
1100
_INITIAL_SECTION = 0
1089
1101
_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
+
1094
1107
1095
1108
_TYPE_NAMES = {
1096
1109
_C_SYS_HEADER : 'C system header' ,
@@ -2527,6 +2540,21 @@ def CheckForBadCharacters(filename, lines, error):
2527
2540
error (filename , linenum , 'readability/nul' , 5 , 'Line contains NUL byte.' )
2528
2541
2529
2542
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
+
2530
2558
def CheckForNewlineAtEOF (filename , lines , error ):
2531
2559
"""Logs an error if there is no newline char at the end of the file.
2532
2560
@@ -3550,7 +3578,7 @@ def CheckForFunctionLengths(filename, clean_lines, linenum,
3550
3578
"""Reports for long function bodies.
3551
3579
3552
3580
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
3554
3582
3555
3583
Uses a simplistic algorithm assuming other style guidelines
3556
3584
(especially spacing) are followed.
@@ -4777,6 +4805,71 @@ def CheckAltTokens(filename, clean_lines, linenum, error):
4777
4805
'Use operator %s instead of %s' % (
4778
4806
_ALT_TOKEN_REPLACEMENT [match .group (1 )], match .group (1 )))
4779
4807
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' )
4780
4873
4781
4874
def GetLineWidth (line ):
4782
4875
"""Determines the width of the line in column positions.
@@ -4931,6 +5024,9 @@ def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state,
4931
5024
CheckSpacingForFunctionCall (filename , clean_lines , linenum , error )
4932
5025
CheckCheck (filename , clean_lines , linenum , error )
4933
5026
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 )
4934
5030
classinfo = nesting_state .InnermostClass ()
4935
5031
if classinfo :
4936
5032
CheckSectionSpacing (filename , clean_lines , classinfo , linenum , error )
@@ -5118,11 +5214,10 @@ def CheckIncludeLine(filename, clean_lines, linenum, include_state, error):
5118
5214
include_state .include_list [- 1 ].append ((include , linenum ))
5119
5215
5120
5216
# 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
5126
5221
#
5127
5222
# We classify each include statement as one of those 5 types
5128
5223
# using a number of techniques. The include_state object keeps
@@ -5385,7 +5480,7 @@ def CheckLanguage(filename, clean_lines, linenum, file_extension,
5385
5480
and line [- 1 ] != '\\ ' ):
5386
5481
error (filename , linenum , 'build/namespaces_headers' , 4 ,
5387
5482
'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'
5389
5484
' for more information.' )
5390
5485
5391
5486
@@ -6507,6 +6602,8 @@ def ProcessFileData(filename, file_extension, lines, error,
6507
6602
6508
6603
CheckForNewlineAtEOF (filename , lines , error )
6509
6604
6605
+ CheckInlineHeader (filename , include_state , error )
6606
+
6510
6607
def ProcessConfigOverrides (filename ):
6511
6608
""" Loads the configuration files and processes the config overrides.
6512
6609
@@ -6525,7 +6622,7 @@ def ProcessConfigOverrides(filename):
6525
6622
if not base_name :
6526
6623
break # Reached the root directory.
6527
6624
6528
- cfg_file = os .path .join (abs_path , "CPPLINT.cfg " )
6625
+ cfg_file = os .path .join (abs_path , ".cpplint " )
6529
6626
abs_filename = abs_path
6530
6627
if not os .path .isfile (cfg_file ):
6531
6628
continue
0 commit comments