def print_check_stats(): num_checks = 0 all_checks = collections.defaultdict(list) for lang in langs: checks = list_checks(lang) all_checks[lang].append(checks) num_checks += len(checks) logger.info("%d langs, %d checks supported", len(langs), num_checks) logger.debug("Langs: %s", langs) logger.debug("Checks: %s", checks)
def print_check_stats(): num_checks = 0 all_checks = collections.defaultdict(list) langs = list_langs() for lang in langs: checks = list_checks(lang) all_checks[lang].append(checks) num_checks += len(checks) print("{} langs, {} checks supported".format(len(langs), num_checks)) # TODO(bzz): debug log level print("Langs: ", langs) print("Checks: ", checks)
def notify_review_event(self, request, context): logger.debug("got review request %s", request) comments = [] # client connection to DataServe with create_channel(data_srv_addr, interceptors=[ LogUnaryClientInterceptor(log_fn), LogStreamClientInterceptor(log_fn), ]) as channel: stub = DataStub(channel) changes = stub.get_changes( context, pb.ChangesRequest(head=request.commit_revision.head, base=request.commit_revision.base, want_contents=False, want_uast=True, exclude_vendored=True, include_languages=langs)) for change in changes: if not change.HasField("head"): continue logger.debug("analyzing '%s' in %s", change.head.path, change.head.language) try: check_results = run_checks( list_checks(change.head.language.lower()), change.head.language.lower(), change.head.uast) except Exception as e: logger.exception( "Error during analyzing file '%s' in commit '%s': %s", change.head.path, request.commit_revision.head.hash, e) continue for check in check_results: for res in check_results[check]: comments.append( pb.Comment(file=change.head.path, line=(res.get("pos", {}) or {}).get("line", 0), text="{}: {}".format(check, res["msg"]))) logger.info("%d comments produced", len(comments)) return pb.EventResponse(analyzer_version=version, comments=comments)
def NotifyReviewEvent(self, request, context): print("got review request {}".format(request)) # client connection to DataServe channel = grpc.insecure_channel(data_srv_addr, options=[ ("grpc.max_send_message_length", grpc_max_msg_size), ("grpc.max_receive_message_length", grpc_max_msg_size), ]) stub = service_data_pb2_grpc.DataStub(channel) changes = stub.GetChanges( service_data_pb2.ChangesRequest( head=request.commit_revision.head, base=request.commit_revision.base, want_contents=False, want_uast=True, exclude_vendored=True)) comments = [] for change in changes: print("analyzing '{}' in {}".format(change.head.path, change.head.language)) check_results = run_checks( list_checks(change.head.language.lower()), change.head.language.lower(), change.head.uast ) n = 0 for check in check_results: for res in check_results[check]: comments.append( service_analyzer_pb2.Comment( file=change.head.path, line=res["pos"]["line"] if res and "pos" in res and res["pos"] and "line" in res["pos"] else 0, text="{}: {}".format(check, res["msg"]))) n += 1 print("{} comments produced".format(n)) return service_analyzer_pb2.EventResponse(analyzer_version=version, comments=comments)
def _list(lang): for check in list_checks(lang): print("{} : {}".format(check, get_check_description(check, lang)))
def parse_arguments() -> argparse.Namespace: parser = argparse.ArgumentParser() parser.add_argument("-l", "--language", type=str, help="Language for the file or listings", required=True) parser.add_argument("-i", "--ip", type=str, help="Server IP", default="0.0.0.0") parser.add_argument("-p", "--port", type=str, help="Server port", default="9432") parser.add_argument("-d", "--disable", type=str, help="Disable specific checks") parser.add_argument( "-e", "--enable", type=str, help="Enable only specific checks. If ommited, all will be run") parser.add_argument("-L", "--list", action="store_true", help="List all avaliable checks") parser.add_argument("file", type=str, nargs="?", help="Input file to parse") args = parser.parse_args() def _convert_checkname(check): ncheck = check if not check.startswith("RSPEC-"): if not check.isdigit(): print( "Wrong check format, use RSPEC-#### or just the number: ", check) parser.print_help() sys.exit(1) else: ncheck = "RSPEC-{}".format(check) return ncheck args.checks: Set[str] = set() if args.enable: args.checks = { _convert_checkname(i.strip()) for i in args.enable.split(",") } else: args.checks = list_checks(args.language) if args.disable: disabled = { _convert_checkname(i.strip()) for i in args.disable.split(",") } for disable in disabled: args.checks.remove(disable) args.checks = list(args.checks) if args.list: _list(args.language) sys.exit(0) return args