Skip to content

Commit c730153

Browse files
TrottBethGriggs
authored andcommittedDec 15, 2020
tools: bump cpplint to 1.5.0
https://github.com/cpplint/cpplint/releases/tag/1.5.0 PR-URL: #35719 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Richard Lau <rlau@redhat.com>
1 parent dc589b5 commit c730153

File tree

1 file changed

+149
-114
lines changed

1 file changed

+149
-114
lines changed
 

‎tools/cpplint.py

+149-114
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.4.6'
62+
__VERSION__ = '1.5.0'
6363

6464
try:
6565
xrange # Python 2
@@ -280,7 +280,6 @@
280280
'build/include',
281281
'build/include_subdir',
282282
'build/include_alpha',
283-
'build/include_inline',
284283
'build/include_order',
285284
'build/include_what_you_use',
286285
'build/namespaces_literals',
@@ -295,13 +294,11 @@
295294
'readability/constructors',
296295
'readability/fn_size',
297296
'readability/inheritance',
298-
'readability/pointer_notation',
299297
'readability/multiline_comment',
300298
'readability/multiline_string',
301299
'readability/namespace',
302300
'readability/nolint',
303301
'readability/nul',
304-
'readability/null_usage',
305302
'readability/strings',
306303
'readability/todo',
307304
'readability/utf8',
@@ -321,7 +318,6 @@
321318
'runtime/string',
322319
'runtime/threadsafe_fn',
323320
'runtime/vlog',
324-
'runtime/v8_persistent',
325321
'whitespace/blank_line',
326322
'whitespace/braces',
327323
'whitespace/comma',
@@ -518,6 +514,120 @@
518514
'cwctype',
519515
])
520516

