Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit adf4f90

Browse filesBrowse files
TrottMylesBorins
authored andcommitted
tools: refloat 7 Node.js patches to cpplint.py
Cherry-pick 12c8b4d Original commit message: This commit is a suggestion for adding a rule for NULL usages in the code base. This will currently report a number of errors which could be ignored using // NOLINT (readability/null_usage) PR-URL: #17373 Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Refs: 12c8b4d Cherry-pick fc81e80 Original commit message: Update cpplint.py to check for inline headers when the corresponding header is already included. PR-URL: #21521 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Refs: fc81e80 Cherry-pick cbc3dd9 Original commit message: src, tools: add check for left leaning pointers This commit adds a rule to cpplint to check that pointers in the code base lean to the left and not right, and also fixes the violations reported. PR-URL: #21010 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Refs: cbc3dd9 Cherry-pick 9029981 Original commit message: tools: fix cpplint.py header rules THIS COMMIT SHOULD GO WITH THE NEXT. IT WILL FIND NEW LINT. PR-URL: #26306 Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Refs: 9029981 Cherry-pick 0a25ace Original commit message: tools: move cpplint configuration to .cpplint PR-URL: #27098 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Refs: 0a25ace Cherry-pick afa9a72 Original commit message: tools: refloat update link to google styleguide for cpplint This commit updates two old links to Google's C++ styleguide which currently result in a 404 when accessed. PR-URL: #30876 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Refs: afa9a72 Cherry-pick e23bf8f Original commit message: tools,src: refloat forbid usage of v8::Persistent `v8::Persistent` comes with the surprising catch that it requires manual cleanup. `v8::Global` doesn’t, making it easier to use, and additionally provides move semantics. New code should always use `v8::Global`. PR-URL: #31018 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> PR-URL: #35569 Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
1 parent 1173efc commit adf4f90
Copy full SHA for adf4f90

File tree

Expand file treeCollapse file tree

1 file changed

+109
-13
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+109
-13
lines changed
Open diff view settings
Collapse file

‎tools/cpplint.py‎

Copy file name to clipboardExpand all lines: tools/cpplint.py
+109-13Lines changed: 109 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@
280280
'build/include',
281281
'build/include_subdir',
282282
'build/include_alpha',
283+
'build/include_inline',
283284
'build/include_order',
284285
'build/include_what_you_use',
285286
'build/namespaces_literals',
@@ -294,11 +295,13 @@
294295
'readability/constructors',
295296
'readability/fn_size',
296297
'readability/inheritance',
298+
'readability/pointer_notation',
297299
'readability/multiline_comment',
298300
'readability/multiline_string',
299301
'readability/namespace',
300302
'readability/nolint',
301303
'readability/nul',
304+
'readability/null_usage',
302305
'readability/strings',
303306
'readability/todo',
304307
'readability/utf8',
@@ -318,6 +321,7 @@
318321
'runtime/string',
319322
'runtime/threadsafe_fn',
320323
'runtime/vlog',
324+
'runtime/v8_persistent',
321325
'whitespace/blank_line',
322326
'whitespace/braces',
323327
'whitespace/comma',
@@ -622,6 +626,14 @@
622626
# Match string that indicates we're working on a Linux Kernel file.
623627
_SEARCH_KERNEL_FILE = re.compile(r'\b(?:LINT_KERNEL_FILE)')
624628

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+
625637
_regexp_compile_cache = {}
626638

627639
# {str, set(int)}: a map from error categories to sets of linenumbers
@@ -641,7 +653,7 @@
641653
# Files to exclude from linting. This is set by the --exclude flag.
642654
_excludes = None
643655

644-
# Whether to supress PrintInfo messages
656+
# Whether to suppress PrintInfo messages
645657
_quiet = False
646658

647659
# The allowed line length of files.
@@ -850,9 +862,9 @@ class _IncludeState(object):
850862
# needs to move backwards, CheckNextIncludeOrder will raise an error.
851863
_INITIAL_SECTION = 0
852864
_MY_H_SECTION = 1
853-
_C_SECTION = 2
854-
_CPP_SECTION = 3
855-
_OTHER_H_SECTION = 4
865+
_OTHER_H_SECTION = 2
866+
_C_SECTION = 3
867+
_CPP_SECTION = 4
856868

857869
_TYPE_NAMES = {
858870
_C_SYS_HEADER: 'C system header',
@@ -864,9 +876,9 @@ class _IncludeState(object):
864876
_SECTION_NAMES = {
865877
_INITIAL_SECTION: "... nothing. (This can't be an error.)",
866878
_MY_H_SECTION: 'a header this file implements',
879+
_OTHER_H_SECTION: 'other header',
867880
_C_SECTION: 'C system header',
868881
_CPP_SECTION: 'C++ system header',
869-
_OTHER_H_SECTION: 'other header',
870882
}
871883

872884
def __init__(self):
@@ -2262,6 +2274,21 @@ def CheckForBadCharacters(filename, lines, error):
22622274
error(filename, linenum, 'readability/nul', 5, 'Line contains NUL byte.')
22632275

22642276

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+
22652292
def CheckForNewlineAtEOF(filename, lines, error):
22662293
"""Logs an error if there is no newline char at the end of the file.
22672294
@@ -3285,7 +3312,7 @@ def CheckForFunctionLengths(filename, clean_lines, linenum,
32853312
"""Reports for long function bodies.
32863313
32873314
For an overview why this is done, see:
3288-
https://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Write_Short_Functions
3315+
https://google.github.io/styleguide/cppguide.html#Write_Short_Functions
32893316
32903317
Uses a simplistic algorithm assuming other style guidelines
32913318
(especially spacing) are followed.
@@ -4511,6 +4538,71 @@ def CheckAltTokens(filename, clean_lines, linenum, error):
45114538
'Use operator %s instead of %s' % (
45124539
_ALT_TOKEN_REPLACEMENT[match.group(1)], match.group(1)))
45134540

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')
45144606

45154607
def GetLineWidth(line):
45164608
"""Determines the width of the line in column positions.
@@ -4665,6 +4757,9 @@ def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state,
46654757
CheckSpacingForFunctionCall(filename, clean_lines, linenum, error)
46664758
CheckCheck(filename, clean_lines, linenum, error)
46674759
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)
46684763
classinfo = nesting_state.InnermostClass()
46694764
if classinfo:
46704765
CheckSectionSpacing(filename, clean_lines, classinfo, linenum, error)
@@ -4841,11 +4936,10 @@ def CheckIncludeLine(filename, clean_lines, linenum, include_state, error):
48414936
include_state.include_list[-1].append((include, linenum))
48424937

48434938
# We want to ensure that headers appear in the right order:
4844-
# 1) for foo.cc, foo.h (preferred location)
4845-
# 2) c system files
4846-
# 3) cpp system files
4847-
# 4) for foo.cc, foo.h (deprecated location)
4848-
# 5) other google headers
4939+
# 1) for foo.cc, foo.h
4940+
# 2) other project headers
4941+
# 3) c system files
4942+
# 4) cpp system files
48494943
#
48504944
# We classify each include statement as one of those 5 types
48514945
# using a number of techniques. The include_state object keeps
@@ -5108,7 +5202,7 @@ def CheckLanguage(filename, clean_lines, linenum, file_extension,
51085202
and line[-1] != '\\'):
51095203
error(filename, linenum, 'build/namespaces', 4,
51105204
'Do not use unnamed namespaces in header files. See '
5111-
'https://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Namespaces'
5205+
'https://google.github.io/styleguide/cppguide.html#Namespaces'
51125206
' for more information.')
51135207

51145208

@@ -6230,6 +6324,8 @@ def ProcessFileData(filename, file_extension, lines, error,
62306324

62316325
CheckForNewlineAtEOF(filename, lines, error)
62326326

6327+
CheckInlineHeader(filename, include_state, error)
6328+
62336329
def ProcessConfigOverrides(filename):
62346330
""" Loads the configuration files and processes the config overrides.
62356331
@@ -6248,7 +6344,7 @@ def ProcessConfigOverrides(filename):
62486344
if not base_name:
62496345
break # Reached the root directory.
62506346

6251-
cfg_file = os.path.join(abs_path, "CPPLINT.cfg")
6347+
cfg_file = os.path.join(abs_path, ".cpplint")
62526348
abs_filename = abs_path
62536349
if not os.path.isfile(cfg_file):
62546350
continue

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.