mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Add support for showing end location marker (#200)
* Add support for showing end location marker * Cleanup Reportable method definitions There’s no need for double splats, since they mess up method resolution, and obscure the actual - single (!) - argument - `status`, so… be gone Also, all of the helpers return the constructed `Issue` like a behaving good methods. * Refactor Util#affected_code * Increase max length of trimmed lines to 120 characters * Refactor Issue to use enum instead of a symbol for #status * Optimize Reportable#valid? * Add spec coverage for newly added Util methods * Refactor DotFormatter a bit Make text format moar in line with Crystal spec runner. * Update README.md
This commit is contained in:
parent
8b52dc4b1d
commit
ea98554191
9 changed files with 225 additions and 100 deletions
|
@ -8,7 +8,7 @@ module Ameba::Formatter
|
|||
describe "#started" do
|
||||
it "writes started message" do
|
||||
subject.started [Source.new ""]
|
||||
output.to_s.should eq "Inspecting 1 file.\n\n"
|
||||
output.to_s.should eq "Inspecting 1 file\n\n"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -29,7 +29,7 @@ module Ameba::Formatter
|
|||
describe "#finished" do
|
||||
it "writes a final message" do
|
||||
subject.finished [Source.new ""]
|
||||
output.to_s.should contain "1 inspected, 0 failures."
|
||||
output.to_s.should contain "1 inspected, 0 failures"
|
||||
end
|
||||
|
||||
it "writes the elapsed time" do
|
||||
|
@ -45,7 +45,7 @@ module Ameba::Formatter
|
|||
end
|
||||
subject.finished [s]
|
||||
log = output.to_s
|
||||
log.should contain "1 inspected, 2 failures."
|
||||
log.should contain "1 inspected, 2 failures"
|
||||
log.should contain "DummyRuleError"
|
||||
log.should contain "NamedRuleError"
|
||||
end
|
||||
|
@ -60,7 +60,7 @@ module Ameba::Formatter
|
|||
end
|
||||
subject.finished [s]
|
||||
log = output.to_s
|
||||
log.should contain "> a = 22"
|
||||
log.should contain "> \e[97ma = 22"
|
||||
log.should contain " \e[33m^\e[0m"
|
||||
end
|
||||
|
||||
|
@ -99,7 +99,7 @@ module Ameba::Formatter
|
|||
s.add_issue(DummyRule.new, location: {1, 1},
|
||||
message: "DummyRuleError", status: :disabled)
|
||||
subject.finished [s]
|
||||
output.to_s.should contain "1 inspected, 0 failures."
|
||||
output.to_s.should contain "1 inspected, 0 failures"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,6 +8,65 @@ module Ameba::Formatter
|
|||
subject = Subject.new
|
||||
|
||||
describe Util do
|
||||
describe "#deansify" do
|
||||
it "returns given string without ANSI codes" do
|
||||
str = String.build do |io|
|
||||
io << "foo".colorize.green.underline
|
||||
io << '-'
|
||||
io << "bar".colorize.red.underline
|
||||
end
|
||||
subject.deansify("foo-bar").should eq "foo-bar"
|
||||
subject.deansify(str).should eq "foo-bar"
|
||||
end
|
||||
end
|
||||
|
||||
describe "#trim" do
|
||||
it "trims string longer than :max_length" do
|
||||
subject.trim(("+" * 300), 1).should eq "+"
|
||||
subject.trim(("+" * 300), 3).should eq "+++"
|
||||
subject.trim(("+" * 300), 5).should eq "+ ..."
|
||||
subject.trim(("+" * 300), 7).should eq "+++ ..."
|
||||
end
|
||||
|
||||
it "leaves intact string shorter than :max_length" do
|
||||
subject.trim(("+" * 3), 100).should eq "+++"
|
||||
end
|
||||
|
||||
it "allows to use custom ellipsis" do
|
||||
subject.trim(("+" * 300), 3, "…").should eq "++…"
|
||||
end
|
||||
end
|
||||
|
||||
describe "#context" do
|
||||
it "returns correct pre/post context lines" do
|
||||
source = Source.new <<-EOF
|
||||
# pre:1
|
||||
# pre:2
|
||||
# pre:3
|
||||
# pre:4
|
||||
# pre:5
|
||||
a = 1
|
||||
# post:1
|
||||
# post:2
|
||||
# post:3
|
||||
# post:4
|
||||
# post:5
|
||||
EOF
|
||||
|
||||
subject.context(source.lines, lineno: 6, context_lines: 3)
|
||||
.should eq({<<-PRE.lines, <<-POST.lines
|
||||
# pre:3
|
||||
# pre:4
|
||||
# pre:5
|
||||
PRE
|
||||
# post:1
|
||||
# post:2
|
||||
# post:3
|
||||
POST
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
describe "#affected_code" do
|
||||
it "returns nil if there is no such a line number" do
|
||||
source = Source.new %(
|
||||
|
@ -23,7 +82,7 @@ module Ameba::Formatter
|
|||
)
|
||||
location = Crystal::Location.new("filename", 1, 1)
|
||||
subject.deansify(subject.affected_code(source, location))
|
||||
.should eq "> a = 1\n ^"
|
||||
.should eq "> a = 1\n ^\n"
|
||||
end
|
||||
|
||||
it "returns correct line if it is found" do
|
||||
|
|
|
@ -42,9 +42,22 @@ module Ameba
|
|||
location: nil,
|
||||
end_location: nil,
|
||||
message: "",
|
||||
status: :enabled
|
||||
status: :disabled
|
||||
|
||||
issue.status.should eq :enabled
|
||||
issue.status.should eq Issue::Status::Disabled
|
||||
issue.disabled?.should be_true
|
||||
issue.enabled?.should be_false
|
||||
end
|
||||
|
||||
it "sets status to :enabled by default" do
|
||||
issue = Issue.new rule: DummyRule.new,
|
||||
location: nil,
|
||||
end_location: nil,
|
||||
message: ""
|
||||
|
||||
issue.status.should eq Issue::Status::Enabled
|
||||
issue.enabled?.should be_true
|
||||
issue.disabled?.should be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue