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 66da122

Browse filesBrowse files
Trotttargos
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> PR-URL: #35719 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 042d4dd commit 66da122
Copy full SHA for 66da122

File tree

Expand file treeCollapse file tree

1 file changed

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

1 file changed

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

‎tools/cpplint.py‎

Copy file name to clipboardExpand all lines: tools/cpplint.py
+110-13Lines changed: 110 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',
@@ -737,6 +741,14 @@
737741
# Match string that indicates we're working on a Linux Kernel file.
738742
_SEARCH_KERNEL_FILE = re.compile(r'\b(?:LINT_KERNEL_FILE)')
739743

744+
_NULL_TOKEN_PATTERN = re.compile(r'\bNULL\b')
745+
746+
_V8_PERSISTENT_PATTERN = re.compile(r'\bv8::Persistent\b')
747+
748+
_RIGHT_LEANING_POINTER_PATTERN = re.compile(r'[^=|(,\s><);&?:}]'
749+
r'(?<!(sizeof|return))'
750+
r'\s\*[a-zA-Z_][0-9a-zA-Z_]*')
751+
740752
_regexp_compile_cache = {}
741753

742754
# {str, set(int)}: a map from error categories to sets of linenumbers
@@ -756,7 +768,7 @@
756768
# Files to exclude from linting. This is set by the --exclude flag.
757769
_excludes = None
758770

759-
# Whether to supress PrintInfo messages
771+
# Whether to suppress PrintInfo messages
760772
_quiet = False
761773

762774
# The allowed line length of files.
@@ -965,10 +977,11 @@ class _IncludeState(object):
965977
# needs to move backwards, CheckNextIncludeOrder will raise an error.
966978
_INITIAL_SECTION = 0
967979
_MY_H_SECTION = 1
968-
_C_SECTION = 2
969-
_CPP_SECTION = 3
970-
_OTHER_SYS_SECTION = 4
971-
_OTHER_H_SECTION = 5
980+
_OTHER_H_SECTION = 2
981+
_OTHER_SYS_SECTION = 3
982+
_C_SECTION = 4
983+
_CPP_SECTION = 5
984+
972985

973986
_TYPE_NAMES = {
974987
_C_SYS_HEADER: 'C system header',
@@ -2386,6 +2399,21 @@ def CheckForBadCharacters(filename, lines, error):
23862399
error(filename, linenum, 'readability/nul', 5, 'Line contains NUL byte.')
23872400

23882401

2402+
def CheckInlineHeader(filename, include_state, error):
2403+
"""Logs an error if both a header and its inline variant are included."""
2404+
2405+
all_headers = dict(item for sublist in include_state.include_list
2406+
for item in sublist)
2407+
bad_headers = set('%s.h' % name[:-6] for name in all_headers.keys()
2408+
if name.endswith('-inl.h'))
2409+
bad_headers &= set(all_headers.keys())
2410+
2411+
for name in bad_headers:
2412+
err = '%s includes both %s and %s-inl.h' % (filename, name, name)
2413+
linenum = all_headers[name]
2414+
error(filename, linenum, 'build/include_inline', 5, err)
2415+
2416+
23892417
def CheckForNewlineAtEOF(filename, lines, error):
23902418
"""Logs an error if there is no newline char at the end of the file.
23912419
@@ -3409,7 +3437,7 @@ def CheckForFunctionLengths(filename, clean_lines, linenum,
34093437
"""Reports for long function bodies.
34103438
34113439
For an overview why this is done, see:
3412-
https://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Write_Short_Functions
3440+
https://google.github.io/styleguide/cppguide.html#Write_Short_Functions
34133441
34143442
Uses a simplistic algorithm assuming other style guidelines
34153443
(especially spacing) are followed.
@@ -4635,6 +4663,71 @@ def CheckAltTokens(filename, clean_lines, linenum, error):
46354663
'Use operator %s instead of %s' % (
46364664
_ALT_TOKEN_REPLACEMENT[match.group(1)], match.group(1)))
46374665

