mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
New rule: useless condition in when
thanks to @hugoabonizio for suggesstion
This commit is contained in:
parent
8cbdd0de4d
commit
96c1af4e35
3 changed files with 130 additions and 0 deletions
45
spec/ameba/rule/useless_condition_in_when_spec.cr
Normal file
45
spec/ameba/rule/useless_condition_in_when_spec.cr
Normal file
|
@ -0,0 +1,45 @@
|
|||
require "../../spec_helper"
|
||||
|
||||
module Ameba::Rule
|
||||
subject = UselessConditionInWhen.new
|
||||
|
||||
describe UselessConditionInWhen do
|
||||
it "passes if there is not useless condition" do
|
||||
s = Source.new %(
|
||||
case
|
||||
when utc?
|
||||
io << " UTC"
|
||||
when local?
|
||||
Format.new(" %:z").format(self, io) if utc?
|
||||
end
|
||||
)
|
||||
subject.catch(s).should be_valid
|
||||
end
|
||||
|
||||
it "fails if there is useless if condition" do
|
||||
s = Source.new %(
|
||||
case
|
||||
when utc?
|
||||
io << " UTC" if utc?
|
||||
end
|
||||
)
|
||||
subject.catch(s).should_not be_valid
|
||||
end
|
||||
|
||||
it "reports rule, location and message" do
|
||||
s = Source.new %(
|
||||
case
|
||||
when String
|
||||
puts "hello"
|
||||
when can_generate?
|
||||
generate if can_generate?
|
||||
end
|
||||
), "source.cr"
|
||||
subject.catch(s).should_not be_valid
|
||||
error = s.errors.first
|
||||
error.rule.should_not be_nil
|
||||
error.location.to_s.should eq "source.cr:6:23"
|
||||
error.message.should eq "Useless condition in when detected"
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue