-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DisabledFormatter to trace disabled lines
- Loading branch information
Showing
5 changed files
with
63 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require "../../spec_helper" | ||
|
||
module Ameba::Formatter | ||
describe DisabledFormatter do | ||
output = IO::Memory.new | ||
subject = DisabledFormatter.new output | ||
|
||
describe "#finished" do | ||
it "writes a final message" do | ||
subject.finished [Source.new ""] | ||
output.to_s.should contain "Disabled rules using inline directives:" | ||
end | ||
|
||
it "writes disabled rules if any" do | ||
Colorize.enabled = false | ||
|
||
path = "source.cr" | ||
s = Source.new("", path).tap do |s| | ||
s.error(ErrorRule.new, 1, 2, "ErrorRule", :disabled) | ||
s.error(NamedRule.new, 2, 2, "NamedRule", :disabled) | ||
end | ||
subject.finished [s] | ||
log = output.to_s | ||
log.should contain "#{path}:1 #{ErrorRule.name}" | ||
log.should contain "#{path}:2 #{NamedRule.name}" | ||
ensure | ||
output.clear | ||
Colorize.enabled = true | ||
end | ||
|
||
it "does not write not-disabled rules" do | ||
s = Source.new("", "source.cr").tap do |s| | ||
s.error(ErrorRule.new, 1, 2, "ErrorRule") | ||
s.error(NamedRule.new, 2, 2, "NamedRule", :disabled) | ||
end | ||
subject.finished [s] | ||
output.to_s.should_not contain ErrorRule.name | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module Ameba::Formatter | ||
# A formatter that shows all disabled line using inline directives. | ||
class DisabledFormatter < BaseFormatter | ||
def finished(sources) | ||
output << "Disabled rules using inline directives: \n\n" | ||
|
||
sources.each do |source| | ||
source.errors.select(&.disabled?).each do |e| | ||
if loc = e.location | ||
output << "#{source.path}:#{loc.line_number}".colorize(:cyan) | ||
output << " #{e.rule.name}\n" | ||
end | ||
end | ||
end | ||
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