4666+
def CheckNullTokens(filename, clean_lines, linenum, error):
4667+
"""Check NULL usage.
4668+
4669+
Args:
4670+
filename: The name of the current file.
4671+
clean_lines: A CleansedLines instance containing the file.
4672+
linenum: The number of the line to check.
4673+
error: The function to call with any errors found.
4674+
"""
4675+
line = clean_lines.elided[linenum]
4676+
4677+
# Avoid preprocessor lines
4678+
if Match(r'^\s*#', line):
4679+
return
4680+
4681+
if line.find('/*') >= 0 or line.find('*/') >= 0:
4682+
return
4683+
4684+
for match in _NULL_TOKEN_PATTERN.finditer(line):
4685+
error(filename, linenum, 'readability/null_usage', 2,
4686+
'Use nullptr instead of NULL')
4687+
4688+
def CheckV8PersistentTokens(filename, clean_lines, linenum, error):
4689+
"""Check v8::Persistent usage.
4690+
4691+
Args:
4692+
filename: The name of the current file.
4693+
clean_lines: A CleansedLines instance containing the file.
4694+
linenum: The number of the line to check.
4695+
error: The function to call with any errors found.
4696+
"""
4697+
line = clean_lines.elided[linenum]
4698+
4699+
# Avoid preprocessor lines
4700+
if Match(r'^\s*#', line):
4701+
return
4702+
4703+
if line.find('/*') >= 0 or line.find('*/') >= 0:
4704+
return
4705+
4706+
for match in _V8_PERSISTENT_PATTERN.finditer(line):
4707+
error(filename, linenum, 'runtime/v8_persistent', 2,
4708+
'Use v8::Global instead of v8::Persistent')
4709+
4710+
def CheckLeftLeaningPointer(filename, clean_lines, linenum, error):
4711+
"""Check for left-leaning pointer placement.
4712+
4713+
Args:
4714+
filename: The name of the current file.
4715+
clean_lines: A CleansedLines instance containing the file.
4716+
linenum: The number of the line to check.
4717+
error: The function to call with any errors found.
4718+
"""
4719+
line = clean_lines.elided[linenum]
4720+
4721+
# Avoid preprocessor lines
4722+
if Match(r'^\s*#', line):
4723+
return
4724+
4725+
if '/*' in line or '*/' in line:
4726+
return
4727+
4728+
for match in _RIGHT_LEANING_POINTER_PATTERN.finditer(line):
4729+
error(filename, linenum, 'readability/pointer_notation', 2,
4730+
'Use left leaning pointer instead of right leaning')
46384731

46394732
def GetLineWidth(line):
46404733
"""Determines the width of the line in column positions.
@@ -4789,6 +4882,9 @@ def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state,
47894882
CheckSpacingForFunctionCall(filename, clean_lines, linenum, error)
47904883
CheckCheck(filename, clean_lines, linenum, error)
47914884
CheckAltTokens(filename, clean_lines, linenum, error)
4885+
CheckNullTokens(filename, clean_lines, linenum, error)
4886+
CheckV8PersistentTokens(filename, clean_lines, linenum, error)
4887+
CheckLeftLeaningPointer(filename, clean_lines, linenum, error)
47924888
classinfo = nesting_state.InnermostClass()
47934889
if classinfo:
47944890
CheckSectionSpacing(filename, clean_lines, classinfo, linenum, error)
@@ -4972,11 +5068,10 @@ def CheckIncludeLine(filename, clean_lines, linenum, include_state, error):
49725068
include_state.include_list[-1].append((include, linenum))
49735069

49745070
# We want to ensure that headers appear in the right order:
4975-
# 1) for foo.cc, foo.h (preferred location)
4976-
# 2) c system files
4977-
# 3) cpp system files
4978-
# 4) for foo.cc, foo.h (deprecated location)
4979-
# 5) other google headers
5071+
# 1) for foo.cc, foo.h
5072+
# 2) other project headers
5073+
# 3) c system files
5074+
# 4) cpp system files
49805075
#
49815076
# We classify each include statement as one of those 5 types
49825077
# using a number of techniques. The include_state object keeps
@@ -5239,7 +5334,7 @@ def CheckLanguage(filename, clean_lines, linenum, file_extension,
52395334
and line[-1] != '\\'):
52405335
error(filename, linenum, 'build/namespaces', 4,
52415336
'Do not use unnamed namespaces in header files. See '
5242-
'https://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Namespaces'
5337+
'https://google.github.io/styleguide/cppguide.html#Namespaces'
52435338
' for more information.')
52445339

52455340

@@ -6361,6 +6456,8 @@ def ProcessFileData(filename, file_extension, lines, error,
63616456

63626457
CheckForNewlineAtEOF(filename, lines, error)
63636458

6459+
CheckInlineHeader(filename, include_state, error)
6460+
63646461
def ProcessConfigOverrides(filename):
63656462
""" Loads the configuration files and processes the config overrides.
63666463
@@ -6379,7 +6476,7 @@ def ProcessConfigOverrides(filename):
63796476
if not base_name:
63806477
break # Reached the root directory.
63816478

6382-
cfg_file = os.path.join(abs_path, "CPPLINT.cfg")
6479+
cfg_file = os.path.join(abs_path, ".cpplint")
63836480
abs_filename = abs_path
63846481
if not os.path.isfile(cfg_file):
63856482
continue

0 commit comments

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