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 c09fdba

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> PR-URL: #35866
1 parent 3955ccd commit c09fdba
Copy full SHA for c09fdba

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
@@ -290,6 +290,7 @@
290290
'build/include',
291291
'build/include_subdir',
292292
'build/include_alpha',
293+
'build/include_inline',
293294
'build/include_order',
294295
'build/include_what_you_use',
295296
'build/namespaces_literals',
@@ -304,11 +305,13 @@
304305
'readability/constructors',
305306
'readability/fn_size',
306307
'readability/inheritance',
308+
'readability/pointer_notation',
307309
'readability/multiline_comment',
308310
'readability/multiline_string',
309311
'readability/namespace',
310312
'readability/nolint',
311313
'readability/nul',
314+
'readability/null_usage',
312315
'readability/strings',
313316
'readability/todo',
314317
'readability/utf8',
@@ -328,6 +331,7 @@
328331
'runtime/string',
329332
'runtime/threadsafe_fn',
330333
'runtime/vlog',
334+
'runtime/v8_persistent',
331335
'whitespace/blank_line',
332336
'whitespace/braces',
333337
'whitespace/comma',
@@ -813,6 +817,14 @@
813817
# Match string that indicates we're working on a Linux Kernel file.
814818
_SEARCH_KERNEL_FILE = re.compile(r'\b(?:LINT_KERNEL_FILE)')
815819

820+
_NULL_TOKEN_PATTERN = re.compile(r'\bNULL\b')
821+
822+
_V8_PERSISTENT_PATTERN = re.compile(r'\bv8::Persistent\b')
823+
824+
_RIGHT_LEANING_POINTER_PATTERN = re.compile(r'[^=|(,\s><);&?:}]'
825+
r'(?<!(sizeof|return))'
826+
r'\s\*[a-zA-Z_][0-9a-zA-Z_]*')
827+
816828
_regexp_compile_cache = {}
817829

818830
# {str, set(int)}: a map from error categories to sets of linenumbers
@@ -832,7 +844,7 @@
832844
# Files to exclude from linting. This is set by the --exclude flag.
833845
_excludes = None
834846

835-
# Whether to supress PrintInfo messages
847+
# Whether to suppress PrintInfo messages
836848
_quiet = False
837849

838850
# The allowed line length of files.
@@ -1053,10 +1065,11 @@ class _IncludeState(object):
10531065
# needs to move backwards, CheckNextIncludeOrder will raise an error.
10541066
_INITIAL_SECTION = 0
10551067
_MY_H_SECTION = 1
1056-
_C_SECTION = 2
1057-
_CPP_SECTION = 3
1058-
_OTHER_SYS_SECTION = 4
1059-
_OTHER_H_SECTION = 5
1068+
_OTHER_H_SECTION = 2
1069+
_OTHER_SYS_SECTION = 3
1070+
_C_SECTION = 4
1071+
_CPP_SECTION = 5
1072+
10601073

10611074
_TYPE_NAMES = {
10621075
_C_SYS_HEADER: 'C system header',
@@ -2474,6 +2487,21 @@ def CheckForBadCharacters(filename, lines, error):
24742487
error(filename, linenum, 'readability/nul', 5, 'Line contains NUL byte.')
24752488

24762489

2490+
def CheckInlineHeader(filename, include_state, error):
2491+
"""Logs an error if both a header and its inline variant are included."""
2492+
2493+
all_headers = dict(item for sublist in include_state.include_list
2494+
for item in sublist)
2495+
bad_headers = set('%s.h' % name[:-6] for name in all_headers.keys()
2496+
if name.endswith('-inl.h'))
2497+
bad_headers &= set(all_headers.keys())
2498+
2499+
for name in bad_headers:
2500+
err = '%s includes both %s and %s-inl.h' % (filename, name, name)
2501+
linenum = all_headers[name]
2502+
error(filename, linenum, 'build/include_inline', 5, err)
2503+
2504+
24772505
def CheckForNewlineAtEOF(filename, lines, error):
24782506
"""Logs an error if there is no newline char at the end of the file.
24792507
@@ -3497,7 +3525,7 @@ def CheckForFunctionLengths(filename, clean_lines, linenum,
34973525
"""Reports for long function bodies.
34983526
34993527
For an overview why this is done, see:
3500-
https://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Write_Short_Functions
3528+
https://google.github.io/styleguide/cppguide.html#Write_Short_Functions
35013529
35023530
Uses a simplistic algorithm assuming other style guidelines
35033531
(especially spacing) are followed.
@@ -4723,6 +4751,71 @@ def CheckAltTokens(filename, clean_lines, linenum, error):
47234751
'Use operator %s instead of %s' % (
47244752
_ALT_TOKEN_REPLACEMENT[match.group(1)], match.group(1)))
47254753

