diff options
author | Ashley Whetter <ashley@awhetter.co.uk> | 2018-03-10 11:41:57 -0800 |
---|---|---|
committer | Ashley Whetter <ashley@awhetter.co.uk> | 2019-02-09 13:39:47 -0800 |
commit | 1ae6c7648ee0d6b3462c70569a772a82154fda69 (patch) | |
tree | a27f96d92cd0670fb26c8efba491b30b230daef8 | |
parent | e319477dca8601b1ecbf196b57ea1c690c7f5c23 (diff) | |
download | pylint-git-1ae6c7648ee0d6b3462c70569a772a82154fda69.tar.gz |
Removed ReportHandlerMixIn methods from plugin registry
-rw-r--r-- | pylint/lint.py | 106 | ||||
-rw-r--r-- | pylint/utils.py | 92 |
2 files changed, 102 insertions, 96 deletions
diff --git a/pylint/lint.py b/pylint/lint.py index e434baccc..f1a6cccab 100644 --- a/pylint/lint.py +++ b/pylint/lint.py @@ -891,9 +891,64 @@ def guess_lint_path(args): return value -# TODO: Split the ReportsHandlerMixIn, keeping register methods here, -# and moving report_order and make_reports to the runner. -class PluginRegistry(utils.ReportsHandlerMixIn): +class ReportRegistry: + def __init__(self): + self.reports = collections.defaultdict(list) + self._reports_state = {} + super().__init__() + + def register_report(self, reportid, r_title, r_cb, checker): + """Register a report + + :param reportid: The unique identifier for the report. + :type reportid: str + :param r_title: The report's title. + :type r_title: str + :param r_cb: The method to call to make the report. + :type r_cb: callable + :param checker: The checker defining the report. + :type checker: BaseChecker + """ + reportid = reportid.upper() + self.reports[checker].append((reportid, r_title, r_cb)) + + def enable_report(self, reportid): + """Enable the report of the given id. + + :param reportid: The unique identifier of the report to enable. + :type reportid: str + """ + reportid = reportid.upper() + self._reports_state[reportid] = True + + def disable_report(self, reportid): + """Disable the report of the given id. + + :param reportid: The unique identifier of the report to disable. + :type reportid: str + """ + reportid = reportid.upper() + self._reports_state[reportid] = False + + def disable_reporters(self): + """Disable all reporters.""" + for _reporters in self.reports.values(): + for report_id, _, _ in _reporters: + self.disable_report(report_id) + + def report_is_enabled(self, reportid): + """Check if the report with the given id is enabled. + + :param reportid: The unique identifier of the report to check. + :type reportid: str + + :returns: True if the report is enabled, False otherwise. + :rtype: bool + """ + return self._reports_state.get(reportid, True) + + +class PluginRegistry(ReportRegistry): """A class to register checkers to.""" def __init__(self, linter, register_options=(lambda options: None)): @@ -906,7 +961,7 @@ class PluginRegistry(utils.ReportsHandlerMixIn): self._linter = linter for r_id, r_title, r_cb in linter.reports: - self.register_post_report(r_id, r_title, r_cb) + self.register_report(r_id, r_title, r_cb, linter) self.register_options(linter.options) @@ -1365,6 +1420,49 @@ group are mutually exclusive.", else: self._reporter.on_close(self._linter.stats, {}) + def report_order(self): + """A list of reports, sorted in the order in which they must be called. + + :returns: The list of reports. + :rtype: list(BaseChecker or object) + """ + reports = self._plugin_registry.reports + reports = sorted(reports, key=lambda x: getattr(x, "name", "")) + try: + reports.remove(self._linter) + except ValueError: + pass + else: + reports.append(self._linter) + return reports + + def make_reports(self, stats, old_stats): + """Render the registered reports. + + :param stats: The statistics dictionary for this run. + :type stats: dict + :param old_stats: The statistics dictionary for the previous run. + :type old_stats: dict + + :returns: The complete report. + :rtype: pylint.reporters.ureports.nodes.Section + """ + sect = report_nodes.Section( + "Report", "%s statements analysed." % (stats["statement"]) + ) + for checker in self.report_order(): + for reportid, r_title, r_cb in self.reports[checker]: + if not self.report_is_enabled(reportid): + continue + report_sect = report_nodes.Section(r_title) + try: + r_cb(report_sect, stats, old_stats) + except EmptyReportError: + continue + report_sect.report_id = reportid + sect.append(report_sect) + return sect + def _report_evaluation(self): """make the global evaluation report""" # check with at least check 1 statements (usually 0 when there is a diff --git a/pylint/utils.py b/pylint/utils.py index 56f8c5f96..9c9db0f0b 100644 --- a/pylint/utils.py +++ b/pylint/utils.py @@ -57,7 +57,6 @@ from astroid import nodes, Module from astroid import modutils from pylint.interfaces import IRawChecker, ITokenChecker, UNDEFINED, implements -from pylint.reporters.ureports.nodes import Section from pylint.exceptions import InvalidMessageError, UnknownMessageError, EmptyReportError @@ -1051,97 +1050,6 @@ class MessagesStore: print("") -class ReportsHandlerMixIn: - """A report handlers organises and calls report methods.""" - - _POST_CHECKER = object() - - def __init__(self): - self._reports = collections.defaultdict(list) - self._reports_state = {} - super().__init__() - - def report_order(self): - """A list of reports, sorted in the order in which they must be called. - - :returns: The list of reports. - :rtype: list(BaseChecker or object) - """ - reports = sorted(self._reports, key=lambda x: getattr(x, "name", "")) - try: - reports.remove(self._POST_CHECKER) - except ValueError: - pass - else: - reports.append(self._POST_CHECKER) - return reports - - def register_report(self, reportid, r_title, r_cb, checker): - """register a report - - :param reportid: The unique identifier for the report. - :type reportid: str - :param r_title: The report's title. - :type r_title: str - :param r_cb: The method to call to make the report. - :type r_cb: callable - :param checker: The checker defining the report. - :type checker: BaseChecker - """ - reportid = reportid.upper() - self._reports[checker].append((reportid, r_title, r_cb)) - - def register_post_report(self, reportid, r_title, r_cb): - """Register a report to run last. - - :param reportid: The unique identifier for the report. - :type reportid: str - :param r_title: The report's title. - :type r_title: str - :param r_cb: The method to call to make the report. - :type r_cb: callable - """ - self.register_report(reportid, r_title, r_cb, self._POST_CHECKER) - - def enable_report(self, reportid): - """disable the report of the given id""" - reportid = reportid.upper() - self._reports_state[reportid] = True - - def disable_report(self, reportid): - """disable the report of the given id""" - reportid = reportid.upper() - self._reports_state[reportid] = False - - def disable_reporters(self): - """Disable all reporters.""" - for _reporters in self._reports.values(): - for report_id, _, _ in _reporters: - self.disable_report(report_id) - - def report_is_enabled(self, reportid): - """return true if the report associated to the given identifier is - enabled - """ - return self._reports_state.get(reportid, True) - - def make_reports(self, stats, old_stats): - """render registered reports""" - sect = Section("Report", "%s statements analysed." % (stats["statement"])) - for checker in self.report_order(): - for reportid, r_title, r_cb in self._reports[checker]: - if not self.report_is_enabled(reportid): - continue - report_sect = Section(r_title) - try: - r_cb(report_sect, stats, old_stats) - except EmptyReportError: - continue - report_sect.report_id = reportid - sect.append(report_sect) - return sect - - def _basename_in_blacklist_re(base_name, black_list_re): """Determines if the basename is matched in a regex blacklist |