def cpplint(self): sys.argv = ['', '--threadnum=4', '--output=xml', self.__dstdir] self.__shower.show() xmlPath = os.path.join(self.__chkdir, 'result.xml') ecnt = 0 with open(xmlPath, 'w') as xmlfile: with redirect.RedirectStdStreams( stdout=self.__shower, stderr=xmlfile, xit=redirect.lazyExit): cpplint.main() ecnt = cpplint._cpplint_state.error_count self.__shower.write('\n') if not ecnt: self.__shower.write('<h2><font color="green">Passed. No error found!</font></h2>') else: self.__shower.write('<h2><font color="red">Failed. Found %d errors!</font></h2>' % ecnt) if ecnt: with redirect.RedirectStdStreams( stdout=self.__shower, stderr=self.__shower, xit=redirect.lazyExit): self.htmlreport(xmlPath) self.__shower.abouttoclose() return ecnt
def main(): args = sys.argv[1:] real = [sys.argv[0]] for arg in args: real += arg.split(':') sys.argv = real cpplint.main()
def main(): files = [] for fn in os.listdir(DIR_SRC): # if not fn.endsiwth(''): fp = os.path.join(DIR_SRC, fn) files.append(fp) #print files print('\n\n%s' % fn.upper()) cpplint.main([fp])
def main(): FILTERS='cpplint --verbose=0 --linelength=100 --filter=-legal/copyright,-build/include_order,-build/c++11,-build/namespaces,-build/class,-build/include,-build/include_subdir,-readability/inheritance,-readability/function,-readability/casting,-readability/namespace,-readability/alt_tokens,-readability/braces,-readability/fn_size,-whitespace/comments,-whitespace/braces,-whitespace/empty_loop_body,-whitespace/indent,-whitespace/newline,-runtime/explicit,-runtime/arrays,-runtime/int,-runtime/references,-runtime/string,-runtime/operator'.split(' ') result = False files = sys.argv[1:] for loopfile in files: newargs = FILTERS + [loopfile] sys.argv = newargs try: cpplint.main() except SystemExit as e: last_result = e.args[0] result = result or last_result if (last_result): write_code_lines(loopfile) sys.exit(result)
def main(): FILTERS = 'cpplint --verbose=0 --linelength=100 --filter=-legal/copyright,-build/include_order,-build/c++11,-build/namespaces,-build/class,-build/include,-build/include_subdir,-readability/inheritance,-readability/function,-readability/casting,-readability/namespace,-readability/alt_tokens,-readability/braces,-readability/fn_size,-whitespace/comments,-whitespace/braces,-whitespace/empty_loop_body,-whitespace/indent,-whitespace/newline,-runtime/explicit,-runtime/arrays,-runtime/int,-runtime/references,-runtime/string,-runtime/operator'.split( ' ') result = False files = sys.argv[1:] for loopfile in files: newargs = FILTERS + [loopfile] sys.argv = newargs try: cpplint.main() except SystemExit as e: last_result = e.args[0] result = result or last_result if (last_result): write_code_lines(loopfile) sys.exit(result)
return 0 return 1 try: import cpplint except ImportError: print('\n >cpplint is not installed!\n') exit_code = cont_check(' >Have you checked cpplint by hand(y/n)?> ') sys.exit(exit_code) git_command = ["git", "diff", "--cached", "--name-only"] process = subprocess.Popen(git_command, stdout=subprocess.PIPE) output, _ = process.communicate() commiting_files = str(output, 'utf-8').split('\n') cpplint_include = ('.cpp', '.hpp') cpplint_files = [f for f in commiting_files if f.endswith(cpplint_include)] if len(cpplint_files): sys.argv = [''] + cpplint_files # Include empty first string try: exit_code = cpplint.main() except SystemExit: print('\n >cpplint failed!\n') inp = ' >Are you sure you still want to continue(y/n)?> ' exit_code = cont_check(inp) sys.exit(exit_code)
# semicolons preceded by whitespace. if end_pos >= 0 and Match(r';', end_line[end_pos:]): if matched.group(1) == 'if': error(filename, end_linenum, 'whitespace/empty_conditional_body', 5, 'Empty conditional bodies should use {}') elif matched.group(1) == 'while' and linenum is not 0 \ and "}" in clean_lines.elided[linenum-1]: # Don't report an error for ros style do-whiles. Works # by checking for a closing brace on the previous # line, since that means it's probably a do-while # loop. return else: error(filename, end_linenum, 'whitespace/empty_loop_body', 5, 'Empty loop bodies should use {} or continue') def main(): args = sys.argv[1:] real = [sys.argv[0]] for arg in args: real += arg.split(':') sys.argv = real cpplint.main() if __name__ == '__main__': main()
script_dir = os.path.dirname(os.path.realpath(__file__)) parser = argparse.ArgumentParser() parser.add_argument('-i', '--includePaths', nargs="+", help='Run linter check in these directories') parser.add_argument('-q', '--quiet', action='store_true', help='Don\'t print anything if no errors are found.') args = parser.parse_args() list_of_files = list() for include_path in args.includePaths: for (dir_path, dir_names, file_names) in os.walk(include_path): for file_name in file_names: if (".h" in file_name) or (".cpp" in file_name): list_of_files += [os.path.join(dir_path, file_name)] repository_path = script_dir + "../../" arg_list = list() arg_list.append("--linelength=200") arg_list.append("--repository=" + repository_path) if (args.quiet): arg_list.append("--quiet") cpplint.main(arg_list + list_of_files)