Skip to content

Commit d177cb3

Browse files
TrottBethGriggs
authored andcommittedDec 15, 2020
tools: bump cpplint to 1.5.1
https://github.com/cpplint/cpplint/releases/tag/1.5.1 PR-URL: #35866 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Richard Lau <rlau@redhat.com>
1 parent a15dede commit d177cb3

File tree

1 file changed

+123
-125
lines changed

1 file changed

+123
-125
lines changed
 

‎tools/cpplint.py

+123-125
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
# if empty, use defaults
6060
_valid_extensions = set([])
6161

62-
__VERSION__ = '1.5.0'
62+
__VERSION__ = '1.5.1'
6363

6464
try:
6565
xrange # Python 2
@@ -77,6 +77,7 @@
7777
[--recursive]
7878
[--exclude=path]
7979
[--extensions=hpp,cpp,...]
80+
[--includeorder=default|standardcfirst]
8081
[--quiet]
8182
[--version]
8283
<file> [file] ...
@@ -209,6 +210,15 @@
209210
Examples:
210211
--extensions=%s
211212
213+
includeorder=default|standardcfirst
214+
For the build/include_order rule, the default is to blindly assume angle
215+
bracket includes with file extension are c-system-headers (default),
216+
even knowing this will have false classifications.
217+
The default is established at google.
218+
standardcfirst means to instead use an allow-list of known c headers and
219+
treat all others as separate group of "other system headers". The C headers
220+
included are those of the C-standard lib and closely related ones.
221+
212222
headers=x,y,...
213223
The header extensions that cpplint will treat as .h in checks. Values are
214224
automatically added to --extensions list.
@@ -280,7 +290,6 @@
280290
'build/include',
281291
'build/include_subdir',
282292
'build/include_alpha',
283-
'build/include_inline',
284293
'build/include_order',
285294
'build/include_what_you_use',
286295
'build/namespaces_literals',
@@ -295,13 +304,11 @@
295304
'readability/constructors',
296305
'readability/fn_size',
297306
'readability/inheritance',
298-
'readability/pointer_notation',
299307
'readability/multiline_comment',
300308
'readability/multiline_string',
301309
'readability/namespace',
302310
'readability/nolint',
303311
'readability/nul',
304-
'readability/null_usage',
305312
'readability/strings',
306313
'readability/todo',
307314
'readability/utf8',
@@ -321,7 +328,6 @@
321328
'runtime/string',
322329
'runtime/threadsafe_fn',
323330
'runtime/vlog',
324-
'runtime/v8_persistent',
325331
'whitespace/blank_line',
326332
'whitespace/braces',
327333
'whitespace/comma',
@@ -550,7 +556,7 @@
550556
'uchar.h',
551557
'wchar.h',
552558
'wctype.h',
553-
# POSIX C headers
559+
# additional POSIX C headers
554560
'aio.h',
555561
'arpa/inet.h',
556562
'cpio.h',
@@ -594,7 +600,7 @@
594600
'utime.h',
595601
'utmpx.h',
596602
'wordexp.h',
597-
# GNUlib headers
603+
# additional GNUlib headers
598604
'a.out.h',
599605
'aliases.h',
600606
'alloca.h',
@@ -626,12 +632,78 @@
626632
'shadow.h',
627633
'sysexits.h',
628634
'ttyent.h',
635+
# Additional linux glibc headers
636+
'dlfcn.h',
637+
'elf.h',
638+
'features.h',
639+
'gconv.h',
640+
'gnu-versions.h',
641+
'lastlog.h',
642+
'libio.h',
643+
'link.h',
644+
'malloc.h',
645+
'memory.h',
646+
'netash/ash.h',
647+
'netatalk/at.h',
648+
'netax25/ax25.h',
649+
'neteconet/ec.h',
650+
'netipx/ipx.h',
651+
'netiucv/iucv.h',
652+
'netpacket/packet.h',
653+
'netrom/netrom.h',
654+
'netrose/rose.h',
655+
'nfs/nfs.h',
656+
'nl_types.h',
657+
'nss.h',
658+
're_comp.h',
659+
'regexp.h',
660+
'sched.h',
661+
'sgtty.h',
662+
'stab.h',
663+
'stdc-predef.h',
664+
'stdio_ext.h',
665+
'syscall.h',
666+
'termio.h',
667+
'thread_db.h',
668+
'ucontext.h',
669+
'ustat.h',
670+
'utmp.h',
671+
'values.h',
672+
'wait.h',
673+
'xlocale.h',
629674
# Hardware specific headers
630675
'arm_neon.h',
631676
'emmintrin.h',
632677
'xmmintin.h',
633678
])
634679

680+
# Folders of C libraries so commonly used in C++,
681+
# that they have parity with standard C libraries.
682+
C_STANDARD_HEADER_FOLDERS = frozenset([
683+
# standard C library
684+
"sys",
685+
# glibc for linux
686+
"arpa",
687+
"asm-generic",
688+
"bits",
689+
"gnu",
690+
"net",
691+
"netinet",
692+
"protocols",
693+
"rpc",
694+
"rpcsvc",
695+
"scsi",
696+
# linux kernel header
697+
"drm",
698+
"linux",
699+
"misc",
700+
"mtd",
701+
"rdma",
702+
"sound",
703+
"video",
704+
"xen",
705+
])
706+
635707
# Type names
636708
_TYPES = re.compile(
637709
r'^(?:'
@@ -741,14 +813,6 @@
741813
# Match string that indicates we're working on a Linux Kernel file.
742814
_SEARCH_KERNEL_FILE = re.compile(r'\b(?:LINT_KERNEL_FILE)')
743815

744-
_NULL_TOKEN_PATTERN = re.compile(r'\bNULL\b')
745-
746-
_V8_PERSISTENT_PATTERN = re.compile(r'\bv8::Persistent\b')
747-
748-
_RIGHT_LEANING_POINTER_PATTERN = re.compile(r'[^=|(,\s><);&?:}]'
749-
r'(?<!(sizeof|return))'
750-
r'\s\*[a-zA-Z_][0-9a-zA-Z_]*')
751-
752816
_regexp_compile_cache = {}
753817

754818
# {str, set(int)}: a map from error categories to sets of linenumbers
@@ -768,13 +832,16 @@
768832
# Files to exclude from linting. This is set by the --exclude flag.
769833
_excludes = None
770834

771-
# Whether to suppress PrintInfo messages
835+
# Whether to supress PrintInfo messages
772836
_quiet = False
773837

774838
# The allowed line length of files.
775839
# This is set by --linelength flag.
776840
_line_length = 80
777841

842+
# This allows to use different include order rule than default
843+
_include_order = "default"
844+
778845
try:
779846
unicode
780847
except NameError:
@@ -818,6 +885,15 @@ def ProcessHppHeadersOption(val):
818885
except ValueError:
819886
PrintUsage('Header extensions must be comma separated list.')
820887

888+
def ProcessIncludeOrderOption(val):
889+
if val is None or val == "default":
890+
pass
891+
elif val == "standardcfirst":
892+
global _include_order
893+
_include_order = val
894+
else:
895+
PrintUsage('Invalid includeorder value %s. Expected default|standardcfirst')
896+
821897
def IsHeaderExtension(file_extension):
822898
return file_extension in GetHeaderExtensions()
823899

@@ -977,11 +1053,10 @@ class _IncludeState(object):
9771053
# needs to move backwards, CheckNextIncludeOrder will raise an error.
9781054
_INITIAL_SECTION = 0
9791055
_MY_H_SECTION = 1
980-
_OTHER_H_SECTION = 2
981-
_OTHER_SYS_SECTION = 3
982-
_C_SECTION = 4
983-
_CPP_SECTION = 5
984-
1056+
_C_SECTION = 2
1057+
_CPP_SECTION = 3
1058+
_OTHER_SYS_SECTION = 4
1059+
_OTHER_H_SECTION = 5
9851060

9861061
_TYPE_NAMES = {
9871062
_C_SYS_HEADER: 'C system header',
@@ -2399,21 +2474,6 @@ def CheckForBadCharacters(filename, lines, error):
23992474
error(filename, linenum, 'readability/nul', 5, 'Line contains NUL byte.')
24002475

24012476

2402-
def CheckInlineHeader(filename, include_state, error):
2403-
"""Logs an error if both a header and its inline variant are included."""
2404-
2405-
all_headers = dict(item for sublist in include_state.include_list
2406-
for item in sublist)
2407-
bad_headers = set('%s.h' % name[:-6] for name in all_headers.keys()
2408-
if name.endswith('-inl.h'))
2409-
bad_headers &= set(all_headers.keys())
2410-
2411-
for name in bad_headers:
2412-
err = '%s includes both %s and %s-inl.h' % (filename, name, name)
2413-
linenum = all_headers[name]
2414-
error(filename, linenum, 'build/include_inline', 5, err)
2415-
2416-
24172477
def CheckForNewlineAtEOF(filename, lines, error):
24182478
"""Logs an error if there is no newline char at the end of the file.
24192479
@@ -3437,7 +3497,7 @@ def CheckForFunctionLengths(filename, clean_lines, linenum,
34373497
"""Reports for long function bodies.
34383498
34393499
For an overview why this is done, see:
3440-
https://google.github.io/styleguide/cppguide.html#Write_Short_Functions
3500+
https://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Write_Short_Functions
34413501
34423502
Uses a simplistic algorithm assuming other style guidelines
34433503
(especially spacing) are followed.
@@ -4663,71 +4723,6 @@ def CheckAltTokens(filename, clean_lines, linenum, error):
46634723
'Use operator %s instead of %s' % (
46644724
_ALT_TOKEN_REPLACEMENT[match.group(1)], match.group(1)))
46654725

4666-
def CheckNullTokens(filename, clean_lines, linenum, error):
4667-
"""Check NULL usage.
4668-
4669-
Args:
4670-
filename: The name of the current file.
4671-
clean_lines: A CleansedLines instance containing the file.
4672-
linenum: The number of the line to check.
4673-
error: The function to call with any errors found.
4674-
"""
4675-
line = clean_lines.elided[linenum]
4676-
4677-
# Avoid preprocessor lines
4678-
if Match(r'^\s*#', line):
4679-
return
4680-
4681-
if line.find('/*') >= 0 or line.find('*/') >= 0:
4682-
return
4683-
4684-
for match in _NULL_TOKEN_PATTERN.finditer(line):
4685-
error(filename, linenum, 'readability/null_usage', 2,
4686-
'Use nullptr instead of NULL')
4687-
4688-
def CheckV8PersistentTokens(filename, clean_lines, linenum, error):
4689-
"""Check v8::Persistent usage.
4690-
4691-
Args:
4692-
filename: The name of the current file.
4693-
clean_lines: A CleansedLines instance containing the file.
4694-
linenum: The number of the line to check.
4695-
error: The function to call with any errors found.
4696-
"""
4697-
line = clean_lines.elided[linenum]
4698-
4699-
# Avoid preprocessor lines
4700-
if Match(r'^\s*#', line):
4701-
return
4702-
4703-
if line.find('/*') >= 0 or line.find('*/') >= 0:
4704-
return
4705-
4706-
for match in _V8_PERSISTENT_PATTERN.finditer(line):
4707-
error(filename, linenum, 'runtime/v8_persistent', 2,
4708-
'Use v8::Global instead of v8::Persistent')
4709-
4710-
def CheckLeftLeaningPointer(filename, clean_lines, linenum, error):
4711-
"""Check for left-leaning pointer placement.
4712-
4713-
Args:
4714-
filename: The name of the current file.
4715-
clean_lines: A CleansedLines instance containing the file.
4716-
linenum: The number of the line to check.
4717-
error: The function to call with any errors found.
4718-
"""
4719-
line = clean_lines.elided[linenum]
4720-
4721-
# Avoid preprocessor lines
4722-
if Match(r'^\s*#', line):
4723-
return
4724-
4725-
if '/*' in line or '*/' in line:
4726-
return
4727-
4728-
for match in _RIGHT_LEANING_POINTER_PATTERN.finditer(line):
4729-
error(filename, linenum, 'readability/pointer_notation', 2,
4730-
'Use left leaning pointer instead of right leaning')
47314726

47324727
def GetLineWidth(line):
47334728
"""Determines the width of the line in column positions.
@@ -4882,9 +4877,6 @@ def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state,
48824877
CheckSpacingForFunctionCall(filename, clean_lines, linenum, error)
48834878
CheckCheck(filename, clean_lines, linenum, error)
48844879
CheckAltTokens(filename, clean_lines, linenum, error)
4885-
CheckNullTokens(filename, clean_lines, linenum, error)
4886-
CheckV8PersistentTokens(filename, clean_lines, linenum, error)
4887-
CheckLeftLeaningPointer(filename, clean_lines, linenum, error)
48884880
classinfo = nesting_state.InnermostClass()
48894881
if classinfo:
48904882
CheckSectionSpacing(filename, clean_lines, classinfo, linenum, error)
@@ -4929,13 +4921,14 @@ def _DropCommonSuffixes(filename):
49294921
return os.path.splitext(filename)[0]
49304922

49314923

4932-
def _ClassifyInclude(fileinfo, include, is_system):
4924+
def _ClassifyInclude(fileinfo, include, used_angle_brackets, include_order="default"):
49334925
"""Figures out what kind of header 'include' is.
49344926
49354927
Args:
49364928
fileinfo: The current file cpplint is running over. A FileInfo instance.
49374929
include: The path to a #included file.
4938-
is_system: True if the #include used <> rather than "".
4930+
used_angle_brackets: True if the #include used <> rather than "".
4931+
include_order: "default" or other value allowed in program arguments
49394932
49404933
Returns:
49414934
One of the _XXX_HEADER constants.
@@ -4945,7 +4938,7 @@ def _ClassifyInclude(fileinfo, include, is_system):
49454938
_C_SYS_HEADER
49464939
>>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'string', True)
49474940
_CPP_SYS_HEADER
4948-
>>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'foo/foo.h', True)
4941+
>>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'foo/foo.h', True, "standardcfirst")
49494942
_OTHER_SYS_HEADER
49504943
>>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'foo/foo.h', False)
49514944
_LIKELY_MY_HEADER
@@ -4957,19 +4950,20 @@ def _ClassifyInclude(fileinfo, include, is_system):
49574950
"""
49584951
# This is a list of all standard c++ header files, except
49594952
# those already checked for above.
4960-
is_cpp_h = include in _CPP_HEADERS
4953+
is_cpp_header = include in _CPP_HEADERS
49614954

4962-
# Mark include as C header if in list or of type 'sys/*.h'.
4963-
is_c_h = include in _C_HEADERS or Search(r'sys\/.*\.h', include)
4955+
# Mark include as C header if in list or in a known folder for standard-ish C headers.
4956+
is_std_c_header = (include_order == "default") or (include in _C_HEADERS
4957+
# additional linux glibc header folders
4958+
or Search(r'(?:%s)\/.*\.h' % "|".join(C_STANDARD_HEADER_FOLDERS), include))
49644959

49654960
# Headers with C++ extensions shouldn't be considered C system headers
4966-
if is_system and os.path.splitext(include)[1] in ['.hpp', '.hxx', '.h++']:
4967-
is_system = False
4961+
is_system = used_angle_brackets and not os.path.splitext(include)[1] in ['.hpp', '.hxx', '.h++']
49684962

49694963
if is_system:
4970-
if is_cpp_h:
4964+
if is_cpp_header:
49714965
return _CPP_SYS_HEADER
4972-
if is_c_h:
4966+
if is_std_c_header:
49734967
return _C_SYS_HEADER
49744968
else:
49754969
return _OTHER_SYS_HEADER
@@ -5037,7 +5031,7 @@ def CheckIncludeLine(filename, clean_lines, linenum, include_state, error):
50375031
match = _RE_PATTERN_INCLUDE.search(line)
50385032
if match:
50395033
include = match.group(2)
5040-
is_system = (match.group(1) == '<')
5034+
used_angle_brackets = (match.group(1) == '<')
50415035
duplicate_line = include_state.FindHeader(include)
50425036
if duplicate_line >= 0:
50435037
error(filename, linenum, 'build/include', 4,
@@ -5068,17 +5062,18 @@ def CheckIncludeLine(filename, clean_lines, linenum, include_state, error):
50685062
include_state.include_list[-1].append((include, linenum))
50695063

50705064
# We want to ensure that headers appear in the right order:
5071-
# 1) for foo.cc, foo.h
5072-
# 2) other project headers
5073-
# 3) c system files
5074-
# 4) cpp system files
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
50755070
#
50765071
# We classify each include statement as one of those 5 types
50775072
# using a number of techniques. The include_state object keeps
50785073
# track of the highest type seen, and complains if we see a
50795074
# lower type after that.
50805075
error_message = include_state.CheckNextIncludeOrder(
5081-
_ClassifyInclude(fileinfo, include, is_system))
5076+
_ClassifyInclude(fileinfo, include, used_angle_brackets, _include_order))
50825077
if error_message:
50835078
error(filename, linenum, 'build/include_order', 4,
50845079
'%s. Should be: %s.h, c system, c++ system, other.' %
@@ -5334,7 +5329,7 @@ def CheckLanguage(filename, clean_lines, linenum, file_extension,
53345329
and line[-1] != '\\'):
53355330
error(filename, linenum, 'build/namespaces', 4,
53365331
'Do not use unnamed namespaces in header files. See '
5337-
'https://google.github.io/styleguide/cppguide.html#Namespaces'
5332+
'https://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Namespaces'
53385333
' for more information.')
53395334

53405335

@@ -6456,8 +6451,6 @@ def ProcessFileData(filename, file_extension, lines, error,
64566451

64576452
CheckForNewlineAtEOF(filename, lines, error)
64586453

6459-
CheckInlineHeader(filename, include_state, error)
6460-
64616454
def ProcessConfigOverrides(filename):
64626455
""" Loads the configuration files and processes the config overrides.
64636456
@@ -6476,7 +6469,7 @@ def ProcessConfigOverrides(filename):
64766469
if not base_name:
64776470
break # Reached the root directory.
64786471

