302
302
'build/include' ,
303
303
'build/include_subdir' ,
304
304
'build/include_alpha' ,
305
+ 'build/include_inline' ,
305
306
'build/include_order' ,
306
307
'build/include_what_you_use' ,
307
308
'build/namespaces_headers' ,
317
318
'readability/constructors' ,
318
319
'readability/fn_size' ,
319
320
'readability/inheritance' ,
321
+ 'readability/pointer_notation' ,
320
322
'readability/multiline_comment' ,
321
323
'readability/multiline_string' ,
322
324
'readability/namespace' ,
323
325
'readability/nolint' ,
324
326
'readability/nul' ,
327
+ 'readability/null_usage' ,
325
328
'readability/strings' ,
326
329
'readability/todo' ,
327
330
'readability/utf8' ,
341
344
'runtime/string' ,
342
345
'runtime/threadsafe_fn' ,
343
346
'runtime/vlog' ,
347
+ 'runtime/v8_persistent' ,
344
348
'whitespace/blank_line' ,
345
349
'whitespace/braces' ,
346
350
'whitespace/comma' ,
871
875
'Missing space after ,' : r's/,\([^ ]\)/, \1/g' ,
872
876
}
873
877
878
+ _NULL_TOKEN_PATTERN = re .compile (r'\bNULL\b' )
879
+
880
+ _V8_PERSISTENT_PATTERN = re .compile (r'\bv8::Persistent\b' )
881
+
882
+ _RIGHT_LEANING_POINTER_PATTERN = re .compile (r'[^=|(,\s><);&?:}]'
883
+ r'(?<!(sizeof|return))'
884
+ r'\s\*[a-zA-Z_][0-9a-zA-Z_]*' )
885
+
874
886
_regexp_compile_cache = {}
875
887
876
888
# {str, set(int)}: a map from error categories to sets of linenumbers
@@ -1115,10 +1127,11 @@ class _IncludeState(object):
1115
1127
# needs to move backwards, CheckNextIncludeOrder will raise an error.
1116
1128
_INITIAL_SECTION = 0
1117
1129
_MY_H_SECTION = 1
1118
- _C_SECTION = 2
1119
- _CPP_SECTION = 3
1120
- _OTHER_SYS_SECTION = 4
1121
- _OTHER_H_SECTION = 5
1130
+ _OTHER_H_SECTION = 2
1131
+ _OTHER_SYS_SECTION = 3
1132
+ _C_SECTION = 4
1133
+ _CPP_SECTION = 5
1134
+
1122
1135
1123
1136
_TYPE_NAMES = {
1124
1137
_C_SYS_HEADER : 'C system header' ,
@@ -2555,6 +2568,21 @@ def CheckForBadCharacters(filename, lines, error):
2555
2568
error (filename , linenum , 'readability/nul' , 5 , 'Line contains NUL byte.' )
2556
2569
2557
2570
2571
+ def CheckInlineHeader (filename , include_state , error ):
2572
+ """Logs an error if both a header and its inline variant are included."""
2573
+
2574
+ all_headers = dict (item for sublist in include_state .include_list
2575
+ for item in sublist )
2576
+ bad_headers = set ('%s.h' % name [:- 6 ] for name in all_headers .keys ()
2577
+ if name .endswith ('-inl.h' ))
2578
+ bad_headers &= set (all_headers .keys ())
2579
+
2580
+ for name in bad_headers :
2581
+ err = '%s includes both %s and %s-inl.h' % (filename , name , name )
2582
+ linenum = all_headers [name ]
2583
+ error (filename , linenum , 'build/include_inline' , 5 , err )
2584
+
2585
+
2558
2586
def CheckForNewlineAtEOF (filename , lines , error ):
2559
2587
"""Logs an error if there is no newline char at the end of the file.
2560
2588
@@ -3578,7 +3606,7 @@ def CheckForFunctionLengths(filename, clean_lines, linenum,
3578
3606
"""Reports for long function bodies.
3579
3607
3580
3608
For an overview why this is done, see:
3581
- https://google-styleguide.googlecode.com/svn/trunk/ cppguide.xml #Write_Short_Functions
3609
+ https://google.github.io/styleguide/ cppguide.html #Write_Short_Functions
3582
3610
3583
3611
Uses a simplistic algorithm assuming other style guidelines
3584
3612
(especially spacing) are followed.
@@ -4805,6 +4833,71 @@ def CheckAltTokens(filename, clean_lines, linenum, error):
4805
4833
'Use operator %s instead of %s' % (
4806
4834
_ALT_TOKEN_REPLACEMENT [match .group (1 )], match .group (1 )))
4807
4835
4836
+ def CheckNullTokens (filename , clean_lines , linenum , error ):
4837
+ """Check NULL usage.
4838
+
4839
+ Args:
4840
+ filename: The name of the current file.
4841
+ clean_lines: A CleansedLines instance containing the file.
4842
+ linenum: The number of the line to check.
4843
+ error: The function to call with any errors found.
4844
+ """
4845
+ line = clean_lines .elided [linenum ]
4846
+
4847
+ # Avoid preprocessor lines
4848
+ if Match (r'^\s*#' , line ):
4849
+ return
4850
+
4851
+ if line .find ('/*' ) >= 0 or line .find ('*/' ) >= 0 :
4852
+ return
4853
+
4854
+ for match in _NULL_TOKEN_PATTERN .finditer (line ):
4855
+ error (filename , linenum , 'readability/null_usage' , 2 ,
4856
+ 'Use nullptr instead of NULL' )
4857
+
4858
+ def CheckV8PersistentTokens (filename , clean_lines , linenum , error ):
4859
+ """Check v8::Persistent usage.
4860
+
4861
+ Args:
4862
+ filename: The name of the current file.
4863
+ clean_lines: A CleansedLines instance containing the file.
4864
+ linenum: The number of the line to check.
4865
+ error: The function to call with any errors found.
4866
+ """
4867
+ line = clean_lines .elided [linenum ]
4868
+
4869
+ # Avoid preprocessor lines
4870
+ if Match (r'^\s*#' , line ):
4871
+ return
4872
+
4873
+ if line .find ('/*' ) >= 0 or line .find ('*/' ) >= 0 :
4874
+ return
4875
+
4876
+ for match in _V8_PERSISTENT_PATTERN .finditer (line ):
4877
+ error (filename , linenum , 'runtime/v8_persistent' , 2 ,
4878
+ 'Use v8::Global instead of v8::Persistent' )
4879
+
4880
+ def CheckLeftLeaningPointer (filename , clean_lines , linenum , error ):
4881
+ """Check for left-leaning pointer placement.
4882
+
4883
+ Args:
4884
+ filename: The name of the current file.
4885
+ clean_lines: A CleansedLines instance containing the file.
4886
+ linenum: The number of the line to check.
4887
+ error: The function to call with any errors found.
4888
+ """
4889
+ line = clean_lines .elided [linenum ]
4890
+
4891
+ # Avoid preprocessor lines
4892
+ if Match (r'^\s*#' , line ):
4893
+ return
4894
+
4895
+ if '/*' in line or '*/' in line :
4896
+ return
4897
+
4898
+ for match in _RIGHT_LEANING_POINTER_PATTERN .finditer (line ):
4899
+ error (filename , linenum , 'readability/pointer_notation' , 2 ,
4900
+ 'Use left leaning pointer instead of right leaning' )
4808
4901
4809
4902
def GetLineWidth (line ):
4810
4903
"""Determines the width of the line in column positions.
@@ -4959,6 +5052,9 @@ def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state,
4959
5052
CheckSpacingForFunctionCall (filename , clean_lines , linenum , error )
4960
5053
CheckCheck (filename , clean_lines , linenum , error )
4961
5054
CheckAltTokens (filename , clean_lines , linenum , error )
5055
+ CheckNullTokens (filename , clean_lines , linenum , error )
5056
+ CheckV8PersistentTokens (filename , clean_lines , linenum , error )
5057
+ CheckLeftLeaningPointer (filename , clean_lines , linenum , error )
4962
5058
classinfo = nesting_state .InnermostClass ()
4963
5059
if classinfo :
4964
5060
CheckSectionSpacing (filename , clean_lines , classinfo , linenum , error )
@@ -5147,11 +5243,10 @@ def CheckIncludeLine(filename, clean_lines, linenum, include_state, error):
5147
5243
include_state .include_list [- 1 ].append ((include , linenum ))
5148
5244
5149
5245
# We want to ensure that headers appear in the right order:
5150
- # 1) for foo.cc, foo.h (preferred location)
5151
- # 2) c system files
5152
- # 3) cpp system files
5153
- # 4) for foo.cc, foo.h (deprecated location)
5154
- # 5) other google headers
5246
+ # 1) for foo.cc, foo.h
5247
+ # 2) other project headers
5248
+ # 3) c system files
5249
+ # 4) cpp system files
5155
5250
#
5156
5251
# We classify each include statement as one of those 5 types
5157
5252
# using a number of techniques. The include_state object keeps
@@ -5414,7 +5509,7 @@ def CheckLanguage(filename, clean_lines, linenum, file_extension,
5414
5509
and line [- 1 ] != '\\ ' ):
5415
5510
error (filename , linenum , 'build/namespaces_headers' , 4 ,
5416
5511
'Do not use unnamed namespaces in header files. See '
5417
- 'https://google-styleguide.googlecode.com/svn/trunk/ cppguide.xml #Namespaces'
5512
+ 'https://google.github.io/styleguide/ cppguide.html #Namespaces'
5418
5513
' for more information.' )
5419
5514
5420
5515
@@ -6537,6 +6632,8 @@ def ProcessFileData(filename, file_extension, lines, error,
6537
6632
6538
6633
CheckForNewlineAtEOF (filename , lines , error )
6539
6634
6635
+ CheckInlineHeader (filename , include_state , error )
6636
+
6540
6637
def ProcessConfigOverrides (filename ):
6541
6638
""" Loads the configuration files and processes the config overrides.
6542
6639
@@ -6555,7 +6652,7 @@ def ProcessConfigOverrides(filename):
6555
6652
if not base_name :
6556
6653
break # Reached the root directory.
6557
6654
6558
- cfg_file = os .path .join (abs_path , "CPPLINT.cfg " )
6655
+ cfg_file = os .path .join (abs_path , ".cpplint " )
6559
6656
abs_filename = abs_path
6560
6657
if not os .path .isfile (cfg_file ):
6561
6658
continue
0 commit comments