Remove blacklist/whitelist from cpplint.py

This commit is contained in:
Neal Richardson 2020-06-19 13:27:01 -07:00 committed by GitHub
parent b448694ab3
commit 08268efb06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

20
cpplint/cpplint.py vendored
View File

@ -3866,9 +3866,9 @@ def CheckTrailingSemicolon(filename, clean_lines, linenum, error):
# Block bodies should not be followed by a semicolon. Due to C++11 # Block bodies should not be followed by a semicolon. Due to C++11
# brace initialization, there are more places where semicolons are # brace initialization, there are more places where semicolons are
# required than not, so we use a whitelist approach to check these # required than not, so we explicitly list the allowed rules rather
# rather than a blacklist. These are the places where "};" should # than listing the disallowed ones. These are the places where "};"
# be replaced by just "}": # should be replaced by just "}":
# 1. Some flavor of block following closing parenthesis: # 1. Some flavor of block following closing parenthesis:
# for (;;) {}; # for (;;) {};
# while (...) {}; # while (...) {};
@ -3924,11 +3924,11 @@ def CheckTrailingSemicolon(filename, clean_lines, linenum, error):
# - INTERFACE_DEF # - INTERFACE_DEF
# - EXCLUSIVE_LOCKS_REQUIRED, SHARED_LOCKS_REQUIRED, LOCKS_EXCLUDED: # - EXCLUSIVE_LOCKS_REQUIRED, SHARED_LOCKS_REQUIRED, LOCKS_EXCLUDED:
# #
# We implement a whitelist of safe macros instead of a blacklist of # We implement a list of safe macros instead of a list of
# unsafe macros, even though the latter appears less frequently in # unsafe macros, even though the latter appears less frequently in
# google code and would have been easier to implement. This is because # google code and would have been easier to implement. This is because
# the downside for getting the whitelist wrong means some extra # the downside for getting the allowed checks wrong means some extra
# semicolons, while the downside for getting the blacklist wrong # semicolons, while the downside for getting disallowed checks wrong
# would result in compile errors. # would result in compile errors.
# #
# In addition to macros, we also don't want to warn on # In addition to macros, we also don't want to warn on
@ -5124,19 +5124,19 @@ def CheckForNonConstReference(filename, clean_lines, linenum,
# #
# We also accept & in static_assert, which looks like a function but # We also accept & in static_assert, which looks like a function but
# it's actually a declaration expression. # it's actually a declaration expression.
whitelisted_functions = (r'(?:[sS]wap(?:<\w:+>)?|' allowed_functions = (r'(?:[sS]wap(?:<\w:+>)?|'
r'operator\s*[<>][<>]|' r'operator\s*[<>][<>]|'
r'static_assert|COMPILE_ASSERT' r'static_assert|COMPILE_ASSERT'
r')\s*\(') r')\s*\(')
if Search(whitelisted_functions, line): if Search(allowed_functions, line):
return return
elif not Search(r'\S+\([^)]*$', line): elif not Search(r'\S+\([^)]*$', line):
# Don't see a whitelisted function on this line. Actually we # Don't see an allowed function on this line. Actually we
# didn't see any function name on this line, so this is likely a # didn't see any function name on this line, so this is likely a
# multi-line parameter list. Try a bit harder to catch this case. # multi-line parameter list. Try a bit harder to catch this case.
for i in xrange(2): for i in xrange(2):
if (linenum > i and if (linenum > i and
Search(whitelisted_functions, clean_lines.elided[linenum - i - 1])): Search(allowed_functions, clean_lines.elided[linenum - i - 1])):
return return
decls = ReplaceAll(r'{[^}]*}', ' ', line) # exclude function body decls = ReplaceAll(r'{[^}]*}', ' ', line) # exclude function body