Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools: update cpplint to 1.6.1 #48098

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 44 additions & 14 deletions tools/cpplint.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@
# if empty, use defaults
_valid_extensions = set([])

__VERSION__ = '1.6.0'
__VERSION__ = '1.6.1'

try:
# -- pylint: disable=used-before-assignment
xrange # Python 2
except NameError:
# -- pylint: disable=redefined-builtin
Expand Down Expand Up @@ -97,9 +98,10 @@
certain of the problem, and 1 meaning it could be a legitimate construct.
This will miss some errors, and is not a substitute for a code review.

To suppress false-positive errors of a certain category, add a
'NOLINT(category)' comment to the line. NOLINT or NOLINT(*)
suppresses errors of all categories on that line.
To suppress false-positive errors of certain categories, add a
'NOLINT(category[, category...])' comment to the line. NOLINT or NOLINT(*)
suppresses errors of all categories on that line. To suppress categories
on the next line use NOLINTNEXTLINE instead of NOLINT.

The files passed in will be linted; at least one file must be provided.
Default linted extensions are %s.
Expand Down Expand Up @@ -377,6 +379,12 @@
'readability/function',
]

# These prefixes for categories should be ignored since they relate to other
# tools which also use the NOLINT syntax, e.g. clang-tidy.
_OTHER_NOLINT_CATEGORY_PREFIXES = [
'clang-analyzer',
]

# The default state of the category filter. This is overridden by the --filter=
# flag. By default all errors are on, so only add here categories that should be
# off by default (i.e., categories that must be enabled by the --filter= flags).
Expand Down Expand Up @@ -405,7 +413,7 @@
'alloc.h',
'builtinbuf.h',
'bvector.h',
'complex.h',
# 'complex.h', collides with System C header "complex.h"
'defalloc.h',
'deque.h',
'editbuf.h',
Expand Down Expand Up @@ -517,6 +525,22 @@
'optional',
'string_view',
'variant',
# 17.6.1.2 C++20 headers
'barrier',
'bit',
'compare',
'concepts',
'coroutine',
'format',
'latch'
'numbers',
'ranges',
'semaphore',
'source_location',
'span',
'stop_token',
'syncstream',
'version',
# 17.6.1.2 C++ headers for C library facilities
'cassert',
'ccomplex',
Expand Down Expand Up @@ -889,12 +913,14 @@
_include_order = "default"

try:
# -- pylint: disable=used-before-assignment
unicode
except NameError:
# -- pylint: disable=redefined-builtin
basestring = unicode = str

try:
# -- pylint: disable=used-before-assignment
long
except NameError:
# -- pylint: disable=redefined-builtin
Expand Down Expand Up @@ -988,14 +1014,16 @@ def ParseNolintSuppressions(filename, raw_line, linenum, error):
suppressed_line = linenum + 1
else:
suppressed_line = linenum
category = matched.group(2)
if category in (None, '(*)'): # => "suppress all"
categories = matched.group(2)
if categories in (None, '(*)'): # => "suppress all"
_error_suppressions.setdefault(None, set()).add(suppressed_line)
else:
if category.startswith('(') and category.endswith(')'):
category = category[1:-1]
elif categories.startswith('(') and categories.endswith(')'):
for category in set(map(lambda c: c.strip(), categories[1:-1].split(','))):
if category in _ERROR_CATEGORIES:
_error_suppressions.setdefault(category, set()).add(suppressed_line)
elif any(c for c in _OTHER_NOLINT_CATEGORY_PREFIXES if category.startswith(c)):
# Ignore any categories from other tools.
pass
elif category not in _LEGACY_ERROR_CATEGORIES:
error(filename, linenum, 'readability/nolint', 5,
'Unknown NOLINT error category: %s' % category)
Expand Down Expand Up @@ -5108,7 +5136,8 @@ def _ClassifyInclude(fileinfo, include, used_angle_brackets, include_order="defa
or Search(r'(?:%s)\/.*\.h' % "|".join(C_STANDARD_HEADER_FOLDERS), include))

# Headers with C++ extensions shouldn't be considered C system headers
is_system = used_angle_brackets and not os.path.splitext(include)[1] in ['.hpp', '.hxx', '.h++']
include_ext = os.path.splitext(include)[1]
is_system = used_angle_brackets and not include_ext in ['.hh', '.hpp', '.hxx', '.h++']

if is_system:
if is_cpp_header:
Expand Down Expand Up @@ -5183,7 +5212,7 @@ def CheckIncludeLine(filename, clean_lines, linenum, include_state, error):
match = _RE_PATTERN_INCLUDE.search(line)
if match:
include = match.group(2)
used_angle_brackets = (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,
Expand Down Expand Up @@ -5947,7 +5976,8 @@ def CheckCStyleCast(filename, clean_lines, linenum, cast_type, pattern, error):
return False

# operator++(int) and operator--(int)
if context.endswith(' operator++') or context.endswith(' operator--'):
if (context.endswith(' operator++') or context.endswith(' operator--') or
context.endswith('::operator++') or context.endswith('::operator--')):
return False

# A single unnamed argument for a function tends to look like old style cast.
Expand Down Expand Up @@ -6628,7 +6658,7 @@ def ProcessConfigOverrides(filename):
continue

try:
with open(cfg_file, encoding='utf-8') as file_handle:
with codecs.open(cfg_file, 'r', 'utf8', 'replace') as file_handle:
for line in file_handle:
line, _, _ = line.partition('#') # Remove comments.
if not line.strip():
Expand Down