517+
# C headers
518+
_C_HEADERS = frozenset([
519+
# System C headers
520+
'assert.h',
521+
'complex.h',
522+
'ctype.h',
523+
'errno.h',
524+
'fenv.h',
525+
'float.h',
526+
'inttypes.h',
527+
'iso646.h',
528+
'limits.h',
529+
'locale.h',
530+
'math.h',
531+
'setjmp.h',
532+
'signal.h',
533+
'stdalign.h',
534+
'stdarg.h',
535+
'stdatomic.h',
536+
'stdbool.h',
537+
'stddef.h',
538+
'stdint.h',
539+
'stdio.h',
540+
'stdlib.h',
541+
'stdnoreturn.h',
542+
'string.h',
543+
'tgmath.h',
544+
'threads.h',
545+
'time.h',
546+
'uchar.h',
547+
'wchar.h',
548+
'wctype.h',
549+
# POSIX C headers
550+
'aio.h',
551+
'arpa/inet.h',
552+
'cpio.h',
553+
'dirent.h',
554+
'dlfcn.h',
555+
'fcntl.h',
556+
'fmtmsg.h',
557+
'fnmatch.h',
558+
'ftw.h',
559+
'glob.h',
560+
'grp.h',
561+
'iconv.h',
562+
'langinfo.h',
563+
'libgen.h',
564+
'monetary.h',
565+
'mqueue.h',
566+
'ndbm.h',
567+
'net/if.h',
568+
'netdb.h',
569+
'netinet/in.h',
570+
'netinet/tcp.h',
571+
'nl_types.h',
572+
'poll.h',
573+
'pthread.h',
574+
'pwd.h',
575+
'regex.h',
576+
'sched.h',
577+
'search.h',
578+
'semaphore.h',
579+
'setjmp.h',
580+
'signal.h',
581+
'spawn.h',
582+
'strings.h',
583+
'stropts.h',
584+
'syslog.h',
585+
'tar.h',
586+
'termios.h',
587+
'trace.h',
588+
'ulimit.h',
589+
'unistd.h',
590+
'utime.h',
591+
'utmpx.h',
592+
'wordexp.h',
593+
# GNUlib headers
594+
'a.out.h',
595+
'aliases.h',
596+
'alloca.h',
597+
'ar.h',
598+
'argp.h',
599+
'argz.h',
600+
'byteswap.h',
601+
'crypt.h',
602+
'endian.h',
603+
'envz.h',
604+
'err.h',
605+
'error.h',
606+
'execinfo.h',
607+
'fpu_control.h',
608+
'fstab.h',
609+
'fts.h',
610+
'getopt.h',
611+
'gshadow.h',
612+
'ieee754.h',
613+
'ifaddrs.h',
614+
'libintl.h',
615+
'mcheck.h',
616+
'mntent.h',
617+
'obstack.h',
618+
'paths.h',
619+
'printf.h',
620+
'pty.h',
621+
'resolv.h',
622+
'shadow.h',
623+
'sysexits.h',
624+
'ttyent.h',
625+
# Hardware specific headers
626+
'arm_neon.h',
627+
'emmintrin.h',
628+
'xmmintin.h',
629+
])
630+
521631
# Type names
522632
_TYPES = re.compile(
523633
r'^(?:'
@@ -604,9 +714,10 @@
604714
# _IncludeState.CheckNextIncludeOrder().
605715
_C_SYS_HEADER = 1
606716
_CPP_SYS_HEADER = 2
607-
_LIKELY_MY_HEADER = 3
608-
_POSSIBLE_MY_HEADER = 4
609-
_OTHER_HEADER = 5
717+
_OTHER_SYS_HEADER = 3
718+
_LIKELY_MY_HEADER = 4
719+
_POSSIBLE_MY_HEADER = 5
720+
_OTHER_HEADER = 6
610721

611722
# These constants define the current inline assembly state
612723
_NO_ASM = 0 # Outside of inline assembly block
@@ -626,14 +737,6 @@
626737
# Match string that indicates we're working on a Linux Kernel file.
627738
_SEARCH_KERNEL_FILE = re.compile(r'\b(?:LINT_KERNEL_FILE)')
628739

629-
_NULL_TOKEN_PATTERN = re.compile(r'\bNULL\b')
630-
631-
_V8_PERSISTENT_PATTERN = re.compile(r'\bv8::Persistent\b')
632-
633-
_RIGHT_LEANING_POINTER_PATTERN = re.compile(r'[^=|(,\s><);&?:}]'
634-
r'(?<!(sizeof|return))'
635-
r'\s\*[a-zA-Z_][0-9a-zA-Z_]*')
636-
637740
_regexp_compile_cache = {}
638741

639742
# {str, set(int)}: a map from error categories to sets of linenumbers
@@ -653,7 +756,7 @@
653756
# Files to exclude from linting. This is set by the --exclude flag.
654757
_excludes = None
655758

656-
# Whether to suppress PrintInfo messages
759+
# Whether to supress PrintInfo messages
657760
_quiet = False
658761

659762
# The allowed line length of files.
@@ -862,23 +965,26 @@ class _IncludeState(object):
862965
# needs to move backwards, CheckNextIncludeOrder will raise an error.
863966
_INITIAL_SECTION = 0
864967
_MY_H_SECTION = 1
865-
_OTHER_H_SECTION = 2
866-
_C_SECTION = 3
867-
_CPP_SECTION = 4
968+
_C_SECTION = 2
969+
_CPP_SECTION = 3
970+
_OTHER_SYS_SECTION = 4
971+
_OTHER_H_SECTION = 5
868972

869973
_TYPE_NAMES = {
870974
_C_SYS_HEADER: 'C system header',
871975
_CPP_SYS_HEADER: 'C++ system header',
976+
_OTHER_SYS_HEADER: 'other system header',
872977
_LIKELY_MY_HEADER: 'header this file implements',
873978
_POSSIBLE_MY_HEADER: 'header this file may implement',
874979
_OTHER_HEADER: 'other header',
875980
}
876981
_SECTION_NAMES = {
877982
_INITIAL_SECTION: "... nothing. (This can't be an error.)",
878983
_MY_H_SECTION: 'a header this file implements',
879-
_OTHER_H_SECTION: 'other header',
880984
_C_SECTION: 'C system header',
881985
_CPP_SECTION: 'C++ system header',
986+
_OTHER_SYS_SECTION: 'other system header',
987+
_OTHER_H_SECTION: 'other header',
882988
}
883989

884990
def __init__(self):
@@ -991,6 +1097,12 @@ def CheckNextIncludeOrder(self, header_type):
9911097
else:
9921098
self._last_header = ''
9931099
return error_message
1100+
elif header_type == _OTHER_SYS_HEADER:
1101+
if self._section <= self._OTHER_SYS_SECTION:
1102+
self._section = self._OTHER_SYS_SECTION
1103+
else:
1104+
self._last_header = ''
1105+
return error_message
9941106
elif header_type == _LIKELY_MY_HEADER:
9951107
if self._section <= self._MY_H_SECTION:
9961108
self._section = self._MY_H_SECTION
@@ -2274,21 +2386,6 @@ def CheckForBadCharacters(filename, lines, error):
22742386
error(filename, linenum, 'readability/nul', 5, 'Line contains NUL byte.')
22752387

22762388

2277-
def CheckInlineHeader(filename, include_state, error):
2278-
"""Logs an error if both a header and its inline variant are included."""
2279-
2280-
all_headers = dict(item for sublist in include_state.include_list
2281-
for item in sublist)
2282-
bad_headers = set('%s.h' % name[:-6] for name in all_headers.keys()
2283-
if name.endswith('-inl.h'))
2284-
bad_headers &= set(all_headers.keys())
2285-
2286-
for name in bad_headers:
2287-
err = '%s includes both %s and %s-inl.h' % (filename, name, name)
2288-
linenum = all_headers[name]
2289-
error(filename, linenum, 'build/include_inline', 5, err)
2290-
2291-
22922389
def CheckForNewlineAtEOF(filename, lines, error):
22932390
"""Logs an error if there is no newline char at the end of the file.
22942391
@@ -3312,7 +3409,7 @@ def CheckForFunctionLengths(filename, clean_lines, linenum,
33123409
"""Reports for long function bodies.
33133410
33143411
For an overview why this is done, see:
3315-
https://google.github.io/styleguide/cppguide.html#Write_Short_Functions
3412+
https://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Write_Short_Functions
33163413
33173414
Uses a simplistic algorithm assuming other style guidelines
33183415
(especially spacing) are followed.
@@ -4538,71 +4635,6 @@ def CheckAltTokens(filename, clean_lines, linenum, error):
45384635
'Use operator %s instead of %s' % (
45394636
_ALT_TOKEN_REPLACEMENT[match.group(1)], match.group(1)))
45404637

