-
-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #680 from gjtorikian/abstract-reporter
Abstract reporter
- Loading branch information
Showing
26 changed files
with
783 additions
and
297 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
module HTMLProofer | ||
class Reporter | ||
include HTMLProofer::Utils | ||
|
||
attr_reader :failures | ||
|
||
def initialize(logger: nil) | ||
@logger = logger | ||
end | ||
|
||
def failures=(failures) | ||
@failures = failures.group_by(&:check_name) \ | ||
.transform_values { |issues| issues.sort_by { |issue| [issue.path, issue.line] } } \ | ||
.sort | ||
end | ||
|
||
def report | ||
raise NotImplementedError, 'HTMLProofer::Reporter subclasses must implement #report' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
class HTMLProofer::Reporter::Cli < HTMLProofer::Reporter | ||
def report | ||
msg = failures.each_with_object([]) do |(check_name, failures), arr| | ||
str = ["For the #{check_name} check, the following failures were found:\n"] | ||
|
||
failures.each do |failure| | ||
path_str = blank?(failure.path) ? '' : "* In #{failure.path}" | ||
|
||
line_str = failure.line.nil? ? '' : " (line #{failure.line})" | ||
|
||
status_str = failure.status.nil? ? '' : " (#{failure.status})" | ||
|
||
str << <<~MSG | ||
#{path_str}#{line_str}: | ||
#{failure.description}#{status_str} | ||
MSG | ||
end | ||
|
||
arr << str.join("\n") | ||
end | ||
|
||
@logger.log(:error, msg.join("\n")) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
class MailToOctocat < ::HTMLProofer::Check | ||
def mailto_octocat? | ||
@link.url.raw_attribute == 'mailto:octocat@github.com' | ||
end | ||
|
||
def run | ||
@html.css('a').each do |node| | ||
@link = create_element(node) | ||
|
||
next if @link.ignore? | ||
|
||
return add_failure("Don't email the Octocat directly!", line: @link.line) if mailto_octocat? | ||
end | ||
end | ||
end | ||
|
||
describe HTMLProofer::Reporter do | ||
it 'supports a custom reporter' do | ||
file = File.join(FIXTURES_DIR, 'links', 'mailto_octocat.html') | ||
cassette_name = make_cassette_name(file, {}) | ||
|
||
VCR.use_cassette(cassette_name, record: :new_episodes) do | ||
proofer = make_proofer(file, :file, { checks: ['MailToOctocat'] }) | ||
output = capture_stderr { proofer.run } | ||
expect(output).to include("In #{file} (line 1)") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.