From 4d193008d781522f6d34534d1199fa5ef5a1fff7 Mon Sep 17 00:00:00 2001 From: Refael Ackermann Date: Mon, 28 Jan 2019 18:34:46 -0500 Subject: [PATCH] tools: refloat Node.js patches to cpplint.py * Preserve 3 node-core checks * Preserve patch to `FileInfo.RepositoryName` * Remove TAP to logfile (unused) PR-URL: https://github.com/nodejs/node/pull/25771 Fixes: https://github.com/nodejs/node/issues/25760 Refs: https://github.com/cpplint/cpplint/blob/3d8f6f876dd6e3918e5641483298dbc82e65f358/cpplint.py Reviewed-By: Sakthipriyan Vairamani Reviewed-By: Ben Noordhuis --- tools/cpplint.py | 138 +++++++++++++++++++++++++++++------------------ 1 file changed, 87 insertions(+), 51 deletions(-) diff --git a/tools/cpplint.py b/tools/cpplint.py index 8ca6471179b070..17f341a61d7a2c 100755 --- a/tools/cpplint.py +++ b/tools/cpplint.py @@ -122,7 +122,7 @@ def GetNonHeaderExtensions(): likely to be false positives. quiet - Supress output other than linting errors, such as information about + Suppress output other than linting errors, such as information about which files have been processed and excluded. filter=-x,+y,... @@ -298,11 +298,13 @@ def GetNonHeaderExtensions(): 'readability/constructors', 'readability/fn_size', 'readability/inheritance', + 'readability/pointer_notation', 'readability/multiline_comment', 'readability/multiline_string', 'readability/namespace', 'readability/nolint', 'readability/nul', + 'readability/null_usage', 'readability/strings', 'readability/todo', 'readability/utf8', @@ -353,7 +355,11 @@ def GetNonHeaderExtensions(): # flag. By default all errors are on, so only add here categories that should be # off by default (i.e., categories that must be enabled by the --filter= flags). # All entries here should start with a '-' or '+', as in the --filter= flag. -_DEFAULT_FILTERS = ['-build/include_alpha'] +_DEFAULT_FILTERS = [ + '-build/include', + '-build/include_subdir', + '-legal/copyright', + ] # The default list of categories suppressed for C (not C++) files. _DEFAULT_C_SUPPRESSED_CATEGORIES = [ @@ -626,6 +632,12 @@ def GetNonHeaderExtensions(): # Match string that indicates we're working on a Linux Kernel file. _SEARCH_KERNEL_FILE = re.compile(r'\b(?:LINT_KERNEL_FILE)') +_NULL_TOKEN_PATTERN = re.compile(r'\bNULL\b') + +_RIGHT_LEANING_POINTER_PATTERN = re.compile(r'[^=|(,\s><);&?:}]' + r'(?= 0 or line.find('*/') >= 0: + return + + for match in _NULL_TOKEN_PATTERN.finditer(line): + error(filename, linenum, 'readability/null_usage', 2, + 'Use nullptr instead of NULL') + +def CheckLeftLeaningPointer(filename, clean_lines, linenum, error): + """Check for left-leaning pointer placement. + + Args: + filename: The name of the current file. + clean_lines: A CleansedLines instance containing the file. + linenum: The number of the line to check. + error: The function to call with any errors found. + """ + line = clean_lines.elided[linenum] + + # Avoid preprocessor lines + if Match(r'^\s*#', line): + return + + if '/*' in line or '*/' in line: + return + + for match in _RIGHT_LEANING_POINTER_PATTERN.finditer(line): + error(filename, linenum, 'readability/pointer_notation', 2, + 'Use left leaning pointer instead of right leaning') def GetLineWidth(line): """Determines the width of the line in column positions. @@ -4477,6 +4505,10 @@ def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state, error(filename, linenum, 'whitespace/tab', 1, 'Tab found; better to use spaces') + if line.find('template<') != -1: + error(filename, linenum, 'whitespace/template', 1, + 'Leave a single space after template, as in `template <...>`') + # One or three blank spaces at the beginning of the line is weird; it's # hard to reconcile that with 2-space indents. # NOTE: here are the conditions rob pike used for his tests. Mine aren't @@ -4570,6 +4602,8 @@ def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state, CheckSpacingForFunctionCall(filename, clean_lines, linenum, error) CheckCheck(filename, clean_lines, linenum, error) CheckAltTokens(filename, clean_lines, linenum, error) + CheckNullTokens(filename, clean_lines, linenum, error) + CheckLeftLeaningPointer(filename, clean_lines, linenum, error) classinfo = nesting_state.InnermostClass() if classinfo: CheckSectionSpacing(filename, clean_lines, classinfo, linenum, error) @@ -6112,6 +6146,8 @@ def ProcessFileData(filename, file_extension, lines, error, CheckForNewlineAtEOF(filename, lines, error) + CheckInlineHeader(filename, include_state, error) + def ProcessConfigOverrides(filename): """ Loads the configuration files and processes the config overrides.