Lines Matching full:line

26 #   Line is too long
35 # Line broken before binary operator
39 # Lack of braces around 2+ line flow control body
44 # Anything outside of a function body except line length/whitespace
92 def check_length(line, ln): argument
93 if len(line) > 79 and not line.startswith(' * Copyright'):
97 def check_tabs(line, ln, allow_tabs, seen_tab): argument
99 if '\t' in line:
102 if ' \t' in line:
104 if ' ' in line and seen_tab:
108 def check_trailing_whitespace(line, ln): argument
109 if line and line[-1] in ' \t':
116 warn(ln, 'Multi-line comment begins after code')
117 for line in lines[1:]:
119 if len(line) <= align or line[align] != '*':
120 warn(ln, 'Comment line does not have * aligned with top')
121 elif line[:align].lstrip() != '':
122 warn(ln, 'Garbage before * in comment line')
124 warn(ln, 'Code after end of multi-line comment')
130 def check_preprocessor(line, ln): argument
131 if line.startswith('#'):
135 def check_braces(line, ln): argument
136 # Strip out one-line initializer expressions.
137 line = re.sub(r'=\s*{.*}', '', line)
138 if line.lstrip().startswith('{') and not line.startswith('{'):
140 if re.search(r'{\s*\S', line):
141 warn(ln, 'Code on line after open brace')
142 if re.search(r'\S.*}', line):
143 warn(ln, 'Code on line before close brace')
148 def check_space_before_paren(line, ln): argument
149 for m in re.finditer(r'([\w]+)(\s*)\(', line):
160 if re.search(r' \)', line):
164 def check_parenthesized_return(line, ln): argument
165 if re.search(r'return\s*\(.*\);', line):
169 def check_cast(line, ln): argument
181 for m in re.finditer(r'\(([^(]+)\)(\s*)[a-zA-Z_(]', line):
189 def check_binary_operator(line, ln): argument
191 if re.match(r'\s*' + binop + r'\s', line):
192 warn(ln - 1, 'Line broken before binary operator')
193 for m in re.finditer(r'(\s|\w)' + binop + r'(\s|\w)', line):
203 def check_assignment_in_conditional(line, ln): argument
206 if re.search(r'if\s*\(+\w+\s*=[^=]', line):
210 def indent(line): argument
211 return len(re.match(r'\s*', line).group(0).expandtabs())
214 def check_unbraced_flow_body(line, ln, lines): argument
215 if re.match(r'\s*do$', line):
219 m = re.match(r'\s*(})?\s*else(\s*if\s*\(.*\))?\s*({)?\s*$', line)
223 if (re.match(r'\s*(if|else if|for|while)\s*\(.*\)$', line) or
224 re.match(r'\s*else$', line)):
225 base = indent(line)
231 def check_bad_string_fn(line, ln): argument
233 if re.search(r'\W(strcpy|strcat|sprintf|\w*scanf)\W', line):
237 def check_indentation(line, indented_lines, ln): argument
244 if line.strip() == '':
245 warn(ln, 'Trailing blank line')
248 if line != indented_lines[ln - 1].rstrip('\r\n'):
263 for line in lines:
265 line = line.rstrip('\r\n')
266 seen_tab = seen_tab or ('\t' in line)
268 # Check line structure issues before altering the line.
269 check_indentation(line, indented_lines, ln)
270 check_length(line, ln)
271 check_tabs(line, ln, allow_tabs, seen_tab)
272 check_trailing_whitespace(line, ln)
274 # Strip out single-line comments the contents of string literals.
276 line = re.sub(r'/\*.*?\*/', '', line)
277 line = re.sub(r'"(\\.|[^"])*"', '""', line)
279 # Parse out and check multi-line comments. (Ignore code on
280 # the first or last line; check_comment will warn about it.)
281 if comment or '/*' in line:
282 comment.append(line)
283 if '*/' in line:
289 if '//' in line:
291 line = re.sub(r'//.*/', '', line)
293 if line.startswith('{'):
295 elif line.startswith('}'):
299 check_preprocessor(line, ln)
300 check_braces(line, ln)
301 check_space_before_paren(line, ln)
302 check_parenthesized_return(line, ln)
303 check_cast(line, ln)
304 check_binary_operator(line, ln)
305 check_assignment_in_conditional(line, ln)
306 check_unbraced_flow_body(line, ln, lines)
307 check_bad_string_fn(line, ln)
310 warn(ln, 'Blank line at end of file')