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)", )
class Events(QWidget): def __init__(self, text=None, file_name=None): super().__init__() self.dead_code = None self.info_bar = QTextEdit() self.font = QFont("Iosevka", 11) self.label = QLabel("Events") self.info_bar.setFont(self.font) self.buttons_layout = QHBoxLayout() self.layout = QVBoxLayout(self) self.info_bar.setReadOnly(True) self.layout.addLayout(self.buttons_layout) self.buttons_layout.addWidget(self.label) self.layout.addWidget(self.info_bar) self.setStyleSheet( """ background-color: transparent; """ ) def look_for_dead_code(self, text): self.vultureObject = Vulture() self.vultureObject.scan(text) with io.StringIO() as buf, redirect_stdout(buf): self.vultureObject.report() output = buf.getvalue() info = output.replace(":", "").split() formatted_info = [] unformatted_info = [] for word in info: try: integer = int(word) new_word = '<h5 style="color: #78ffd6; ">Line {} </h5>'.format(integer) formatted_info.append("\n") formatted_info.append(new_word) unformatted_info.append("\n") unformatted_info.append("Line {}".format(integer)) except ValueError: formatted_info.append("<font color=#dd3e54>" + word + "</font>") unformatted_info.append(word) self.dead_code = " ".join(formatted_info) self.info_bar.setText(self.dead_code)
class DeadCodeCheker(QThread): doneSignal = pyqtSignal(bool) infoSignal = pyqtSignal(str) def __init__(self): super(DeadCodeCheker, self).__init__() self.text = None self.events_class = None def add_args(self, text): self.text = text self.events_class = Events def run(self): self.vultureObject = Vulture() self.vultureObject.scan(self.text) with io.StringIO() as buf, redirect_stdout(buf): self.vultureObject.report() output = buf.getvalue() info = output.replace(":", "").split() formatted_info = [] unformatted_info = [] for word in info: try: integer = int(word) new_word = '<h5 style="color: #78ffd6; ">Line {} </h5>'.format(integer) formatted_info.append("\n") formatted_info.append(new_word) unformatted_info.append("\n") unformatted_info.append("Line {}".format(integer)) except ValueError: formatted_info.append("<font color=#dd3e54>" + word + "</font>") unformatted_info.append(word) self.dead_code = " ".join(formatted_info) self.doneSignal.emit(True) self.infoSignal.emit(self.dead_code)
class DeadCodeChecker(): def __init__(self, text): self.vultureObject = Vulture() self.vultureObject.scan(text) def getString(self): with io.StringIO() as buf, redirect_stdout(buf): self.vultureObject.report() output = buf.getvalue() newOutput = output.replace(':', '') return newOutput def getList(self): with io.StringIO() as buf, redirect_stdout(buf): self.vultureObject.report() output = buf.getvalue() newOutput = output.replace(':', '').split('\n') return newOutput