Home | History | Annotate | Download | only in tools

Lines Matching refs:line

49 #  - Check for spaces between brackets in one-line inline method
75 same line, but it is far from perfect (in either direction).
103 'NOLINT(category)' comment to the line. NOLINT or NOLINT(*)
104 suppresses errors of all categories on that line.
320 # False positives include C-style multi-line comments (http://go/nsiut )
321 # and multi-line strings (http://go/beujw ), but those have always been
338 _END_ASM = 2 # Last line of inline assembly block
363 Parses any NOLINT comments on the current line, updating the global
369 raw_line: str, the line of input text, with comments.
370 linenum: int, the number of the current line.
395 """Returns true if the specified error category is suppressed on this line.
402 linenum: int, the current line number.
427 """Tracks line numbers for includes, and the order in which includes appear.
430 filename and line number on which that file was included.
696 """Count line in current function body."""
706 linenum: The number of the line to check.
867 "cpplint(category)" comments on the offending line. These are
872 linenum: The number of the line containing the error.
901 # Matches multi-line C++ comments.
906 # end of the line. Otherwise, we try to remove spaces from the right side,
916 def IsCppString(line):
917 """Does line terminate so, that the next symbol is in string constant.
919 This function does not consider single-line nor multi-line comments.
922 line: is a partial line of code starting from the 0..n.
925 True, if next character appended to 'line' is inside a
929 line = line.replace(r'\\', 'XX') # after this, \\" does not match to \"
930 return ((line.count('"') - line.count(r'\"') - line.count("'\"'")) & 1) == 1
937 # Only return this marker if the comment goes beyond this line
954 """Clears a range of lines for multi-line comments."""
956 # unnecessary blank line warnings later in the code.
971 'Could not find end of multi-line comment')
977 def CleanseComments(line):
978 """Removes //-comments and single-line C-style /* */ comments.
981 line: A line of C++ source.
984 The line with single-line comments removed.
986 commentpos = line.find('//')
987 if commentpos != -1 and not IsCppString(line[:commentpos]):
988 line = line[:commentpos].rstrip()
990 return _RE_PATTERN_CLEANSE_LINE_C_COMMENTS.sub('', line)
1018 """Collapses strings and chars on a line to simple "" or '' blocks.
1023 elided: The line being processed.
1026 The line with collapsed strings.
1038 def FindEndOfExpressionInLine(line, startpos, depth, startchar, endchar):
1042 line: a CleansedLines line.
1051 for i in xrange(startpos, len(line)):
1052 if line[i] == startchar:
1054 elif line[i] == endchar:
1069 linenum: The number of the line to check.
1070 pos: A position on the line.
1073 A tuple (line, linenum, pos) pointer *past* the closing brace, or
1074 (line, len(lines), -1) if we never find a close. Note we ignore
1075 strings and comments when matching; and the line we return is the
1076 'cleansed' line at linenum.
1079 line = clean_lines.elided[linenum]
1080 startchar = line[pos]
1082 return (line, clean_lines.NumLines(), -1)
1087 # Check first line
1088 end_pos = FindEndOfExpressionInLine(line, pos, 0, startchar, endchar)
1090 return (line, linenum, end_pos)
1091 tail = line[pos:]
1095 line = clean_lines.elided[linenum]
1096 delta = line.count(startchar) - line.count(endchar)
1098 return (line, linenum,
1099 FindEndOfExpressionInLine(line, 0, num_open, startchar, endchar))
1103 return (line, clean_lines.NumLines(), -1)
1108 # We'll say it should occur by line 10. Don't forget there's a
1109 # dummy line at the front.
1110 for line in xrange(1, min(len(lines), 11)):
1111 if re.search(r'Copyright', lines[line], re.I): break
1112 else: # means no copyright line was found
1115 'You should have a line: "Copyright [year] <Copyright Owner>"')
1150 lines: An array of strings, each representing a line of the file.
1161 for linenum, line in enumerate(lines):
1162 linesplit = line.split()
1166 # set ifndef to the header guard presented on the #ifndef line.
1171 # find the last occurrence of #endif, save entire line
1172 if line.startswith('#endif'):
1173 endif = line
1214 '#endif line should be "#endif // %s"' % cppvar)
1218 """Logs an error for each line containing Unicode replacement characters.
1222 it's possible for this to throw off line numbering if the invalid
1227 lines: An array of strings, each representing a line of the file.
1230 for linenum, line in enumerate(lines):
1231 if u'\ufffd' in line:
1233 'Line contains invalid UTF-8 (or Unicode replacement character).')
1241 lines: An array of strings, each representing a line of the file.
1255 """Logs an error if we see /* ... */ or "..." that extend past one line.
1257 /* ... */ comments are legit inside macros, for one line.
1260 lines, as long as a line continuation character (backslash)
1261 terminates each line. Although not currently prohibited by the C++
1268 linenum: The number of the line to check.
1271 line = clean_lines.elided[linenum]
1273 # Remove all \\ (escaped backslashes) from the line. They are OK, and the
1275 line = line.replace('\\\\', '')
1277 if line.count('/*') > line.count('*/'):
1279 'Complex multi-line /*...*/-style comment found. '
1283 'or with more clearly structured multi-line comments.')
1285 if (line.count('"') - line.count('\\"')) % 2:
1287 'Multi-line string ("...") found. This lint script doesn\'t '
1321 linenum: The number of the line to check.
1324 line = clean_lines.elided[linenum]
1326 ix = line.find(single_thread_function)
1328 if ix >= 0 and (ix == 0 or (not line[ix - 1].isalnum() and
1329 line[ix - 1] not in ('_', '.', '>'))):
1355 linenum: The number of the line to check.
1358 line
1359 if _RE_PATTERN_INVALID_INCREMENT.match(line):
1382 linenum: The number of the line to check.
1395 linenum: The number of the line to check.
1422 line = clean_lines.elided[i]
1423 depth += line.count('{') - line.count('}')
1444 line = clean_lines.raw_lines[linenum]
1458 and not Match(r'};*\s*(//|/\*).*\bnamespace\b', line)):
1477 line):
1483 if not Match(r'};*\s*(//|/\*).*\bnamespace[\*/\.\\\s]*$', line):
1534 def UpdatePreprocessor(self, line):
1554 line: current line to check.
1556 if Match(r'^\s*#\s*(if|ifdef|ifndef)\b', line):
1560 elif Match(r'^\s*#\s*(else|elif)\b', line):
1575 elif Match(r'^\s*#\s*endif\b', line):
1592 """Update nesting state with current line.
1597 linenum: The number of the line to check.
1600 line = clean_lines.elided[linenum]
1603 self.UpdatePreprocessor(line)
1609 depth_change = line.count('(') - line.count(')')
1616 _MATCH_ASM.match(line)):
1620 # Not entering assembly block. If previous line was _END_ASM,
1628 # Consume namespace declaration at the beginning of the line. Do
1629 # this in a loop so that we catch same line declarations like this:
1636 namespace_decl_match = Match(r'^\s*namespace\b\s*([:\w]+)?(.*)$', line)
1643 line = namespace_decl_match.group(2)
1644 if line.find('{') != -1:
1646 line = line[line.find('{') + 1:]
1648 # Look for a class declaration in whatever is left of the line
1672 '(([^=>]|<[^<>]*>)*)$', line)
1678 line = class_decl_match.group(5)
1687 access_match = Match(r'\s*(public|private|protected)\s*:', line)
1691 # Consume braces or semicolons from what's left of the line
1694 matched = Match(r'^[^{;)}]*([{;)}])(.*)$', line)
1707 if _MATCH_ASM.match(line):
1725 line = matched.group(2)
1779 linenum: The number of the line to check.
1783 filename, line number, error level, and message
1786 line, but leave in strings for now.
1787 line = clean_lines.lines[linenum]
1789 if Search(r'printf\s*\(.*".*%[-+ ]?\d*q', line):
1793 if Search(r'printf\s*\(.*".*%\d+\$', line):
1798 line = line.replace('\\\\', '')
1800 if Search(r'("|\').*\\(%|\[|\(|{)', line):
1805 line = clean_lines.elided[linenum]
1811 line):
1815 if Match(r'\s*#\s*endif\s*[^/\s]+', line):
1819 if Match(r'\s*class\s+(\w+\s*::\s*)+\w+\s*;', line):
1821 'Inner-style forward declarations are invalid. Remove this line.')
1824 line):
1828 if Search(r'^\s*const\s*string\s*&\s*\w+\s*;', line):
1855 line)
1864 def CheckSpacingForFunctionCall(filename, line, linenum, error):
1869 line: The text of the line to check.
1870 linenum: The number of the line to check.
1878 fncall = line # if there's no control flow construct, look at whole line
1883 match = Search(pattern, line)
1928 'Closing ) should be moved to the previous line')
1934 def IsBlankLine(line):
1935 """Returns true if the given line is blank.
1937 We consider a line to be blank if the line is empty or consists of
1941 line: A line of a string.
1944 True, if the given line is blank.
1946 return not line or line.isspace()
1963 NOLINT *on the last line of a function* disables this check.
1968 linenum: The number of the line to check.
1973 line = lines[linenum]
1980 match_result = Match(regexp, line)
1999 function = Search(r'((\w|:)*)\(', line).group(1)
2012 elif Match(r'^\}\s*$', line): # function end
2015 elif not Match(r'^\s*$', line):
2026 comment: The text of the comment from the line in question.
2028 linenum: The number of the line to check.
2057 linenum: The number of the line to check.
2062 line = clean_lines.elided[linenum] # get rid of comments and strings
2066 r'DISALLOW_IMPLICIT_CONSTRUCTORS)'), line)
2087 linenum: Current line number.
2088 init_suffix: Remainder of the current line after the initial <.
2093 line = init_suffix
2105 match = Search(r'^[^<>(),;\[\]]*([<>(),;\[\]])(.*)$', line)
2109 line = match.group(2)
2140 # Scan the next line
2144 line = clean_lines.elided[linenum]
2157 linenum: Current line number.
2158 init_prefix: Part of the current line before the initial >.
2163 line = init_prefix
2167 match = Search(r'^(.*)([<>(),;\[\]])[^<>(),;\[\]]*$', line)
2171 line = match.group(1)
2199 # Scan the previous line
2203 line = clean_lines.elided[linenum]
2215 line, don't end a function with a blank line, don't add a blank line
2221 linenum: The number of the line to check.
2228 line = raw[linenum]
2230 # Before nixing comments, check if the line is blank for no good
2231 # reason. This includes the first line after a block is opened, and
2232 # blank lines at the end of a function (ie, right before a line like '}'
2234 # Skip all the blank line checks if we are immediately inside a
2235 # namespace body. In other words, don't issue blank line warnings
2242 if IsBlankLine(line) and not nesting_state.InNamespaceBody():
2246 # TODO(unknown): Don't complain if line before blank line, and line after,
2251 # OK, we have a blank line at the start of a code block. Before we
2253 # non-empty line has the parameters of a function header that are indented
2254 # 4 spaces (because they did not fit in a 80 column line when placed on
2255 # the same line as the function name). We also check for the case where
2256 # the previous line is indented 6 spaces, which may happen when the
2257 # initializers of a constructor do not fit into a 80 column line.
2270 # simple heuristic here: If the line is indented 4 spaces; and we have a
2272 # or colon (for initializer lists) we assume that it is the last line of
2281 'Blank line at the start of a code block. Is this needed?')
2285 # // Something followed by a blank line
2296 'Blank line at the end of a code block. Is this needed?')
2301 'Do not leave a blank line after "%s:"' % matched.group(1))
2304 commentpos = line.find('//')
2308 if (line.count('"', 0, commentpos) -
2309 line.count('\\"', 0, commentpos)) % 2 == 0: # not in quotes
2311 if (not Match(r'^\s*{ //', line) and
2313 line[commentpos-1] not in string.whitespace) or
2315 line[commentpos-2] not in string.whitespace))):
2320 if commentend < len(line) and not line[commentend] == ' ':
2328 match = (Search(r'[=/-]{4,}\s*$', line[commentend:]) or
2329 Search(r'^/$', line[commentend:]) or
2330 Search(r'^/+ ', line[commentend:]))
2334 CheckComment(line[commentpos:], filename, linenum, error)
2336 line = clean_lines.elided[linenum] # get rid of comments and strings
2339 line = re.sub(r'operator(==|!=|<|<<|<=|>=|>>|>)\(', 'operator\(', line)
2345 if Search(r'[\w.]=[\w.]', line) and not Search(r'\b(if|while) ', line):
2357 match = Search(r'[^<>=!\s](==|!=|<=|>=)[^<>=!\s]', line)
2363 match = Search(r'(\S)(?:L|UL|ULL|l|ul|ull)?<<(\S)', line)
2367 elif not Match(r'#.*include', line):
2369 reduced_line = line.replace('->', '')
2403 match = Search(r'>>[a-zA-Z_]', line)
2409 match = Search(r'(!\s|~\s|[\s]--[\s;]|[\s]\+\+[\s;])', line)
2415 match = Search(r' (if\(|for\(|while\(|switch\()', line)
2427 line)
2432 not match.group(2) and Search(r'\bfor\s*\(.*; \)', line)):
2441 if Search(r',[^\s]', line):
2449 if Search(r';[^\s};\\)/]', line):
2454 CheckSpacingForFunctionCall(filename, line, linenum, error)
2458 # braces. And since you should never have braces at the beginning of a line,
2460 if Search(r'[^ ({]{', line):
2465 if Search(r'}else', line):
2471 if Search(r'\w\s+\[', line) and not Search(r'delete\s+\[', line):
2475 # You shouldn't have a space before a semicolon at the end of the line.
2478 if Search(r':\s*;\s*$', line):
2481 elif Search(r'^\s*;\s*$', line):
2483 'Line contains only semicolon. If this should be an empty statement, '
2485 elif (Search(r'\s+;\s*$', line) and
2486 not Search(r'\bfor\b', line)):
2493 if (Search('for *\(.*[^:]:[^: ]', line) or
2494 Search('for *\(.*[^: ]:[^:]', line)):
2500 """Checks for additional blank line issues related to sections.
2502 Currently the only thing checked here is blank line before protected/private.
2508 linenum: The number of the line to check.
2516 # Also skip checks if we are on the first line. This accounts for
2528 # Issue warning if the line before public/protected/private was
2529 # not a blank line, but don't do this if the previous line contains
2534 # Also ignores cases where the previous line ends with a backslash as can be
2541 # account for multi-line base-specifier lists, e.g.:
2551 line' % matched.group(1))
2555 """Return the most recent non-blank line and its line number.
2559 linenum: The number of the line to check.
2563 non-blank line before the current line, or the empty string if this is the
2564 first non-blank line. The second is the line number of that line, or -1
2565 if this is the first non-blank line.
2571 if not IsBlankLine(prevline): # if not a blank line...
2578 """Looks for misplaced braces (e.g. at the end of line).
2583 linenum: The number of the line to check.
2587 line = clean_lines.elided[linenum] # get rid of comments and strings
2589 if Match(r'\s*{\s*$', line):
2590 # We allow an open brace to start a line in the case where someone
2595 # previous non-blank line is ';', ':', '{', or '}', or if the previous
2596 # line starts a preprocessor block.
2601 '{ should almost always be at the end of the previous line')
2603 # An else clause should be on the same line as the preceding closing brace.
2604 if Match(r'\s*else\s*', line):
2608 'An else should appear on the same line as the preceding }')
2612 if Search(r'}\s*else[^{]*$', line) or Match(r'[^}]*else\s*{', line):
2613 if Search(r'}\s*else if([^{]*)$', line): # could be multi-line if
2615 pos = line.find('else if')
2616 pos = line.find('(', pos)
2622 else: # common case: else not followed by a multi-line if
2626 # Likewise, an else should never have the else clause on the same line
2627 if Search(r'\belse [^\s{]', line) and not Search(r'\belse if\b', line):
2629 'Else clause should never be on same line as else (use 2 lines)')
2631 # In the same way, a do/while should never be on one line
2632 if Match(r'\s*do [^\s{]', line):
2634 'do/while clauses should not be on a single line')
2642 if Match(r'\s+{.*}\s*;', line) and not prevline.count(';'):
2643 line = prevline + line
2646 if (Search(r'{.*}\s*;', line) and
2647 line.count('{') == line.count('}') and
2648 not Search(r'struct|class|enum|\s*=\s*{', line)):
2659 linenum: The number of the line to check.
2663 # Search for loop keywords at the beginning of the line. Because only
2666 line = clean_lines.elided[linenum]
2667 if Match(r'\s*(for|while)\s*\(', line):
2670 clean_lines, linenum, line.find('('))
2680 def ReplaceableCheck(operator, macro, line):
2689 line: The current source line.
2712 return Match(match_this, line) and not Search(r'NULL|&&|\|\|', line)
2721 linenum: The number of the line to check.
2733 # Don't waste time here if line doesn't contain 'CHECK' or 'EXPECT'
2736 line = clean_lines.elided[linenum] # get rid of comments and strings
2740 if ReplaceableCheck(operator, current_macro, line):
2754 linenum: The number of the line to check.
2757 line = clean_lines.elided[linenum]
2760 if Match(r'^\s*#', line):
2763 # Last ditch effort to avoid multi-line comments. This will not help
2764 # if the comment started before the current line or ended after the
2765 # current line, but it catches most of the false positives. At least,
2767 # multi-line comments in preprocessor macros.
2770 # multi-line comments.
2771 if line.find('/*') >= 0 or line.find('*/') >= 0:
2774 for match in _ALT_TOKEN_REPLACEMENT_PATTERN.finditer(line):
2780 def GetLineWidth(line):
2781 """Determines the width of the line in column positions.
2784 line: A string, which may be a Unicode string.
2787 The width of the line in column positions, accounting for Unicode
2790 if isinstance(line, unicode):
2792 for uc in unicodedata.normalize('NFC', line):
2799 return len(line)
2807 do what we can. In particular we check for 2-space indents, line lengths,
2813 linenum: The number of the line to check.
2821 line = raw_lines[linenum]
2823 if line.find('\t') != -1:
2827 # One or three blank spaces at the beginning of the line is weird; it's
2841 while initial_spaces < len(line) and line[initial_spaces] == ' ':
2843 if line and line[-1].isspace():
2845 'Line ends in whitespace. Consider deleting these extra spaces.')
2850 'Weird number of spaces at line-start. '
2853 elif not initial_spaces and line[:2] != '//' and Search(r'[^:]:\s*$',
2854 line):
2859 'be on the following line.')
2862 # Check if the line is a header guard.
2866 if (line.startswith('#ifndef %s' % cppvar) or
2867 line.startswith('#define %s' % cppvar) or
2868 line.startswith('#endif // %s' % cppvar)):
2878 if (not line.startswith('#include') and not is_header_guard and
2879 not Match(r'^\s*//.*http(s?)://\S*$', line) and
2880 not Match(r'^// \$Id:.*#[0-9]+ \$$', line)):
2881 line_width = GetLineWidth(line)
2894 # It's ok to have many commands in a switch case that fits in 1 line
2899 'More than one command on the same line')
3031 Strings on #include lines are NOT removed from elided line, to make
3038 linenum: The number of the line to check.
3044 line = clean_lines.lines[linenum]
3047 if _RE_PATTERN_INCLUDE_NEW_STYLE.search(line):
3054 match = _RE_PATTERN_INCLUDE.search(line)
3087 match = _RE_PATTERN_INCLUDE.match(line)
3110 It can be single line and can span multiple lines.
3163 linenum: The number of the line to check.
3168 # If the line is empty or consists of entirely a comment, no need to
3170 line = clean_lines.elided[linenum]
3171 if not line:
3174 match = _RE_PATTERN_INCLUDE.search(line)
3181 # line.
3183 extended_line = line + clean_lines.elided[linenum + 1]
3185 extended_line = line
3198 # Don't check the implementation on same line.
3199 fnline = line.split('{', 1)[0]
3223 r'(int|float|double|bool|char|int32|uint32|int64|uint64)\([^)]', line)
3231 not (Match(r'^\s*MOCK_(CONST_)?METHOD\d+(_T)?\(', line) or
3232 Match(r'^\s*MockCallback<.*>', line))):
3238 # to check the previous line for MOCK_METHOD.
3247 CheckCStyleCast(filename, linenum, line, clean_lines.raw_lines[linenum],
3255 if CheckCStyleCast(filename, linenum, line, clean_lines.raw_lines[linenum],
3260 CheckCStyleCast(filename, linenum, line, clean_lines.raw_lines[linenum],
3267 r'(&\([^)]+\)[\w(])|(&(static|dynamic|reinterpret)_cast\b)', line):
3278 line)
3290 if Search(r'\bdynamic_cast<', line) and not _IsTestFilename(filename):
3296 if Search(r'\b([A-Za-z0-9_]*_)\(\1\)', line):
3310 if Search(r'\bshort port\b', line):
3311 if not Search(r'\bunsigned short port\b', line):
3315 match = Search(r'\b(short|long(?! +double)|long long)\b', line)
3321 match = Search(r'snprintf\s*\(([^,]*),\s*([0-9]*)\s*,', line)
3329 if Search(r'\bsprintf\b', line):
3332 match = Search(r'\b(strcpy|strcat)\b', line)
3337 if Search(r'\bsscanf\b', line):
3342 # TODO(unknown): catch out-of-line unary operator&:
3347 if Search(r'\boperator\s*&\s*\(\s*\)', line):
3353 if Search(r'\}\s*if\s*\(', line):
3355 'Did you mean "else if"? If not, start a new line for "if".')
3361 # convention of the whole function to process multiple line to handle it.
3364 printf_args = _GetTextInside(line, r'(?i)\b(string)?printf\s*\(')
3369 line, re.I).group(1)
3375 match = Search(r'memset\s*\(([^,]*),\s*([^,]*),\s*0\s*\)', line)
3381 if Search(r'\busing namespace\b', line):
3387 match = Match(r'\s*(.+::)?(\w+) [a-z]\w*\[(.+)];', line)
3432 line)
3449 and Search(r'\bnamespace\s*{', line)
3450 and line[-1] != '\\'):
3457 def CheckCStyleCast(filename, linenum, line, raw_line, cast_type, pattern,
3465 linenum: The number of the line to check.
3466 line: The line of code to check.
3467 raw_line: The raw line of code to check, with comments.
3477 match = Search(pattern, line)
3482 sizeof_match = Match(r'.*sizeof\s*$', line[0:match.start(1) - 1])
3489 if (line[0:match.start(1) - 1].endswith(' operator++') or
3490 line[0:match.start(1) - 1].endswith(' operator--')):
3493 remainder = line[match.end(0):]
3655 for line in headerfile:
3657 clean_line = CleanseComments(line)
3689 line = clean_lines.elided[linenum]
3690 if not line or line[0] == '#':
3694 matched = _RE_PATTERN_STRING.search(line)
3697 # (We check only the first match per line; good enough.)
3698 prefix = line[:matched.start()]
3703 if pattern.search(line):
3707 if not '<' in line: # Reduces the cpu time usage by skipping lines.
3711 if pattern.search(line):
3772 linenum: The number of the line to check.
3776 line = raw[linenum]
3777 match = _RE_PATTERN_EXPLICIT_MAKEPAIR.search(line)
3785 def ProcessLine(filename, file_extension, clean_lines, line,
3788 """Processes a single line in the file.
3793 clean_lines: An array of strings, each representing a line of the file,
3795 line: Number of line being processed.
3801 filename, line number, error level, and message
3803 run on each source line. Each function takes 4
3804 arguments: filename, clean_lines, line, error
3807 ParseNolintSuppressions(filename, raw_lines[line], line, error)
3808 nesting_state.Update(filename, clean_lines, line, error)
3811 CheckForFunctionLengths(filename, clean_lines, line, function_state, error)
3812 CheckForMultilineCommentsAndStrings(filename, clean_lines, line, error)
3813 CheckStyle(filename, clean_lines, line, file_extension, nesting_state, error)
3814 CheckLanguage(filename, clean_lines, line, file_extension, include_state,
3816 CheckForNonStandardConstructs(filename, clean_lines, line,
3818 CheckPosixThreading(filename, clean_lines, line, error)
3819 CheckInvalidIncrement(filename, clean_lines, line, error)
3820 CheckMakePairUsesDeduction(filename, clean_lines, line, error)
3822 check_fn(filename, clean_lines, line, error)
3831 lines: An array of strings, each representing a line of the file, with the
3834 filename, line number, error level, and message
3836 run on each source line. Each function takes 4
3837 arguments: filename, clean_lines, line, error
3839 lines = (['// marker so line numbers and indices both start at 1'] + lines +
3840 ['// marker so line numbers end in a known way'])
3855 for line in xrange(clean_lines.NumLines()):
3856 ProcessLine(filename, file_extension, clean_lines, line,
3879 run on each source line. Each function takes 4
3880 arguments: filename, clean_lines, line, error
3960 """Parses the command line arguments.
3965 args: The command line arguments: