Skip to content

Commit 3c6b5d5

Browse files
committed
cpplint: make lint rules closer to node's source
* Support C-style header guards (/* comments */) * Support `class NODE_EXTERN something` * Support `} // extern "C"` closures * Ignore header order * Ignore `long/short` usage (because of OpenSSL's API)
1 parent 6a5a7b0 commit 3c6b5d5

1 file changed

Lines changed: 18 additions & 13 deletions

File tree

tools/cpplint.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,9 +1087,11 @@ def CheckForHeaderGuard(filename, lines, error):
10871087
error(filename, ifndef_linenum, 'build/header_guard', error_level,
10881088
'#ifndef header guard has wrong style, please use: %s' % cppvar)
10891089

1090-
if endif != ('#endif // %s' % cppvar):
1090+
if (endif != ('#endif // %s' % cppvar) and
1091+
endif != ('#endif /* %s */' % cppvar)):
10911092
error_level = 0
1092-
if endif != ('#endif // %s' % (cppvar + '_')):
1093+
if (endif != ('#endif // %s' % (cppvar + '_')) and
1094+
endif != ('#endif /* %s */' % (cppvar + '_'))):
10931095
error_level = 5
10941096

10951097
ParseNolintSuppressions(filename, lines[endif_linenum], endif_linenum,
@@ -1380,7 +1382,8 @@ def CheckForNonStandardConstructs(filename, clean_lines, linenum,
13801382
classinfo_stack = class_state.classinfo_stack
13811383
# Look for a class declaration
13821384
class_decl_match = Match(
1383-
r'\s*(template\s*<[\w\s<>,:]*>\s*)?(class|struct)\s+(\w+(::\w+)*)', line)
1385+
r'\s*(template\s*<[\w\s<>,:]*>\s*)?(class|struct)\s+' +
1386+
r'(?:NODE_EXTERN\s+)?(\w+(::\w+)*)', line)
13841387
if class_decl_match:
13851388
classinfo_stack.append(_ClassInfo(class_decl_match.group(3), linenum))
13861389

@@ -1711,6 +1714,7 @@ def CheckSpacing(filename, clean_lines, linenum, error):
17111714
if (next_line
17121715
and Match(r'\s*}', next_line)
17131716
and next_line.find('namespace') == -1
1717+
and next_line.find('extern') == -1
17141718
and next_line.find('} else ') == -1):
17151719
error(filename, linenum, 'whitespace/blank_line', 3,
17161720
'Blank line at the end of a code block. Is this needed?')
@@ -2112,7 +2116,8 @@ def CheckStyle(filename, clean_lines, linenum, file_extension, error):
21122116
cppvar = GetHeaderGuardCPPVariable(filename)
21132117
if (line.startswith('#ifndef %s' % cppvar) or
21142118
line.startswith('#define %s' % cppvar) or
2115-
line.startswith('#endif // %s' % cppvar)):
2119+
line.startswith('#endif // %s' % cppvar) or
2120+
line.startswith('#endif /* %s */' % cppvar)):
21162121
is_header_guard = True
21172122
# #include lines and header guards can be long, since there's no clean way to
21182123
# split them.
@@ -2307,10 +2312,10 @@ def CheckIncludeLine(filename, clean_lines, linenum, include_state, error):
23072312
# lower type after that.
23082313
error_message = include_state.CheckNextIncludeOrder(
23092314
_ClassifyInclude(fileinfo, include, is_system))
2310-
if error_message:
2311-
error(filename, linenum, 'build/include_order', 4,
2312-
'%s. Should be: %s.h, c system, c++ system, other.' %
2313-
(error_message, fileinfo.BaseName()))
2315+
# if error_message:
2316+
# error(filename, linenum, 'build/include_order', 4,
2317+
# '%s. Should be: %s.h, c system, c++ system, other.' %
2318+
# (error_message, fileinfo.BaseName()))
23142319
if not include_state.IsInAlphabeticalOrder(include):
23152320
error(filename, linenum, 'build/include_alpha', 4,
23162321
'Include "%s" not in alphabetical order' % include)
@@ -2464,11 +2469,11 @@ def CheckLanguage(filename, clean_lines, linenum, file_extension, include_state,
24642469
if not Search(r'\bunsigned short port\b', line):
24652470
error(filename, linenum, 'runtime/int', 4,
24662471
'Use "unsigned short" for ports, not "short"')
2467-
else:
2468-
match = Search(r'\b(short|long(?! +double)|long long)\b', line)
2469-
if match:
2470-
error(filename, linenum, 'runtime/int', 4,
2471-
'Use int16/int64/etc, rather than the C type %s' % match.group(1))
2472+
# else:
2473+
# match = Search(r'\b(short|long(?! +double)|long long)\b', line)
2474+
# if match:
2475+
# error(filename, linenum, 'runtime/int', 4,
2476+
# 'Use int16/int64/etc, rather than the C type %s' % match.group(1))
24722477

24732478
# When snprintf is used, the second argument shouldn't be a literal.
24742479
match = Search(r'snprintf\s*\(([^,]*),\s*([0-9]*)\s*,', line)

0 commit comments

Comments
 (0)