mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Add autocorrect for Style/UnlessElse
This commit is contained in:
parent
e6ebca7a5b
commit
d7795c0d7d
5 changed files with 122 additions and 2 deletions
|
@ -13,7 +13,7 @@ module Ameba::Rule::Style
|
|||
end
|
||||
|
||||
it "fails if unless has else" do
|
||||
expect_issue subject, <<-CRYSTAL
|
||||
source = expect_issue subject, <<-CRYSTAL
|
||||
unless something
|
||||
# ^^^^^^^^^^^^^^ error: Favour if over unless with else
|
||||
:one
|
||||
|
@ -21,6 +21,14 @@ module Ameba::Rule::Style
|
|||
:two
|
||||
end
|
||||
CRYSTAL
|
||||
|
||||
expect_correction source, <<-CRYSTAL
|
||||
if something
|
||||
:two
|
||||
else
|
||||
:one
|
||||
end
|
||||
CRYSTAL
|
||||
end
|
||||
|
||||
it "reports rule, pos and message" do
|
||||
|
|
|
@ -46,5 +46,22 @@ module Ameba
|
|||
s.matches_path?("new_source.cr").should be_false
|
||||
end
|
||||
end
|
||||
|
||||
describe "#pos" do
|
||||
it "works" do
|
||||
s = Source.new <<-EOS
|
||||
foo
|
||||
bar
|
||||
fizz
|
||||
buzz
|
||||
EOS
|
||||
loc = Crystal::Location.new("", 2, 1)
|
||||
end_loc = Crystal::Location.new("", 3, 4)
|
||||
s.code[s.pos(loc)...s.pos(end_loc, end: true)].should eq <<-EOS
|
||||
bar
|
||||
fizz
|
||||
EOS
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue