summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorDaniel Bevenius <daniel.bevenius@gmail.com>2018-05-16 11:50:48 +0200
committerDaniel Bevenius <daniel.bevenius@gmail.com>2018-06-07 05:46:51 +0200
commitcbc3dd997eb90d629d1b9912b7a5a40eb82343df (patch)
tree822b55186ac52c127a686d2d828c15518be20186 /tools
parent75e91659887012f743aa4487d6d4ce3d765c028a (diff)
downloadandroid-node-v8-cbc3dd997eb90d629d1b9912b7a5a40eb82343df.tar.gz
android-node-v8-cbc3dd997eb90d629d1b9912b7a5a40eb82343df.tar.bz2
android-node-v8-cbc3dd997eb90d629d1b9912b7a5a40eb82343df.zip
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: https://github.com/nodejs/node/pull/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>
Diffstat (limited to 'tools')
-rw-r--r--tools/cpplint.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/tools/cpplint.py b/tools/cpplint.py
index ee103ef716..a4f786f01a 100644
--- a/tools/cpplint.py
+++ b/tools/cpplint.py
@@ -527,6 +527,10 @@ _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'(?<!(sizeof|return))'
+ r'\s\*[a-zA-z_][0-9a-zA-z_]*')
+
_regexp_compile_cache = {}
# {str, set(int)}: a map from error categories to sets of linenumbers
@@ -4179,6 +4183,28 @@ def CheckNullTokens(filename, clean_lines, linenum, error):
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/null_usage', 2,
+ 'Use left leaning pointer instead of right leaning')
+
def GetLineWidth(line):
"""Determines the width of the line in column positions.
@@ -4321,6 +4347,7 @@ def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state,
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)