mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
tools: bump cpplint to 1.5.1
https://github.com/cpplint/cpplint/releases/tag/1.5.1 PR-URL: https://github.com/nodejs/node/pull/35866 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Richard Lau <rlau@redhat.com>
This commit is contained in:
parent
dfc288e7fd
commit
c61306df36
1 changed files with 123 additions and 125 deletions
248
tools/cpplint.py
vendored
248
tools/cpplint.py
vendored
|
@ -59,7 +59,7 @@ import xml.etree.ElementTree
|
|||
# if empty, use defaults
|
||||
_valid_extensions = set([])
|
||||
|
||||
__VERSION__ = '1.5.0'
|
||||
__VERSION__ = '1.5.1'
|
||||
|
||||
try:
|
||||
xrange # Python 2
|
||||
|
@ -77,6 +77,7 @@ Syntax: cpplint.py [--verbose=#] [--output=emacs|eclipse|vs7|junit]
|
|||
[--recursive]
|
||||
[--exclude=path]
|
||||
[--extensions=hpp,cpp,...]
|
||||
[--includeorder=default|standardcfirst]
|
||||
[--quiet]
|
||||
[--version]
|
||||
<file> [file] ...
|
||||
|
@ -209,6 +210,15 @@ Syntax: cpplint.py [--verbose=#] [--output=emacs|eclipse|vs7|junit]
|
|||
Examples:
|
||||
--extensions=%s
|
||||
|
||||
includeorder=default|standardcfirst
|
||||
For the build/include_order rule, the default is to blindly assume angle
|
||||
bracket includes with file extension are c-system-headers (default),
|
||||
even knowing this will have false classifications.
|
||||
The default is established at google.
|
||||
standardcfirst means to instead use an allow-list of known c headers and
|
||||
treat all others as separate group of "other system headers". The C headers
|
||||
included are those of the C-standard lib and closely related ones.
|
||||
|
||||
headers=x,y,...
|
||||
The header extensions that cpplint will treat as .h in checks. Values are
|
||||
automatically added to --extensions list.
|
||||
|
@ -280,7 +290,6 @@ _ERROR_CATEGORIES = [
|
|||
'build/include',
|
||||
'build/include_subdir',
|
||||
'build/include_alpha',
|
||||
'build/include_inline',
|
||||
'build/include_order',
|
||||
'build/include_what_you_use',
|
||||
'build/namespaces_literals',
|
||||
|
@ -295,13 +304,11 @@ _ERROR_CATEGORIES = [
|
|||
'readability/constructors',
|
||||
'readability/fn_size',
|
||||
'readability/inheritance',
|
||||
'readability/pointer_notation',
|
||||
'readability/multiline_comment',
|
||||
'readability/multiline_string',
|
||||
'readability/namespace',
|
||||
'readability/nolint',
|
||||
'readability/nul',
|
||||
'readability/null_usage',
|
||||
'readability/strings',
|
||||
'readability/todo',
|
||||
'readability/utf8',
|
||||
|
@ -321,7 +328,6 @@ _ERROR_CATEGORIES = [
|
|||
'runtime/string',
|
||||
'runtime/threadsafe_fn',
|
||||
'runtime/vlog',
|
||||
'runtime/v8_persistent',
|
||||
'whitespace/blank_line',
|
||||
'whitespace/braces',
|
||||
'whitespace/comma',
|
||||
|
@ -550,7 +556,7 @@ _C_HEADERS = frozenset([
|
|||
'uchar.h',
|
||||
'wchar.h',
|
||||
'wctype.h',
|
||||
# POSIX C headers
|
||||
# additional POSIX C headers
|
||||
'aio.h',
|
||||
'arpa/inet.h',
|
||||
'cpio.h',
|
||||
|
@ -594,7 +600,7 @@ _C_HEADERS = frozenset([
|
|||
'utime.h',
|
||||
'utmpx.h',
|
||||
'wordexp.h',
|
||||
# GNUlib headers
|
||||
# additional GNUlib headers
|
||||
'a.out.h',
|
||||
'aliases.h',
|
||||
'alloca.h',
|
||||
|
@ -626,12 +632,78 @@ _C_HEADERS = frozenset([
|
|||
'shadow.h',
|
||||
'sysexits.h',
|
||||
'ttyent.h',
|
||||
# Additional linux glibc headers
|
||||
'dlfcn.h',
|
||||
'elf.h',
|
||||
'features.h',
|
||||
'gconv.h',
|
||||
'gnu-versions.h',
|
||||
'lastlog.h',
|
||||
'libio.h',
|
||||
'link.h',
|
||||
'malloc.h',
|
||||
'memory.h',
|
||||
'netash/ash.h',
|
||||
'netatalk/at.h',
|
||||
'netax25/ax25.h',
|
||||
'neteconet/ec.h',
|
||||
'netipx/ipx.h',
|
||||
'netiucv/iucv.h',
|
||||
'netpacket/packet.h',
|
||||
'netrom/netrom.h',
|
||||
'netrose/rose.h',
|
||||
'nfs/nfs.h',
|
||||
'nl_types.h',
|
||||
'nss.h',
|
||||
're_comp.h',
|
||||
'regexp.h',
|
||||
'sched.h',
|
||||
'sgtty.h',
|
||||
'stab.h',
|
||||
'stdc-predef.h',
|
||||
'stdio_ext.h',
|
||||
'syscall.h',
|
||||
'termio.h',
|
||||
'thread_db.h',
|
||||
'ucontext.h',
|
||||
'ustat.h',
|
||||
'utmp.h',
|
||||
'values.h',
|
||||
'wait.h',
|
||||
'xlocale.h',
|
||||
# Hardware specific headers
|
||||
'arm_neon.h',
|
||||
'emmintrin.h',
|
||||
'xmmintin.h',
|
||||
])
|
||||
|
||||
# Folders of C libraries so commonly used in C++,
|
||||
# that they have parity with standard C libraries.
|
||||
C_STANDARD_HEADER_FOLDERS = frozenset([
|
||||
# standard C library
|
||||
"sys",
|
||||
# glibc for linux
|
||||
"arpa",
|
||||
"asm-generic",
|
||||
"bits",
|
||||
"gnu",
|
||||
"net",
|
||||
"netinet",
|
||||
"protocols",
|
||||
"rpc",
|
||||
"rpcsvc",
|
||||
"scsi",
|
||||
# linux kernel header
|
||||
"drm",
|
||||
"linux",
|
||||
"misc",
|
||||
"mtd",
|
||||
"rdma",
|
||||
"sound",
|
||||
"video",
|
||||
"xen",
|
||||
])
|
||||
|
||||
# Type names
|
||||
_TYPES = re.compile(
|
||||
r'^(?:'
|
||||
|
@ -741,14 +813,6 @@ _SEARCH_C_FILE = re.compile(r'\b(?:LINT_C_FILE|'
|
|||
# Match string that indicates we're working on a Linux Kernel file.
|
||||
_SEARCH_KERNEL_FILE = re.compile(r'\b(?:LINT_KERNEL_FILE)')
|
||||
|
||||
_NULL_TOKEN_PATTERN = re.compile(r'\bNULL\b')
|
||||
|
||||
_V8_PERSISTENT_PATTERN = re.compile(r'\bv8::Persistent\b')
|
||||
|
||||
_RIGHT_LEANING_POINTER_PATTERN = re.compile(r'[^=|(,\s><);&?:}]'
|
||||
r'(?<!(sizeof|return))'
|
||||
r'\s\*[a-zA-Z_][0-9a-zA-Z_]*')
|
||||
|
||||
_regexp_compile_cache = {}
|
||||
|
||||
# {str, set(int)}: a map from error categories to sets of linenumbers
|
||||
|
@ -768,13 +832,16 @@ _repository = None
|
|||
# Files to exclude from linting. This is set by the --exclude flag.
|
||||
_excludes = None
|
||||
|
||||
# Whether to suppress PrintInfo messages
|
||||
# Whether to supress PrintInfo messages
|
||||
_quiet = False
|
||||
|
||||
# The allowed line length of files.
|
||||
# This is set by --linelength flag.
|
||||
_line_length = 80
|
||||
|
||||
# This allows to use different include order rule than default
|
||||
_include_order = "default"
|
||||
|
||||
try:
|
||||
unicode
|
||||
except NameError:
|
||||
|
@ -818,6 +885,15 @@ def ProcessHppHeadersOption(val):
|
|||
except ValueError:
|
||||
PrintUsage('Header extensions must be comma separated list.')
|
||||
|
||||
def ProcessIncludeOrderOption(val):
|
||||
if val is None or val == "default":
|
||||
pass
|
||||
elif val == "standardcfirst":
|
||||
global _include_order
|
||||
_include_order = val
|
||||
else:
|
||||
PrintUsage('Invalid includeorder value %s. Expected default|standardcfirst')
|
||||
|
||||
def IsHeaderExtension(file_extension):
|
||||
return file_extension in GetHeaderExtensions()
|
||||
|
||||
|
@ -977,11 +1053,10 @@ class _IncludeState(object):
|
|||
# needs to move backwards, CheckNextIncludeOrder will raise an error.
|
||||
_INITIAL_SECTION = 0
|
||||
_MY_H_SECTION = 1
|
||||
_OTHER_H_SECTION = 2
|
||||
_OTHER_SYS_SECTION = 3
|
||||
_C_SECTION = 4
|
||||
_CPP_SECTION = 5
|
||||
|
||||
_C_SECTION = 2
|
||||
_CPP_SECTION = 3
|
||||
_OTHER_SYS_SECTION = 4
|
||||
_OTHER_H_SECTION = 5
|
||||
|
||||
_TYPE_NAMES = {
|
||||
_C_SYS_HEADER: 'C system header',
|
||||
|
@ -2399,21 +2474,6 @@ def CheckForBadCharacters(filename, lines, error):
|
|||
error(filename, linenum, 'readability/nul', 5, 'Line contains NUL byte.')
|
||||
|
||||
|
||||
def CheckInlineHeader(filename, include_state, error):
|
||||
"""Logs an error if both a header and its inline variant are included."""
|
||||
|
||||
all_headers = dict(item for sublist in include_state.include_list
|
||||
for item in sublist)
|
||||
bad_headers = set('%s.h' % name[:-6] for name in all_headers.keys()
|
||||
if name.endswith('-inl.h'))
|
||||
bad_headers &= set(all_headers.keys())
|
||||
|
||||
for name in bad_headers:
|
||||
err = '%s includes both %s and %s-inl.h' % (filename, name, name)
|
||||
linenum = all_headers[name]
|
||||
error(filename, linenum, 'build/include_inline', 5, err)
|
||||
|
||||
|
||||
def CheckForNewlineAtEOF(filename, lines, error):
|
||||
"""Logs an error if there is no newline char at the end of the file.
|
||||
|
||||
|
@ -3437,7 +3497,7 @@ def CheckForFunctionLengths(filename, clean_lines, linenum,
|
|||
"""Reports for long function bodies.
|
||||
|
||||
For an overview why this is done, see:
|
||||
https://google.github.io/styleguide/cppguide.html#Write_Short_Functions
|
||||
https://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Write_Short_Functions
|
||||
|
||||
Uses a simplistic algorithm assuming other style guidelines
|
||||
(especially spacing) are followed.
|
||||
|
@ -4663,71 +4723,6 @@ def CheckAltTokens(filename, clean_lines, linenum, error):
|
|||
'Use operator %s instead of %s' % (
|
||||
_ALT_TOKEN_REPLACEMENT[match.group(1)], match.group(1)))
|
||||
|
||||
def CheckNullTokens(filename, clean_lines, linenum, error):
|
||||
"""Check NULL usage.
|
||||
|
||||
Args:
|
||||
filename: The name of the current file.
|
||||
clean_lines: A CleansedLines instance containing the file.
|
||||
linenum: The number of the line to check.
|
||||
error: The function to call with any errors found.
|
||||
"""
|
||||
line = clean_lines.elided[linenum]
|
||||
|
||||
# Avoid preprocessor lines
|
||||
if Match(r'^\s*#', line):
|
||||
return
|
||||
|
||||
if line.find('/*') >= 0 or line.find('*/') >= 0:
|
||||
return
|
||||
|
||||
for match in _NULL_TOKEN_PATTERN.finditer(line):
|
||||
error(filename, linenum, 'readability/null_usage', 2,
|
||||
'Use nullptr instead of NULL')
|
||||
|
||||
def CheckV8PersistentTokens(filename, clean_lines, linenum, error):
|
||||
"""Check v8::Persistent usage.
|
||||
|
||||
Args:
|
||||
filename: The name of the current file.
|
||||
clean_lines: A CleansedLines instance containing the file.
|
||||
linenum: The number of the line to check.
|
||||
error: The function to call with any errors found.
|
||||
"""
|
||||
line = clean_lines.elided[linenum]
|
||||
|
||||
# Avoid preprocessor lines
|
||||
if Match(r'^\s*#', line):
|
||||
return
|
||||
|
||||
if line.find('/*') >= 0 or line.find('*/') >= 0:
|
||||
return
|
||||
|
||||
for match in _V8_PERSISTENT_PATTERN.finditer(line):
|
||||
error(filename, linenum, 'runtime/v8_persistent', 2,
|
||||
'Use v8::Global instead of v8::Persistent')
|
||||
|
||||
def CheckLeftLeaningPointer(filename, clean_lines, linenum, error):
|
||||
"""Check for left-leaning pointer placement.
|
||||
|
||||
Args:
|
||||
filename: The name of the current file.
|
||||
clean_lines: A CleansedLines instance containing the file.
|
||||
linenum: The number of the line to check.
|
||||
error: The function to call with any errors found.
|
||||
"""
|
||||
line = clean_lines.elided[linenum]
|
||||
|
||||
# Avoid preprocessor lines
|
||||
if Match(r'^\s*#', line):
|
||||
return
|
||||
|
||||
if '/*' in line or '*/' in line:
|
||||
return
|
||||
|
||||
for match in _RIGHT_LEANING_POINTER_PATTERN.finditer(line):
|
||||
error(filename, linenum, 'readability/pointer_notation', 2,
|
||||
'Use left leaning pointer instead of right leaning')
|
||||
|
||||
def GetLineWidth(line):
|
||||
"""Determines the width of the line in column positions.
|
||||
|
@ -4882,9 +4877,6 @@ def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state,
|
|||
CheckSpacingForFunctionCall(filename, clean_lines, linenum, error)
|
||||
CheckCheck(filename, clean_lines, linenum, error)
|
||||
CheckAltTokens(filename, clean_lines, linenum, error)
|
||||
CheckNullTokens(filename, clean_lines, linenum, error)
|
||||
CheckV8PersistentTokens(filename, clean_lines, linenum, error)
|
||||
CheckLeftLeaningPointer(filename, clean_lines, linenum, error)
|
||||
classinfo = nesting_state.InnermostClass()
|
||||
if classinfo:
|
||||
CheckSectionSpacing(filename, clean_lines, classinfo, linenum, error)
|
||||
|
@ -4929,13 +4921,14 @@ def _DropCommonSuffixes(filename):
|
|||
return os.path.splitext(filename)[0]
|
||||
|
||||
|
||||
def _ClassifyInclude(fileinfo, include, is_system):
|
||||
def _ClassifyInclude(fileinfo, include, used_angle_brackets, include_order="default"):
|
||||
"""Figures out what kind of header 'include' is.
|
||||
|
||||
Args:
|
||||
fileinfo: The current file cpplint is running over. A FileInfo instance.
|
||||
include: The path to a #included file.
|
||||
is_system: True if the #include used <> rather than "".
|
||||
used_angle_brackets: True if the #include used <> rather than "".
|
||||
include_order: "default" or other value allowed in program arguments
|
||||
|
||||
Returns:
|
||||
One of the _XXX_HEADER constants.
|
||||
|
@ -4945,7 +4938,7 @@ def _ClassifyInclude(fileinfo, include, is_system):
|
|||
_C_SYS_HEADER
|
||||
>>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'string', True)
|
||||
_CPP_SYS_HEADER
|
||||
>>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'foo/foo.h', True)
|
||||
>>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'foo/foo.h', True, "standardcfirst")
|
||||
_OTHER_SYS_HEADER
|
||||
>>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'foo/foo.h', False)
|
||||
_LIKELY_MY_HEADER
|
||||
|
@ -4957,19 +4950,20 @@ def _ClassifyInclude(fileinfo, include, is_system):
|
|||
"""
|
||||
# This is a list of all standard c++ header files, except
|
||||
# those already checked for above.
|
||||
is_cpp_h = include in _CPP_HEADERS
|
||||
is_cpp_header = include in _CPP_HEADERS
|
||||
|
||||
# Mark include as C header if in list or of type 'sys/*.h'.
|
||||
is_c_h = include in _C_HEADERS or Search(r'sys\/.*\.h', include)
|
||||
# Mark include as C header if in list or in a known folder for standard-ish C headers.
|
||||
is_std_c_header = (include_order == "default") or (include in _C_HEADERS
|
||||
# additional linux glibc header folders
|
||||
or Search(r'(?:%s)\/.*\.h' % "|".join(C_STANDARD_HEADER_FOLDERS), include))
|
||||
|
||||
# Headers with C++ extensions shouldn't be considered C system headers
|
||||
if is_system and os.path.splitext(include)[1] in ['.hpp', '.hxx', '.h++']:
|
||||
is_system = False
|
||||
is_system = used_angle_brackets and not os.path.splitext(include)[1] in ['.hpp', '.hxx', '.h++']
|
||||
|
||||
if is_system:
|
||||
if is_cpp_h:
|
||||
if is_cpp_header:
|
||||
return _CPP_SYS_HEADER
|
||||
if is_c_h:
|
||||
if is_std_c_header:
|
||||
return _C_SYS_HEADER
|
||||
else:
|
||||
return _OTHER_SYS_HEADER
|
||||
|
@ -5037,7 +5031,7 @@ def CheckIncludeLine(filename, clean_lines, linenum, include_state, error):
|
|||
match = _RE_PATTERN_INCLUDE.search(line)
|
||||
if match:
|
||||
include = match.group(2)
|
||||
is_system = (match.group(1) == '<')
|
||||
used_angle_brackets = (match.group(1) == '<')
|
||||
duplicate_line = include_state.FindHeader(include)
|
||||
if duplicate_line >= 0:
|
||||
error(filename, linenum, 'build/include', 4,
|
||||
|
@ -5068,17 +5062,18 @@ def CheckIncludeLine(filename, clean_lines, linenum, include_state, error):
|
|||
include_state.include_list[-1].append((include, linenum))
|
||||
|
||||
# We want to ensure that headers appear in the right order:
|
||||
# 1) for foo.cc, foo.h
|
||||
# 2) other project headers
|
||||
# 3) c system files
|
||||
# 4) cpp system files
|
||||
# 1) for foo.cc, foo.h (preferred location)
|
||||
# 2) c system files
|
||||
# 3) cpp system files
|
||||
# 4) for foo.cc, foo.h (deprecated location)
|
||||
# 5) other google headers
|
||||
#
|
||||
# We classify each include statement as one of those 5 types
|
||||
# using a number of techniques. The include_state object keeps
|
||||
# track of the highest type seen, and complains if we see a
|
||||
# lower type after that.
|
||||
error_message = include_state.CheckNextIncludeOrder(
|
||||
_ClassifyInclude(fileinfo, include, is_system))
|
||||
_ClassifyInclude(fileinfo, include, used_angle_brackets, _include_order))
|
||||
if error_message:
|
||||
error(filename, linenum, 'build/include_order', 4,
|
||||
'%s. Should be: %s.h, c system, c++ system, other.' %
|
||||
|
@ -5334,7 +5329,7 @@ def CheckLanguage(filename, clean_lines, linenum, file_extension,
|
|||
and line[-1] != '\\'):
|
||||
error(filename, linenum, 'build/namespaces', 4,
|
||||
'Do not use unnamed namespaces in header files. See '
|
||||
'https://google.github.io/styleguide/cppguide.html#Namespaces'
|
||||
'https://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Namespaces'
|
||||
' for more information.')
|
||||
|
||||
|
||||
|
@ -6456,8 +6451,6 @@ def ProcessFileData(filename, file_extension, lines, error,
|
|||
|
||||
CheckForNewlineAtEOF(filename, lines, error)
|
||||
|
||||
CheckInlineHeader(filename, include_state, error)
|
||||
|
||||
def ProcessConfigOverrides(filename):
|
||||
""" Loads the configuration files and processes the config overrides.
|
||||
|
||||
|
@ -6476,7 +6469,7 @@ def ProcessConfigOverrides(filename):
|
|||
if not base_name:
|
||||
break # Reached the root directory.
|
||||
|
||||
cfg_file = os.path.join(abs_path, ".cpplint")
|
||||
cfg_file = os.path.join(abs_path, "CPPLINT.cfg")
|
||||
abs_filename = abs_path
|
||||
if not os.path.isfile(cfg_file):
|
||||
continue
|
||||
|
@ -6527,6 +6520,8 @@ def ProcessConfigOverrides(filename):
|
|||
_root = os.path.join(os.path.dirname(cfg_file), val)
|
||||
elif name == 'headers':
|
||||
ProcessHppHeadersOption(val)
|
||||
elif name == 'includeorder':
|
||||
ProcessIncludeOrderOption(val)
|
||||
else:
|
||||
_cpplint_state.PrintError(
|
||||
'Invalid configuration option (%s) in file %s\n' %
|
||||
|
@ -6693,6 +6688,7 @@ def ParseArguments(args):
|
|||
'exclude=',
|
||||
'recursive',
|
||||
'headers=',
|
||||
'includeorder=',
|
||||
'quiet'])
|
||||
except getopt.GetoptError:
|
||||
PrintUsage('Invalid arguments.')
|
||||
|
@ -6749,6 +6745,8 @@ def ParseArguments(args):
|
|||
ProcessHppHeadersOption(val)
|
||||
elif opt == '--recursive':
|
||||
recursive = True
|
||||
elif opt == '--includeorder':
|
||||
ProcessIncludeOrderOption(val)
|
||||
|
||||
if not filenames:
|
||||
PrintUsage('No files were specified.')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue