def run_check(self, ctx: RunContext): # noqa """Check code with vulture.""" params = ctx.get_params("vulture") options = ctx.options if options: params.setdefault("min-confidence", options.vulture_min_confidence) params.setdefault("ignore-names", options.vulture_ignore_names) params.setdefault("ignore-decorators", options.vulture_ignore_decorators) config = make_config(parse_params(ctx.filename, params)) vulture = Vulture( verbose=config["verbose"], ignore_names=config["ignore_names"], ignore_decorators=config["ignore_decorators"], ) vulture.scan(ctx.source, filename=ctx.filename) unused_code_items = vulture.get_unused_code( min_confidence=config["min_confidence"], sort_by_size=config["sort_by_size"]) for item in unused_code_items: error_code = ERROR_CODES[item.typ] ctx.push( source="vulture", type="R", lnum=item.first_lineno, number=error_code, text=f"{item.message} ({item.confidence}% confidence)", )
self.file_path = file_path self.first_lineno = first_lineno self.last_lineno = last_lineno self.reason = reason def run(self): pass def __repr__(self): return str(self.__dict__) if __name__ == '__main__': options, args = _parse_args() vulture = Vulture(verbose=options.verbose) vulture.scavenge(args, exclude=options.exclude) code_items = vulture.get_unused_code(min_confidence=90, sort_by_size=options.sort_by_size) DELETION_JOBS = [] for item in code_items: DELETION_JOBS.append( DeletionJob(file_path=utils.format_path(item.filename), first_lineno=item.first_lineno, last_lineno=item.last_lineno, reason=item.message + ' ({}% confidence)'.format(item.confidence))) print(DELETION_JOBS)