Skip to content

Commit

Permalink
Handle edge cases and convert to property
Browse files Browse the repository at this point in the history
  • Loading branch information
kamalq97 committed Dec 10, 2024
1 parent c98b4d7 commit 7485692
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
4 changes: 1 addition & 3 deletions riff/riff.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,7 @@ def main( # dead: disable
for violation in filtered_violations:
logger.error(violation)
if print_github_annotation:
print( # noqa: T201
violation.to_github_annotation(),
)
print(violation.to_github_annotation) # noqa: T201
raise typer.Exit(1)


Expand Down
16 changes: 14 additions & 2 deletions riff/violation.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,21 @@ class Violation(NamedTuple):
column_start: int | None = None
column_end: int | None = None

@property
def to_github_annotation(self: "Violation") -> str:
relativized_path = self.path.relative_to(Path.cwd())
return f'::error file={relativized_path},line={self.line_start},col={self.column_start},endLine={self.line_end},endColumn={self.column_end}::"Ruff ({self.error_code})"'
relative_path = self.path.relative_to(Path.cwd())
annotation_parts = [f'::error file={relative_path}', f'line={self.line_start}']

if self.line_end:
annotation_parts.append(f'endLine={self.line_end}')

if self.column_start:
annotation_parts.append(f'col={self.column_start}')

if self.column_end:
annotation_parts.append(f'endColumn={self.column_end}')

','.join(annotation_parts) + '::"Ruff ({self.error_code})"'

@staticmethod
def parse(raw: dict) -> "Violation":
Expand Down

0 comments on commit 7485692

Please sign in to comment.