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 25b0033

Browse filesBrowse files
TrottMoLow
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> PR-URL: #35866 PR-URL: #36213 Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> PR-URL: #36235 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> PR-URL: #36324 Reviewed-By: Beth Griggs <bgriggs@redhat.com> PR-URL: #38851 Reviewed-By: Khaidi Chu <i@2333.moe> PR-URL: #42416 Reviewed-By: Mestery <mestery@protonmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> PR-URL: #48098 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent 87b36b3 commit 25b0033
Copy full SHA for 25b0033

File tree

Expand file treeCollapse file tree

1 file changed

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

1 file changed

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

‎tools/cpplint.py‎

Copy file name to clipboardExpand all lines: tools/cpplint.py
+109-12Lines changed: 109 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@
302302
'build/include',
303303
'build/include_subdir',
304304
'build/include_alpha',
305+
'build/include_inline',
305306
'build/include_order',
306307
'build/include_what_you_use',
307308
'build/namespaces_headers',
@@ -317,11 +318,13 @@
317318
'readability/constructors',
318319
'readability/fn_size',
319320
'readability/inheritance',
321+
'readability/pointer_notation',
320322
'readability/multiline_comment',
321323
'readability/multiline_string',
322324
'readability/namespace',
323325
'readability/nolint',
324326
'readability/nul',
327+
'readability/null_usage',
325328
'readability/strings',
326329
'readability/todo',
327330
'readability/utf8',
@@ -341,6 +344,7 @@
341344
'runtime/string',
342345
'runtime/threadsafe_fn',
343346
'runtime/vlog',
347+
'runtime/v8_persistent',
344348
'whitespace/blank_line',
345349
'whitespace/braces',
346350
'whitespace/comma',
@@ -871,6 +875,14 @@
871875
'Missing space after ,': r's/,\([^ ]\)/, \1/g',
872876
}
873877

878+
_NULL_TOKEN_PATTERN = re.compile(r'\bNULL\b')
879+
880+
_V8_PERSISTENT_PATTERN = re.compile(r'\bv8::Persistent\b')
881+
882+
_RIGHT_LEANING_POINTER_PATTERN = re.compile(r'[^=|(,\s><);&?:}]'
883+
r'(?<!(sizeof|return))'
884+
r'\s\*[a-zA-Z_][0-9a-zA-Z_]*')
885+
874886
_regexp_compile_cache = {}
875887

876888
# {str, set(int)}: a map from error categories to sets of linenumbers
@@ -1115,10 +1127,11 @@ class _IncludeState(object):
11151127
# needs to move backwards, CheckNextIncludeOrder will raise an error.
11161128
_INITIAL_SECTION = 0
11171129
_MY_H_SECTION = 1
1118-
_C_SECTION = 2
1119-
_CPP_SECTION = 3
1120-
_OTHER_SYS_SECTION = 4
1121-
_OTHER_H_SECTION = 5
1130+
_OTHER_H_SECTION = 2
1131+
_OTHER_SYS_SECTION = 3
1132+
_C_SECTION = 4
1133+
_CPP_SECTION = 5
1134+
11221135

11231136
_TYPE_NAMES = {
11241137
_C_SYS_HEADER: 'C system header',
@@ -2555,6 +2568,21 @@ def CheckForBadCharacters(filename, lines, error):
25552568
error(filename, linenum, 'readability/nul', 5, 'Line contains NUL byte.')
25562569

25572570

2571+
def CheckInlineHeader(filename, include_state, error):
2572+
"""Logs an error if both a header and its inline variant are included."""
2573+
2574+
all_headers = dict(item for sublist in include_state.include_list
2575+
for item in sublist)
2576+
bad_headers = set('%s.h' % name[:-6] for name in all_headers.keys()
2577+
if name.endswith('-inl.h'))
2578+
bad_headers &= set(all_headers.keys())
2579+
2580+
for name in bad_headers:
2581+
err = '%s includes both %s and %s-inl.h' % (filename, name, name)
2582+
linenum = all_headers[name]
2583+
error(filename, linenum, 'build/include_inline', 5, err)
2584+
2585+
25582586
def CheckForNewlineAtEOF(filename, lines, error):
25592587
"""Logs an error if there is no newline char at the end of the file.
25602588
@@ -3578,7 +3606,7 @@ def CheckForFunctionLengths(filename, clean_lines, linenum,
35783606
"""Reports for long function bodies.
35793607
35803608
For an overview why this is done, see:
3581-
https://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Write_Short_Functions
3609+
https://google.github.io/styleguide/cppguide.html#Write_Short_Functions
35823610
35833611
Uses a simplistic algorithm assuming other style guidelines
35843612
(especially spacing) are followed.
@@ -4805,6 +4833,71 @@ def CheckAltTokens(filename, clean_lines, linenum, error):
48054833
'Use operator %s instead of %s' % (
48064834
_ALT_TOKEN_REPLACEMENT[match.group(1)], match.group(1)))
48074835

