Loading pylint_reporter/reporter.py +26 −3 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ Module providing a Pylint plugin import json import pylint.config import pylint.reporters Loading @@ -27,7 +28,8 @@ class JSONStatsReporter: Serialise reports and stats to a JSON file """ def __init__(self, parent=None): def __init__(self, options, parent=None): self.options = options self.parent = parent or pylint.reporters.BaseReporter() self.messages = [] Loading Loading @@ -55,10 +57,28 @@ class JSONStatsReporter: stats=stats, previous=previous_stats, ) with open('.lint.json', 'w') as fout: with open(self.options.config.json_output, 'w') as fout: json.dump(report, fout, default=serialiser, indent=4) class JSONStatsOptions(pylint.config.OptionsProviderMixIn): """Options for the JSONStatsReporter plugin""" name = 'json_stats' options = ( ( "json-output", { "type": "string", "dest": "json_output", "default": "lint.json", "metavar": "<output-json>", "help": "The filename to output JSON serialised results and stats", } ), ) def serialiser(obj): """Serialise sets as JSON arrays""" if isinstance(obj, set): Loading @@ -68,8 +88,11 @@ def serialiser(obj): def register(linter): """Pylint plugin entrypoint function""" options = JSONStatsOptions() linter.register_options_provider(options) def set_reporter(reporter): org_set_reporter(JSONStatsReporter(reporter)) org_set_reporter(JSONStatsReporter(options, reporter)) linter.set_reporter, org_set_reporter = set_reporter, linter.set_reporter set_reporter(linter.reporter) Loading Loading
pylint_reporter/reporter.py +26 −3 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ Module providing a Pylint plugin import json import pylint.config import pylint.reporters Loading @@ -27,7 +28,8 @@ class JSONStatsReporter: Serialise reports and stats to a JSON file """ def __init__(self, parent=None): def __init__(self, options, parent=None): self.options = options self.parent = parent or pylint.reporters.BaseReporter() self.messages = [] Loading Loading @@ -55,10 +57,28 @@ class JSONStatsReporter: stats=stats, previous=previous_stats, ) with open('.lint.json', 'w') as fout: with open(self.options.config.json_output, 'w') as fout: json.dump(report, fout, default=serialiser, indent=4) class JSONStatsOptions(pylint.config.OptionsProviderMixIn): """Options for the JSONStatsReporter plugin""" name = 'json_stats' options = ( ( "json-output", { "type": "string", "dest": "json_output", "default": "lint.json", "metavar": "<output-json>", "help": "The filename to output JSON serialised results and stats", } ), ) def serialiser(obj): """Serialise sets as JSON arrays""" if isinstance(obj, set): Loading @@ -68,8 +88,11 @@ def serialiser(obj): def register(linter): """Pylint plugin entrypoint function""" options = JSONStatsOptions() linter.register_options_provider(options) def set_reporter(reporter): org_set_reporter(JSONStatsReporter(reporter)) org_set_reporter(JSONStatsReporter(options, reporter)) linter.set_reporter, org_set_reporter = set_reporter, linter.set_reporter set_reporter(linter.reporter) Loading