4541-
def CheckNullTokens(filename, clean_lines, linenum, error):
4542-
"""Check NULL usage.
4543-
4544-
Args:
4545-
filename: The name of the current file.
4546-
clean_lines: A CleansedLines instance containing the file.
4547-
linenum: The number of the line to check.
4548-
error: The function to call with any errors found.
4549-
"""
4550-
line = clean_lines.elided[linenum]
4551-
4552-
# Avoid preprocessor lines
4553-
if Match(r'^\s*#', line):
4554-
return
4555-
4556-
if line.find('/*') >= 0 or line.find('*/') >= 0:
4557-
return
4558-
4559-
for match in _NULL_TOKEN_PATTERN.finditer(line):
4560-
error(filename, linenum, 'readability/null_usage', 2,
4561-
'Use nullptr instead of NULL')
4562-
4563-
def CheckV8PersistentTokens(filename, clean_lines, linenum, error):
4564-
"""Check v8::Persistent usage.
4565-
4566-
Args:
4567-
filename: The name of the current file.
4568-
clean_lines: A CleansedLines instance containing the file.
4569-
linenum: The number of the line to check.
4570-
error: The function to call with any errors found.
4571-
"""
4572-
line = clean_lines.elided[linenum]
4573-
4574-
# Avoid preprocessor lines
4575-
if Match(r'^\s*#', line):
4576-
return
4577-
4578-
if line.find('/*') >= 0 or line.find('*/') >= 0:
4579-
return
4580-
4581-
for match in _V8_PERSISTENT_PATTERN.finditer(line):
4582-
error(filename, linenum, 'runtime/v8_persistent', 2,
4583-
'Use v8::Global instead of v8::Persistent')
4584-
4585-
def CheckLeftLeaningPointer(filename, clean_lines, linenum, error):
4586-
"""Check for left-leaning pointer placement.
4587-
4588-
Args:
4589-
filename: The name of the current file.
4590-
clean_lines: A CleansedLines instance containing the file.
4591-
linenum: The number of the line to check.
4592-
error: The function to call with any errors found.
4593-
"""
4594-
line = clean_lines.elided[linenum]
4595-
4596-
# Avoid preprocessor lines
4597-
if Match(r'^\s*#', line):
4598-
return
4599-
4600-
if '/*' in line or '*/' in line:
4601-
return
4602-
4603-
for match in _RIGHT_LEANING_POINTER_PATTERN.finditer(line):
4604-
error(filename, linenum, 'readability/pointer_notation', 2,
4605-
'Use left leaning pointer instead of right leaning')
46064638