4836+
def CheckNullTokens(filename, clean_lines, linenum, error):
4837+
"""Check NULL usage.
4838+
4839+
Args:
4840+
filename: The name of the current file.
4841+
clean_lines: A CleansedLines instance containing the file.
4842+
linenum: The number of the line to check.
4843+
error: The function to call with any errors found.
4844+
"""
4845+
line = clean_lines.elided[linenum]
4846+
4847+
# Avoid preprocessor lines
4848+
if Match(r'^\s*#', line):
4849+
return
4850+
4851+
if line.find('/*') >= 0 or line.find('*/') >= 0:
4852+
return
4853+
4854+
for match in _NULL_TOKEN_PATTERN.finditer(line):
4855+
error(filename, linenum, 'readability/null_usage', 2,
4856+
'Use nullptr instead of NULL')
4857+
4858+
def CheckV8PersistentTokens(filename, clean_lines, linenum, error):
4859+
"""Check v8::Persistent usage.
4860+
4861+
Args:
4862+
filename: The name of the current file.
4863+
clean_lines: A CleansedLines instance containing the file.
4864+
linenum: The number of the line to check.
4865+
error: The function to call with any errors found.
4866+
"""
4867+
line = clean_lines.elided[linenum]
4868+
4869+
# Avoid preprocessor lines
4870+
if Match(r'^\s*#', line):
4871+
return
4872+
4873+
if line.find('/*') >= 0 or line.find('*/') >= 0:
4874+
return
4875+
4876+
for match in _V8_PERSISTENT_PATTERN.finditer(line):
4877+
error(filename, linenum, 'runtime/v8_persistent', 2,
4878+
'Use v8::Global instead of v8::Persistent')
4879+
4880+
def CheckLeftLeaningPointer(filename, clean_lines, linenum, error):
4881+
"""Check for left-leaning pointer placement.
4882+
4883+
Args:
4884+
filename: The name of the current file.
4885+
clean_lines: A CleansedLines instance containing the file.
4886+
linenum: The number of the line to check.
4887+
error: The function to call with any errors found.
4888+
"""
4889+
line = clean_lines.elided[linenum]
4890+
4891+
# Avoid preprocessor lines
4892+
if Match(r'^\s*#', line):
4893+
return
4894+
4895+
if '/*' in line or '*/' in line:
4896+
return
4897+
4898+
for match in _RIGHT_LEANING_POINTER_PATTERN.finditer(line):
4899+
error(filename, linenum, 'readability/pointer_notation', 2,
4900+
'Use left leaning pointer instead of right leaning')
48084901

48094902
def GetLineWidth(line):
48104903
"""Determines the width of the line in column positions.
@@ -4959,6 +5052,9 @@ def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state,
49595052
CheckSpacingForFunctionCall(filename, clean_lines, linenum, error)
49605053
CheckCheck(filename, clean_lines, linenum, error)
49615054
CheckAltTokens(filename, clean_lines, linenum, error)
5055+
CheckNullTokens(filename, clean_lines, linenum, error)
5056+
CheckV8PersistentTokens(filename, clean_lines, linenum, error)
5057+
CheckLeftLeaningPointer(filename, clean_lines, linenum, error)
49625058
classinfo = nesting_state.InnermostClass()
49635059
if classinfo:
49645060
CheckSectionSpacing(filename, clean_lines, classinfo, linenum, error)
@@ -5147,11 +5243,10 @@ def CheckIncludeLine(filename, clean_lines, linenum, include_state, error):
51475243
include_state.include_list[-1].append((include, linenum))
51485244

51495245
# We want to ensure that headers appear in the right order:
5150-
# 1) for foo.cc, foo.h (preferred location)
5151-
# 2) c system files
5152-
# 3) cpp system files
5153-
# 4) for foo.cc, foo.h (deprecated location)
5154-
# 5) other google headers
5246+
# 1) for foo.cc, foo.h
5247+
# 2) other project headers
5248+
# 3) c system files
5249+
# 4) cpp system files
51555250
#
51565251
# We classify each include statement as one of those 5 types
51575252
# using a number of techniques. The include_state object keeps
@@ -5414,7 +5509,7 @@ def CheckLanguage(filename, clean_lines, linenum, file_extension,
54145509
and line[-1] != '\\'):
54155510
error(filename, linenum, 'build/namespaces_headers', 4,
54165511
'Do not use unnamed namespaces in header files. See '
5417-
'https://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Namespaces'
5512+
'https://google.github.io/styleguide/cppguide.html#Namespaces'
54185513
' for more information.')
54195514

54205515

@@ -6537,6 +6632,8 @@ def ProcessFileData(filename, file_extension, lines, error,
65376632

65386633
CheckForNewlineAtEOF(filename, lines, error)
65396634

6635+
CheckInlineHeader(filename, include_state, error)
6636+
65406637
def ProcessConfigOverrides(filename):
65416638
""" Loads the configuration files and processes the config overrides.
65426639
@@ -6555,7 +6652,7 @@ def ProcessConfigOverrides(filename):
65556652
if not base_name:
65566653
break # Reached the root directory.
65576654

6558-
cfg_file = os.path.join(abs_path, "CPPLINT.cfg")
6655+
cfg_file = os.path.join(abs_path, ".cpplint")
65596656
abs_filename = abs_path
65606657
if not os.path.isfile(cfg_file):
65616658
continue

0 commit comments

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