290
290
'build/include' ,
291
291
'build/include_subdir' ,
292
292
'build/include_alpha' ,
293
+ 'build/include_inline' ,
293
294
'build/include_order' ,
294
295
'build/include_what_you_use' ,
295
296
'build/namespaces_literals' ,
304
305
'readability/constructors' ,
305
306
'readability/fn_size' ,
306
307
'readability/inheritance' ,
308
+ 'readability/pointer_notation' ,
307
309
'readability/multiline_comment' ,
308
310
'readability/multiline_string' ,
309
311
'readability/namespace' ,
310
312
'readability/nolint' ,
311
313
'readability/nul' ,
314
+ 'readability/null_usage' ,
312
315
'readability/strings' ,
313
316
'readability/todo' ,
314
317
'readability/utf8' ,
328
331
'runtime/string' ,
329
332
'runtime/threadsafe_fn' ,
330
333
'runtime/vlog' ,
334
+ 'runtime/v8_persistent' ,
331
335
'whitespace/blank_line' ,
332
336
'whitespace/braces' ,
333
337
'whitespace/comma' ,
813
817
# Match string that indicates we're working on a Linux Kernel file.
814
818
_SEARCH_KERNEL_FILE = re .compile (r'\b(?:LINT_KERNEL_FILE)' )
815
819
820
+ _NULL_TOKEN_PATTERN = re .compile (r'\bNULL\b' )
821
+
822
+ _V8_PERSISTENT_PATTERN = re .compile (r'\bv8::Persistent\b' )
823
+
824
+ _RIGHT_LEANING_POINTER_PATTERN = re .compile (r'[^=|(,\s><);&?:}]'
825
+ r'(?<!(sizeof|return))'
826
+ r'\s\*[a-zA-Z_][0-9a-zA-Z_]*' )
827
+
816
828
_regexp_compile_cache = {}
817
829
818
830
# {str, set(int)}: a map from error categories to sets of linenumbers
832
844
# Files to exclude from linting. This is set by the --exclude flag.
833
845
_excludes = None
834
846
835
- # Whether to supress PrintInfo messages
847
+ # Whether to suppress PrintInfo messages
836
848
_quiet = False
837
849
838
850
# The allowed line length of files.
@@ -1053,10 +1065,11 @@ class _IncludeState(object):
1053
1065
# needs to move backwards, CheckNextIncludeOrder will raise an error.
1054
1066
_INITIAL_SECTION = 0
1055
1067
_MY_H_SECTION = 1
1056
- _C_SECTION = 2
1057
- _CPP_SECTION = 3
1058
- _OTHER_SYS_SECTION = 4
1059
- _OTHER_H_SECTION = 5
1068
+ _OTHER_H_SECTION = 2
1069
+ _OTHER_SYS_SECTION = 3
1070
+ _C_SECTION = 4
1071
+ _CPP_SECTION = 5
1072
+
1060
1073
1061
1074
_TYPE_NAMES = {
1062
1075
_C_SYS_HEADER : 'C system header' ,
@@ -2474,6 +2487,21 @@ def CheckForBadCharacters(filename, lines, error):
2474
2487
error (filename , linenum , 'readability/nul' , 5 , 'Line contains NUL byte.' )
2475
2488
2476
2489
2490
+ def CheckInlineHeader (filename , include_state , error ):
2491
+ """Logs an error if both a header and its inline variant are included."""
2492
+
2493
+ all_headers = dict (item for sublist in include_state .include_list
2494
+ for item in sublist )
2495
+ bad_headers = set ('%s.h' % name [:- 6 ] for name in all_headers .keys ()
2496
+ if name .endswith ('-inl.h' ))
2497
+ bad_headers &= set (all_headers .keys ())
2498
+
2499
+ for name in bad_headers :
2500
+ err = '%s includes both %s and %s-inl.h' % (filename , name , name )
2501
+ linenum = all_headers [name ]
2502
+ error (filename , linenum , 'build/include_inline' , 5 , err )
2503
+
2504
+
2477
2505
def CheckForNewlineAtEOF (filename , lines , error ):
2478
2506
"""Logs an error if there is no newline char at the end of the file.
2479
2507
@@ -3497,7 +3525,7 @@ def CheckForFunctionLengths(filename, clean_lines, linenum,
3497
3525
"""Reports for long function bodies.
3498
3526
3499
3527
For an overview why this is done, see:
3500
- https://google-styleguide.googlecode.com/svn/trunk/ cppguide.xml #Write_Short_Functions
3528
+ https://google.github.io/styleguide/ cppguide.html #Write_Short_Functions
3501
3529
3502
3530
Uses a simplistic algorithm assuming other style guidelines
3503
3531
(especially spacing) are followed.
@@ -4723,6 +4751,71 @@ def CheckAltTokens(filename, clean_lines, linenum, error):
4723
4751
'Use operator %s instead of %s' % (
4724
4752
_ALT_TOKEN_REPLACEMENT [match .group (1 )], match .group (1 )))
4725
4753
4754
+ def CheckNullTokens (filename , clean_lines , linenum , error ):
4755
+ """Check NULL usage.
4756
+
4757
+ Args:
4758
+ filename: The name of the current file.
4759
+ clean_lines: A CleansedLines instance containing the file.
4760
+ linenum: The number of the line to check.
4761
+ error: The function to call with any errors found.
4762
+ """
4763
+ line = clean_lines .elided [linenum ]
4764
+
4765
+ # Avoid preprocessor lines
4766
+ if Match (r'^\s*#' , line ):
4767
+ return
4768
+
4769
+ if line .find ('/*' ) >= 0 or line .find ('*/' ) >= 0 :
4770
+ return
4771
+
4772
+ for match in _NULL_TOKEN_PATTERN .finditer (line ):
4773
+ error (filename , linenum , 'readability/null_usage' , 2 ,
4774
+ 'Use nullptr instead of NULL' )
4775
+
4776
+ def CheckV8PersistentTokens (filename , clean_lines , linenum , error ):
4777
+ """Check v8::Persistent usage.
4778
+
4779
+ Args:
4780
+ filename: The name of the current file.
4781
+ clean_lines: A CleansedLines instance containing the file.
4782
+ linenum: The number of the line to check.
4783
+ error: The function to call with any errors found.
4784
+ """
4785
+ line = clean_lines .elided [linenum ]
4786
+
4787
+ # Avoid preprocessor lines
4788
+ if Match (r'^\s*#' , line ):
4789
+ return
4790
+
4791
+ if line .find ('/*' ) >= 0 or line .find ('*/' ) >= 0 :
4792
+ return
4793
+
4794
+ for match in _V8_PERSISTENT_PATTERN .finditer (line ):
4795
+ error (filename , linenum , 'runtime/v8_persistent' , 2 ,
4796
+ 'Use v8::Global instead of v8::Persistent' )
4797
+
4798
+ def CheckLeftLeaningPointer (filename , clean_lines , linenum , error ):
4799
+ """Check for left-leaning pointer placement.
4800
+
4801
+ Args:
4802
+ filename: The name of the current file.
4803
+ clean_lines: A CleansedLines instance containing the file.
4804
+ linenum: The number of the line to check.
4805
+ error: The function to call with any errors found.
4806
+ """
4807
+ line = clean_lines .elided [linenum ]
4808
+
4809
+ # Avoid preprocessor lines
4810
+ if Match (r'^\s*#' , line ):
4811
+ return
4812
+
4813
+ if '/*' in line or '*/' in line :
4814
+ return
4815
+
4816
+ for match in _RIGHT_LEANING_POINTER_PATTERN .finditer (line ):
4817
+ error (filename , linenum , 'readability/pointer_notation' , 2 ,
4818
+ 'Use left leaning pointer instead of right leaning' )
4726
4819
4727
4820
def GetLineWidth (line ):
4728
4821
"""Determines the width of the line in column positions.
@@ -4877,6 +4970,9 @@ def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state,
4877
4970
CheckSpacingForFunctionCall (filename , clean_lines , linenum , error )
4878
4971
CheckCheck (filename , clean_lines , linenum , error )
4879
4972
CheckAltTokens (filename , clean_lines , linenum , error )
4973
+ CheckNullTokens (filename , clean_lines , linenum , error )
4974
+ CheckV8PersistentTokens (filename , clean_lines , linenum , error )
4975
+ CheckLeftLeaningPointer (filename , clean_lines , linenum , error )
4880
4976
classinfo = nesting_state .InnermostClass ()
4881
4977
if classinfo :
4882
4978
CheckSectionSpacing (filename , clean_lines , classinfo , linenum , error )
@@ -5062,11 +5158,10 @@ def CheckIncludeLine(filename, clean_lines, linenum, include_state, error):
5062
5158
include_state .include_list [- 1 ].append ((include , linenum ))
5063
5159
5064
5160
# We want to ensure that headers appear in the right order:
5065
- # 1) for foo.cc, foo.h (preferred location)
5066
- # 2) c system files
5067
- # 3) cpp system files
5068
- # 4) for foo.cc, foo.h (deprecated location)
5069
- # 5) other google headers
5161
+ # 1) for foo.cc, foo.h
5162
+ # 2) other project headers
5163
+ # 3) c system files
5164
+ # 4) cpp system files
5070
5165
#
5071
5166
# We classify each include statement as one of those 5 types
5072
5167
# using a number of techniques. The include_state object keeps
@@ -5329,7 +5424,7 @@ def CheckLanguage(filename, clean_lines, linenum, file_extension,
5329
5424
and line [- 1 ] != '\\ ' ):
5330
5425
error (filename , linenum , 'build/namespaces' , 4 ,
5331
5426
'Do not use unnamed namespaces in header files. See '
5332
- 'https://google-styleguide.googlecode.com/svn/trunk/ cppguide.xml #Namespaces'
5427
+ 'https://google.github.io/styleguide/ cppguide.html #Namespaces'
5333
5428
' for more information.' )
5334
5429
5335
5430
@@ -6451,6 +6546,8 @@ def ProcessFileData(filename, file_extension, lines, error,
6451
6546
6452
6547
CheckForNewlineAtEOF (filename , lines , error )
6453
6548
6549
+ CheckInlineHeader (filename , include_state , error )
6550
+
6454
6551
def ProcessConfigOverrides (filename ):
6455
6552
""" Loads the configuration files and processes the config overrides.
6456
6553
@@ -6469,7 +6566,7 @@ def ProcessConfigOverrides(filename):
6469
6566
if not base_name :
6470
6567
break # Reached the root directory.
6471
6568
6472
- cfg_file = os .path .join (abs_path , "CPPLINT.cfg " )
6569
+ cfg_file = os .path .join (abs_path , ".cpplint " )
6473
6570
abs_filename = abs_path
6474
6571
if not os .path .isfile (cfg_file ):
6475
6572
continue
0 commit comments