6479-
cfg_file = os.path.join(abs_path, ".cpplint")
6472+
cfg_file = os.path.join(abs_path, "CPPLINT.cfg")
64806473
abs_filename = abs_path
64816474
if not os.path.isfile(cfg_file):
64826475
continue
@@ -6527,6 +6520,8 @@ def ProcessConfigOverrides(filename):
65276520
_root = os.path.join(os.path.dirname(cfg_file), val)
65286521
elif name == 'headers':
65296522
ProcessHppHeadersOption(val)
6523+
elif name == 'includeorder':
6524+
ProcessIncludeOrderOption(val)
65306525
else:
65316526
_cpplint_state.PrintError(
65326527
'Invalid configuration option (%s) in file %s\n' %
@@ -6693,6 +6688,7 @@ def ParseArguments(args):
66936688
'exclude=',
66946689
'recursive',
66956690
'headers=',
6691+
'includeorder=',
66966692
'quiet'])
66976693
except getopt.GetoptError:
66986694
PrintUsage('Invalid arguments.')
@@ -6749,6 +6745,8 @@ def ParseArguments(args):
67496745
ProcessHppHeadersOption(val)
67506746
elif opt == '--recursive':
67516747
recursive = True
6748+
elif opt == '--includeorder':
6749+
ProcessIncludeOrderOption(val)
67526750

67536751
if not filenames:
67546752
PrintUsage('No files were specified.')

0 commit comments

Comments
 (0)
Please sign in to comment.