Skip to content

Commit 1f850c0

Browse files
Trottjuanarbol
authored andcommitted
tools: bump cpplint to 1.6.0
PR-URL: #42416 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Mestery <mestery@protonmail.com> Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
1 parent 67ea8e2 commit 1f850c0

File tree

1 file changed

+26
-115
lines changed

1 file changed

+26
-115
lines changed

tools/cpplint.py

+26-115
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@
4141
same line, but it is far from perfect (in either direction).
4242
"""
4343

44+
# cpplint predates fstrings
45+
# pylint: disable=consider-using-f-string
46+
47+
# pylint: disable=invalid-name
48+
4449
import codecs
4550
import copy
4651
import getopt
@@ -59,7 +64,7 @@
5964
# if empty, use defaults
6065
_valid_extensions = set([])
6166

62-
__VERSION__ = '1.5.5'
67+
__VERSION__ = '1.6.0'
6368

6469
try:
6570
xrange # Python 2
@@ -295,7 +300,6 @@
295300
'build/include',
296301
'build/include_subdir',
297302
'build/include_alpha',
298-
'build/include_inline',
299303
'build/include_order',
300304
'build/include_what_you_use',
301305
'build/namespaces_headers',
@@ -311,13 +315,11 @@
311315
'readability/constructors',
312316
'readability/fn_size',
313317
'readability/inheritance',
314-
'readability/pointer_notation',
315318
'readability/multiline_comment',
316319
'readability/multiline_string',
317320
'readability/namespace',
318321
'readability/nolint',
319322
'readability/nul',
320-
'readability/null_usage',
321323
'readability/strings',
322324
'readability/todo',
323325
'readability/utf8',
@@ -337,7 +339,6 @@
337339
'runtime/string',
338340
'runtime/threadsafe_fn',
339341
'runtime/vlog',
340-
'runtime/v8_persistent',
341342
'whitespace/blank_line',
342343
'whitespace/braces',
343344
'whitespace/comma',
@@ -846,14 +847,6 @@
846847
'Missing space after ,': r's/,\([^ ]\)/, \1/g',
847848
}
848849

849-
_NULL_TOKEN_PATTERN = re.compile(r'\bNULL\b')
850-
851-
_V8_PERSISTENT_PATTERN = re.compile(r'\bv8::Persistent\b')
852-
853-
_RIGHT_LEANING_POINTER_PATTERN = re.compile(r'[^=|(,\s><);&?:}]'
854-
r'(?<!(sizeof|return))'
855-
r'\s\*[a-zA-Z_][0-9a-zA-Z_]*')
856-
857850
_regexp_compile_cache = {}
858851

859852
# {str, set(int)}: a map from error categories to sets of linenumbers
@@ -1094,11 +1087,10 @@ class _IncludeState(object):
10941087
# needs to move backwards, CheckNextIncludeOrder will raise an error.
10951088
_INITIAL_SECTION = 0
10961089
_MY_H_SECTION = 1
1097-
_OTHER_H_SECTION = 2
1098-
_OTHER_SYS_SECTION = 3
1099-
_C_SECTION = 4
1100-
_CPP_SECTION = 5
1101-
1090+
_C_SECTION = 2
1091+
_CPP_SECTION = 3
1092+
_OTHER_SYS_SECTION = 4
1093+
_OTHER_H_SECTION = 5
11021094

11031095
_TYPE_NAMES = {
11041096
_C_SYS_HEADER: 'C system header',
@@ -1928,6 +1920,7 @@ def __init__(self, lines):
19281920
self.raw_lines = lines
19291921
self.num_lines = len(lines)
19301922
self.lines_without_raw_strings = CleanseRawStrings(lines)
1923+
# # pylint: disable=consider-using-enumerate
19311924
for linenum in range(len(self.lines_without_raw_strings)):
19321925
self.lines.append(CleanseComments(
19331926
self.lines_without_raw_strings[linenum]))
@@ -2534,21 +2527,6 @@ def CheckForBadCharacters(filename, lines, error):
25342527
error(filename, linenum, 'readability/nul', 5, 'Line contains NUL byte.')
25352528

25362529

2537-
def CheckInlineHeader(filename, include_state, error):
2538-
"""Logs an error if both a header and its inline variant are included."""
2539-
2540-
all_headers = dict(item for sublist in include_state.include_list
2541-
for item in sublist)
2542-
bad_headers = set('%s.h' % name[:-6] for name in all_headers.keys()
2543-
if name.endswith('-inl.h'))
2544-
bad_headers &= set(all_headers.keys())
2545-
2546-
for name in bad_headers:
2547-
err = '%s includes both %s and %s-inl.h' % (filename, name, name)
2548-
linenum = all_headers[name]
2549-
error(filename, linenum, 'build/include_inline', 5, err)
2550-
2551-
25522530
def CheckForNewlineAtEOF(filename, lines, error):
25532531
"""Logs an error if there is no newline char at the end of the file.
25542532
@@ -3572,7 +3550,7 @@ def CheckForFunctionLengths(filename, clean_lines, linenum,
35723550
"""Reports for long function bodies.
35733551
35743552
For an overview why this is done, see:
3575-
https://google.github.io/styleguide/cppguide.html#Write_Short_Functions
3553+
https://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Write_Short_Functions
35763554
35773555
Uses a simplistic algorithm assuming other style guidelines
35783556
(especially spacing) are followed.
@@ -4799,71 +4777,6 @@ def CheckAltTokens(filename, clean_lines, linenum, error):
47994777
'Use operator %s instead of %s' % (
48004778
_ALT_TOKEN_REPLACEMENT[match.group(1)], match.group(1)))
48014779

4802-
def CheckNullTokens(filename, clean_lines, linenum, error):
4803-
"""Check NULL usage.
4804-
4805-
Args:
4806-
filename: The name of the current file.
4807-
clean_lines: A CleansedLines instance containing the file.
4808-
linenum: The number of the line to check.
4809-
error: The function to call with any errors found.
4810-
"""
4811-
line = clean_lines.elided[linenum]
4812-
4813-
# Avoid preprocessor lines
4814-
if Match(r'^\s*#', line):
4815-
return
4816-
4817-
if line.find('/*') >= 0 or line.find('*/') >= 0:
4818-
return
4819-
4820-
for match in _NULL_TOKEN_PATTERN.finditer(line):
4821-
error(filename, linenum, 'readability/null_usage', 2,
4822-
'Use nullptr instead of NULL')
4823-
4824-
def CheckV8PersistentTokens(filename, clean_lines, linenum, error):
4825-
"""Check v8::Persistent usage.
4826-
4827-
Args:
4828-
filename: The name of the current file.
4829-
clean_lines: A CleansedLines instance containing the file.
4830-
linenum: The number of the line to check.
4831-
error: The function to call with any errors found.
4832-
"""
4833-
line = clean_lines.elided[linenum]
4834-
4835-
# Avoid preprocessor lines
4836-
if Match(r'^\s*#', line):
4837-
return
4838-
4839-
if line.find('/*') >= 0 or line.find('*/') >= 0:
4840-
return
4841-
4842-
for match in _V8_PERSISTENT_PATTERN.finditer(line):
4843-
error(filename, linenum, 'runtime/v8_persistent', 2,
4844-
'Use v8::Global instead of v8::Persistent')
4845-
4846-
def CheckLeftLeaningPointer(filename, clean_lines, linenum, error):
4847-
"""Check for left-leaning pointer placement.
4848-
4849-
Args:
4850-
filename: The name of the current file.
4851-
clean_lines: A CleansedLines instance containing the file.
4852-
linenum: The number of the line to check.
4853-
error: The function to call with any errors found.
4854-
"""
4855-
line = clean_lines.elided[linenum]
4856-
4857-
# Avoid preprocessor lines
4858-
if Match(r'^\s*#', line):
4859-
return
4860-
4861-
if '/*' in line or '*/' in line:
4862-
return
4863-
4864-
for match in _RIGHT_LEANING_POINTER_PATTERN.finditer(line):
4865-
error(filename, linenum, 'readability/pointer_notation', 2,
4866-
'Use left leaning pointer instead of right leaning')
48674780

48684781
def GetLineWidth(line):
48694782
"""Determines the width of the line in column positions.
@@ -5018,9 +4931,6 @@ def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state,
50184931
CheckSpacingForFunctionCall(filename, clean_lines, linenum, error)
50194932
CheckCheck(filename, clean_lines, linenum, error)
50204933
CheckAltTokens(filename, clean_lines, linenum, error)
5021-
CheckNullTokens(filename, clean_lines, linenum, error)
5022-
CheckV8PersistentTokens(filename, clean_lines, linenum, error)
5023-
CheckLeftLeaningPointer(filename, clean_lines, linenum, error)
50244934
classinfo = nesting_state.InnermostClass()
50254935
if classinfo:
50264936
CheckSectionSpacing(filename, clean_lines, classinfo, linenum, error)
@@ -5164,10 +5074,12 @@ def CheckIncludeLine(filename, clean_lines, linenum, include_state, error):
51645074
#
51655075
# We also make an exception for Lua headers, which follow google
51665076
# naming convention but not the include convention.
5167-
match = Match(r'#include\s*"([^/]+\.h)"', line)
5168-
if match and not _THIRD_PARTY_HEADERS_PATTERN.match(match.group(1)):
5169-
error(filename, linenum, 'build/include_subdir', 4,
5170-
'Include the directory when naming .h files')
5077+
match = Match(r'#include\s*"([^/]+\.(.*))"', line)
5078+
if match:
5079+
if (IsHeaderExtension(match.group(2)) and
5080+
not _THIRD_PARTY_HEADERS_PATTERN.match(match.group(1))):
5081+
error(filename, linenum, 'build/include_subdir', 4,
5082+
'Include the directory when naming header files')
51715083

51725084
# we shouldn't include a file more than once. actually, there are a
51735085
# handful of instances where doing so is okay, but in general it's
@@ -5206,10 +5118,11 @@ def CheckIncludeLine(filename, clean_lines, linenum, include_state, error):
52065118
include_state.include_list[-1].append((include, linenum))
52075119

52085120
# We want to ensure that headers appear in the right order:
5209-
# 1) for foo.cc, foo.h
5210-
# 2) other project headers
5211-
# 3) c system files
5212-
# 4) cpp system files
5121+
# 1) for foo.cc, foo.h (preferred location)
5122+
# 2) c system files
5123+
# 3) cpp system files
5124+
# 4) for foo.cc, foo.h (deprecated location)
5125+
# 5) other google headers
52135126
#
52145127
# We classify each include statement as one of those 5 types
52155128
# using a number of techniques. The include_state object keeps
@@ -5472,7 +5385,7 @@ def CheckLanguage(filename, clean_lines, linenum, file_extension,
54725385
and line[-1] != '\\'):
54735386
error(filename, linenum, 'build/namespaces_headers', 4,
54745387
'Do not use unnamed namespaces in header files. See '
5475-
'https://google.github.io/styleguide/cppguide.html#Namespaces'
5388+
'https://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Namespaces'
54765389
' for more information.')
54775390

54785391

@@ -6594,8 +6507,6 @@ def ProcessFileData(filename, file_extension, lines, error,
65946507

65956508
CheckForNewlineAtEOF(filename, lines, error)
65966509

6597-
CheckInlineHeader(filename, include_state, error)
6598-
65996510
def ProcessConfigOverrides(filename):
66006511
""" Loads the configuration files and processes the config overrides.
66016512
@@ -6614,13 +6525,13 @@ def ProcessConfigOverrides(filename):
66146525
if not base_name:
66156526
break # Reached the root directory.
66166527

6617-
cfg_file = os.path.join(abs_path, ".cpplint")
6528+
cfg_file = os.path.join(abs_path, "CPPLINT.cfg")
66186529
abs_filename = abs_path
66196530
if not os.path.isfile(cfg_file):
66206531
continue
66216532

66226533
try:
6623-
with open(cfg_file) as file_handle:
6534+
with open(cfg_file, encoding='utf-8') as file_handle:
66246535
for line in file_handle:
66256536
line, _, _ = line.partition('#') # Remove comments.
66266537
if not line.strip():

0 commit comments

Comments
 (0)