def report_messages_stats(sect, stats, _): """make messages type report""" if not stats["by_msg"]: # don't print this report when we didn't detected any errors raise exceptions.EmptyReportError() in_order = sorted((value, msg_id) for msg_id, value in stats["by_msg"].items() if not msg_id.startswith("I")) in_order.reverse() lines = ("message id", "occurrences") for value, msg_id in in_order: lines += (msg_id, str(value)) sect.append(report_nodes.Table(children=lines, cols=2, rheaders=1))
def report_by_type_stats( sect: reporter_nodes.Section, stats: LinterStats, old_stats: LinterStats | None, ) -> None: """Make a report of. * percentage of different types documented * percentage of different types with a bad name """ # percentage of different types documented and/or with a bad name nice_stats: dict[str, dict[str, str]] = {} for node_type in ("module", "class", "method", "function"): node_type = cast(Literal["function", "class", "method", "module"], node_type) total = stats.get_node_count(node_type) nice_stats[node_type] = {} if total != 0: undocumented_node = stats.get_undocumented(node_type) documented = total - undocumented_node percent = (documented * 100.0) / total nice_stats[node_type]["percent_documented"] = f"{percent:.2f}" badname_node = stats.get_bad_names(node_type) percent = (badname_node * 100.0) / total nice_stats[node_type]["percent_badname"] = f"{percent:.2f}" lines = [ "type", "number", "old number", "difference", "%documented", "%badname" ] for node_type in ("module", "class", "method", "function"): node_type = cast(Literal["function", "class", "method", "module"], node_type) new = stats.get_node_count(node_type) old = old_stats.get_node_count(node_type) if old_stats else None diff_str = lint_utils.diff_string(old, new) if old else None lines += [ node_type, str(new), str(old) if old else "NC", diff_str if diff_str else "NC", nice_stats[node_type].get("percent_documented", "0"), nice_stats[node_type].get("percent_badname", "0"), ] sect.append(reporter_nodes.Table(children=lines, cols=6, rheaders=1))
def report_messages_by_module_stats(sect, stats, _): """make errors / warnings by modules report""" if len(stats["by_module"]) == 1: # don't print this report when we are analysing a single module raise exceptions.EmptyReportError() by_mod = collections.defaultdict(dict) for m_type in ("fatal", "error", "warning", "refactor", "convention"): total = stats[m_type] for module in stats["by_module"].keys(): mod_total = stats["by_module"][module][m_type] if total == 0: percent = 0 else: percent = float((mod_total) * 100) / total by_mod[module][m_type] = percent sorted_result = [] for module, mod_info in by_mod.items(): sorted_result.append(( mod_info["error"], mod_info["warning"], mod_info["refactor"], mod_info["convention"], module, )) sorted_result.sort() sorted_result.reverse() lines = ["module", "error", "warning", "refactor", "convention"] for line in sorted_result: # Don't report clean modules. if all(entry == 0 for entry in line[:-1]): continue lines.append(line[-1]) for val in line[:-1]: lines.append("%.2f" % val) if len(lines) == 5: raise exceptions.EmptyReportError() sect.append(report_nodes.Table(children=lines, cols=5, rheaders=1))
def report_total_messages_stats(sect, stats, previous_stats): """make total errors / warnings report""" lines = ["type", "number", "previous", "difference"] lines += checkers.table_lines_from_stats( stats, previous_stats, ("convention", "refactor", "warning", "error")) sect.append(report_nodes.Table(children=lines, cols=4, rheaders=1))