Skip to content

Commit

Permalink
Add GitHub reporter
Browse files Browse the repository at this point in the history
A new `github` reporter has been added. This reporter automatically
annotates code on GitHub's UI with the messages found during linting.

Closes pylint-dev#9443.
  • Loading branch information
crazybolillo committed Mar 5, 2024
1 parent fd80514 commit 7defa64
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 4 additions & 0 deletions doc/whatsnew/fragments/9443.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
A new `github` reporter has been added. This reporter automatically annotates code on GitHub's UI with the messages
found during linting. Use it with `pylint --output-format=github`.

Closes #9443.
13 changes: 10 additions & 3 deletions pylint/reporters/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,9 @@ class ColorizedTextReporter(TextReporter):
}

def __init__(
self,
output: TextIO | None = None,
color_mapping: ColorMappingDict | None = None,
self,
output: TextIO | None = None,
color_mapping: ColorMappingDict | None = None,
) -> None:
super().__init__(output)
self.color_mapping = color_mapping or ColorizedTextReporter.COLOR_MAPPING
Expand Down Expand Up @@ -255,9 +255,16 @@ def handle_message(self, msg: Message) -> None:
self.write_message(msg)


class GithubReporter(TextReporter):
"""Report messages in GitHub's special format to annotate code in their UI."""
name = "github"
line_format = "::error file={path},line={line},endline={end_line},col={col},title={msg_id}::{msg}"


def register(linter: PyLinter) -> None:
linter.register_reporter(TextReporter)
linter.register_reporter(NoHeaderReporter)
linter.register_reporter(ParseableTextReporter)
linter.register_reporter(VSTextReporter)
linter.register_reporter(ColorizedTextReporter)
linter.register_reporter(GithubReporter)

0 comments on commit 7defa64

Please sign in to comment.