def check_tidy(src_dir): count_lines = 0 count_empty_lines = 0 for (dirpath, dirnames, filenames) in os.walk(src_dir): if any(d in fs.relpath(dirpath, src_dir) for d in skip_dirs): continue files = [ fs.join(dirpath, name) for name in filenames if is_interesting(name) ] if not files: continue for file in files: if is_checked_by_clang(file): formatted = ex.run_cmd_output(' '.join( ['clang-format-3.8', '-style=file', file]), quiet=True) f = open(file + '.formatted', 'w') f.write(formatted) f.close() ex.check_run_cmd('diff', [file, file + '.formatted'], quiet=True) fs.remove(file + '.formatted') for line in fileinput.input(files): if '\t' in line: report_error('TAB character') if '\r' in line: report_error('CR character') if line.endswith(' \n') or line.endswith('\t\n'): report_error('trailing whitespace') if not line.endswith('\n'): report_error('line ends without NEW LINE character') if len(line) - 1 > column_limit: report_error('line exceeds %d characters' % column_limit) if fileinput.isfirstline(): if not CheckLicenser.check(fileinput.filename()): report_error_name_line(fileinput.filename(), None, 'incorrect license') count_lines += 1 if not line.strip(): count_empty_lines += 1 print "* total lines of code: %d" % count_lines print("* total non-blank lines of code: %d" % (count_lines - count_empty_lines)) print "%s* total errors: %d%s" % (TERM_RED if count_err > 0 else TERM_GREEN, count_err, TERM_EMPTY) print return count_err == 0
def check(self, files): for line in fileinput.input(files): for i, rule in enumerate(self.rules): mc = rule.search(line) if mc: self.report_error(self.err_msgs[i]) if fileinput.isfirstline(): if not CheckLicenser.check(fileinput.filename()): self.report_error('incorrect license') self.count_lines += 1 if not line.strip(): self.count_empty_lines += 1
def check_tidy(src_dir): count_lines = 0 count_empty_lines = 0 for (dirpath, dirnames, filenames) in os.walk(src_dir): if any(d in fs.relpath(dirpath, src_dir) for d in skip_dirs): continue files = [ fs.join(dirpath, name) for name in filenames if is_interesting(name) ] if not files: continue for line in fileinput.input(files): if '\t' in line: report_error('TAB character') if '\r' in line: report_error('CR character') if line.endswith(' \n') or line.endswith('\t\n'): report_error('trailing whitespace') if not line.endswith('\n'): report_error('line ends without NEW LINE character') if len(line) - 1 > column_limit: report_error('line exceeds %d characters' % column_limit) if fileinput.isfirstline(): if not CheckLicenser.check(fileinput.filename()): report_error_name_line(fileinput.filename(), None, 'incorrent license') count_lines += 1 if not line.strip(): count_empty_lines += 1 print "* total lines of code: %d" % count_lines print("* total non-blank lines of code: %d" % (count_lines - count_empty_lines)) print "%s* total errors: %d%s" % (TERM_RED if count_err > 0 else TERM_GREEN, count_err, TERM_EMPTY) print return count_err == 0
def check(self, files): for line in fileinput.input(files): if '\t' in line: self.report_error('TAB character') if '\r' in line: self.report_error('CR character') if line.endswith(' \n') or line.endswith('\t\n'): self.report_error('trailing whitespace') if not line.endswith('\n'): self.report_error('line ends without NEW LINE character') if len(line) - 1 > StyleChecker.column_limit: self.report_error('line exceeds %d characters' % StyleChecker.column_limit) if fileinput.isfirstline(): if not CheckLicenser.check(fileinput.filename()): self.report_error('incorrect license') self.count_lines += 1 if not line.strip(): self.count_empty_lines += 1