Skip to content

Keep file/line in the github reporter's log output#657

Open
wilfison wants to merge 1 commit into
sds:mainfrom
wilfison:fix/github-reporter-log-location
Open

Keep file/line in the github reporter's log output#657
wilfison wants to merge 1 commit into
sds:mainfrom
wilfison:fix/github-reporter-log-location

Conversation

@wilfison

Copy link
Copy Markdown
Contributor

Closes #495

Problem

The github reporter emits GitHub Actions workflow commands like:

::error file=app/views/x.haml,line=12::Message

GitHub moves the file/line of a workflow command into the annotation shown in the "Files changed" tab, so they disappear from the plain Actions log — leaving only the bare message with no location. This makes the log much less useful than the default reporter, which is the trade-off reported in #495.

Change

Enhance Reporter::GithubReporter so the location is preserved in both places:

  • Location stays in the log — the command's message is now prefixed with
    filename:line LinterName:, so the log line reads e.g.
    app/views/x.haml:12 RuboCop: Style/StringLiterals: ... even after GitHub strips the
    file/line into the annotation.
  • Annotations get a titletitle=haml-lint <LinterName> (falling back to haml-lint
    when a lint has no linter), so annotations are labeled and distinguishable from other tools'.
  • Correct escaping — message values escape %, \n, \r; property values (file,
    title, ...) additionally escape the : and , that delimit the command.

Before

::error file=app/views/x.haml,line=12::Avoid defining `class` in attributes hash...

After

::error file=app/views/x.haml,line=12,title=haml-lint ClassAttributeWithStaticValue::app/views/x.haml:12 ClassAttributeWithStaticValue: Avoid defining `class` in attributes hash...

The annotation in the Files tab still works exactly as before; the difference is that the log
now keeps the file, line, and linter name.

Tests

  • Updated the file/line assertions to target the file=/line= command properties.
  • Added coverage for the annotation title, the location/linter prefix in the message (with and
    without an associated linter), and escaping of delimiter characters.
  • bundle exec rspec spec/haml_lint/reporter/github_reporter_spec.rb — 18 examples, 0 failures.
  • bundle exec rubocop lib/haml_lint/reporter/github_reporter.rb — no offenses.

The github reporter emits workflow commands whose `file`/`line` GitHub
moves into the Files-tab annotation, dropping them from the plain Actions
log. Prefix the command message with `filename:line LinterName:` so the
location stays in the log, add a `title=haml-lint <Linter>` to the
annotation, and escape the `:`/`,` delimiters in property values.

Closes sds#495
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow multiple reporters?

1 participant