46074639
def GetLineWidth(line):
46084640
"""Determines the width of the line in column positions.
@@ -4757,9 +4789,6 @@ def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state,
47574789
CheckSpacingForFunctionCall(filename, clean_lines, linenum, error)
47584790
CheckCheck(filename, clean_lines, linenum, error)
47594791
CheckAltTokens(filename, clean_lines, linenum, error)
4760-
CheckNullTokens(filename, clean_lines, linenum, error)
4761-
CheckV8PersistentTokens(filename, clean_lines, linenum, error)
4762-
CheckLeftLeaningPointer(filename, clean_lines, linenum, error)
47634792
classinfo = nesting_state.InnermostClass()
47644793
if classinfo:
47654794
CheckSectionSpacing(filename, clean_lines, classinfo, linenum, error)
@@ -4820,6 +4849,8 @@ def _ClassifyInclude(fileinfo, include, is_system):
48204849
_C_SYS_HEADER
48214850
>>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'string', True)
48224851
_CPP_SYS_HEADER
4852+
>>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'foo/foo.h', True)
4853+
_OTHER_SYS_HEADER
48234854
>>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'foo/foo.h', False)
48244855
_LIKELY_MY_HEADER
48254856
>>> _ClassifyInclude(FileInfo('foo/foo_unknown_extension.cc'),
@@ -4832,15 +4863,20 @@ def _ClassifyInclude(fileinfo, include, is_system):
48324863
# those already checked for above.
48334864
is_cpp_h = include in _CPP_HEADERS
48344865

4866+
# Mark include as C header if in list or of type 'sys/*.h'.
4867+
is_c_h = include in _C_HEADERS or Search(r'sys\/.*\.h', include)
4868+
48354869
# Headers with C++ extensions shouldn't be considered C system headers
48364870
if is_system and os.path.splitext(include)[1] in ['.hpp', '.hxx', '.h++']:
48374871
is_system = False
48384872

48394873
if is_system:
48404874
if is_cpp_h:
48414875
return _CPP_SYS_HEADER
4842-
else:
4876+
if is_c_h:
48434877
return _C_SYS_HEADER
4878+
else:
4879+
return _OTHER_SYS_HEADER
48444880

48454881
# If the target file and the include we're checking share a
48464882
# basename when we drop common extensions, and the include
@@ -4936,10 +4972,11 @@ def CheckIncludeLine(filename, clean_lines, linenum, include_state, error):
49364972
include_state.include_list[-1].append((include, linenum))
49374973

49384974
# We want to ensure that headers appear in the right order:
4939-
# 1) for foo.cc, foo.h
4940-
# 2) other project headers
4941-
# 3) c system files
4942-
# 4) cpp system files
4975+
# 1) for foo.cc, foo.h (preferred location)
4976+
# 2) c system files
4977+
# 3) cpp system files
4978+
# 4) for foo.cc, foo.h (deprecated location)
4979+
# 5) other google headers
49434980
#
49444981
# We classify each include statement as one of those 5 types
49454982
# using a number of techniques. The include_state object keeps
@@ -5202,7 +5239,7 @@ def CheckLanguage(filename, clean_lines, linenum, file_extension,
52025239
and line[-1] != '\\'):
52035240
error(filename, linenum, 'build/namespaces', 4,
52045241
'Do not use unnamed namespaces in header files. See '
5205-
'https://google.github.io/styleguide/cppguide.html#Namespaces'
5242+
'https://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Namespaces'
52065243
' for more information.')
52075244

52085245

@@ -6324,8 +6361,6 @@ def ProcessFileData(filename, file_extension, lines, error,
63246361

63256362
CheckForNewlineAtEOF(filename, lines, error)
63266363

6327-
CheckInlineHeader(filename, include_state, error)
6328-
63296364
def ProcessConfigOverrides(filename):
63306365
""" Loads the configuration files and processes the config overrides.
63316366
@@ -6344,7 +6379,7 @@ def ProcessConfigOverrides(filename):
63446379
if not base_name:
63456380
break # Reached the root directory.
63466381

6347-
cfg_file = os.path.join(abs_path, ".cpplint")
6382+
cfg_file = os.path.join(abs_path, "CPPLINT.cfg")
63486383
abs_filename = abs_path
63496384
if not os.path.isfile(cfg_file):
63506385
continue

0 commit comments

Comments
 (0)
Please sign in to comment.