4754+
def CheckNullTokens(filename, clean_lines, linenum, error):
4755+
"""Check NULL usage.
4756+
4757+
Args:
4758+
filename: The name of the current file.
4759+
clean_lines: A CleansedLines instance containing the file.
4760+
linenum: The number of the line to check.
4761+
error: The function to call with any errors found.
4762+
"""
4763+
line = clean_lines.elided[linenum]
4764+
4765+
# Avoid preprocessor lines
4766+
if Match(r'^\s*#', line):
4767+
return
4768+
4769+
if line.find('/*') >= 0 or line.find('*/') >= 0:
4770+
return
4771+
4772+
for match in _NULL_TOKEN_PATTERN.finditer(line):
4773+
error(filename, linenum, 'readability/null_usage', 2,
4774+
'Use nullptr instead of NULL')
4775+
4776+
def CheckV8PersistentTokens(filename, clean_lines, linenum, error):
4777+
"""Check v8::Persistent usage.
4778+
4779+
Args:
4780+
filename: The name of the current file.
4781+
clean_lines: A CleansedLines instance containing the file.
4782+
linenum: The number of the line to check.
4783+
error: The function to call with any errors found.
4784+
"""
4785+
line = clean_lines.elided[linenum]
4786+
4787+
# Avoid preprocessor lines
4788+
if Match(r'^\s*#', line):
4789+
return
4790+
4791+
if line.find('/*') >= 0 or line.find('*/') >= 0:
4792+
return
4793+
4794+
for match in _V8_PERSISTENT_PATTERN.finditer(line):
4795+
error(filename, linenum, 'runtime/v8_persistent', 2,
4796+
'Use v8::Global instead of v8::Persistent')
4797+
4798+
def CheckLeftLeaningPointer(filename, clean_lines, linenum, error):
4799+
"""Check for left-leaning pointer placement.
4800+
4801+
Args:
4802+
filename: The name of the current file.
4803+
clean_lines: A CleansedLines instance containing the file.
4804+
linenum: The number of the line to check.
4805+
error: The function to call with any errors found.
4806+
"""
4807+
line = clean_lines.elided[linenum]
4808+
4809+
# Avoid preprocessor lines
4810+
if Match(r'^\s*#', line):
4811+
return
4812+
4813+
if '/*' in line or '*/' in line:
4814+
return
4815+
4816+
for match in _RIGHT_LEANING_POINTER_PATTERN.finditer(line):
4817+
error(filename, linenum, 'readability/pointer_notation', 2,
4818+
'Use left leaning pointer instead of right leaning')
47264819

47274820
def GetLineWidth(line):
47284821
"""Determines the width of the line in column positions.
@@ -4877,6 +4970,9 @@ def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state,
48774970
CheckSpacingForFunctionCall(filename, clean_lines, linenum, error)
48784971
CheckCheck(filename, clean_lines, linenum, error)
48794972
CheckAltTokens(filename, clean_lines, linenum, error)
4973+
CheckNullTokens(filename, clean_lines, linenum, error)
4974+
CheckV8PersistentTokens(filename, clean_lines, linenum, error)
4975+
CheckLeftLeaningPointer(filename, clean_lines, linenum, error)
48804976
classinfo = nesting_state.InnermostClass()
48814977
if classinfo:
48824978
CheckSectionSpacing(filename, clean_lines, classinfo, linenum, error)
@@ -5062,11 +5158,10 @@ def CheckIncludeLine(filename, clean_lines, linenum, include_state, error):
50625158
include_state.include_list[-1].append((include, linenum))
50635159

50645160
# We want to ensure that headers appear in the right order:
5065-
# 1) for foo.cc, foo.h (preferred location)
5066-
# 2) c system files
5067-
# 3) cpp system files
5068-
# 4) for foo.cc, foo.h (deprecated location)
5069-
# 5) other google headers
5161+
# 1) for foo.cc, foo.h
5162+
# 2) other project headers
5163+
# 3) c system files
5164+
# 4) cpp system files
50705165
#
50715166
# We classify each include statement as one of those 5 types
50725167
# using a number of techniques. The include_state object keeps
@@ -5329,7 +5424,7 @@ def CheckLanguage(filename, clean_lines, linenum, file_extension,
53295424
and line[-1] != '\\'):
53305425
error(filename, linenum, 'build/namespaces', 4,
53315426
'Do not use unnamed namespaces in header files. See '
5332-
'https://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Namespaces'
5427+
'https://google.github.io/styleguide/cppguide.html#Namespaces'
53335428
' for more information.')
53345429

53355430

@@ -6451,6 +6546,8 @@ def ProcessFileData(filename, file_extension, lines, error,
64516546

64526547
CheckForNewlineAtEOF(filename, lines, error)
64536548

6549+
CheckInlineHeader(filename, include_state, error)
6550+
64546551
def ProcessConfigOverrides(filename):
64556552
""" Loads the configuration files and processes the config overrides.
64566553
@@ -6469,7 +6566,7 @@ def ProcessConfigOverrides(filename):
64696566
if not base_name:
64706567
break # Reached the root directory.
64716568

6472-
cfg_file = os.path.join(abs_path, "CPPLINT.cfg")
6569+
cfg_file = os.path.join(abs_path, ".cpplint")
64736570
abs_filename = abs_path
64746571
if not os.path.isfile(cfg_file):
64756572
continue

0 commit comments

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