mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Add corrector to the Style/IsANil
rule
This commit is contained in:
parent
071a8b7afb
commit
7d88455b7f
2 changed files with 13 additions and 3 deletions
|
@ -14,17 +14,25 @@ module Ameba::Rule::Style
|
||||||
end
|
end
|
||||||
|
|
||||||
it "reports if there is a call to is_a?(Nil) without receiver" do
|
it "reports if there is a call to is_a?(Nil) without receiver" do
|
||||||
expect_issue subject, <<-CRYSTAL
|
source = expect_issue subject, <<-CRYSTAL
|
||||||
a = is_a?(Nil)
|
a = is_a?(Nil)
|
||||||
# ^^^ error: Use `nil?` instead of `is_a?(Nil)`
|
# ^^^ error: Use `nil?` instead of `is_a?(Nil)`
|
||||||
CRYSTAL
|
CRYSTAL
|
||||||
|
|
||||||
|
expect_correction source, <<-CRYSTAL
|
||||||
|
a = self.nil?
|
||||||
|
CRYSTAL
|
||||||
end
|
end
|
||||||
|
|
||||||
it "reports if there is a call to is_a?(Nil) with receiver" do
|
it "reports if there is a call to is_a?(Nil) with receiver" do
|
||||||
expect_issue subject, <<-CRYSTAL
|
source = expect_issue subject, <<-CRYSTAL
|
||||||
a.is_a?(Nil)
|
a.is_a?(Nil)
|
||||||
# ^^^ error: Use `nil?` instead of `is_a?(Nil)`
|
# ^^^ error: Use `nil?` instead of `is_a?(Nil)`
|
||||||
CRYSTAL
|
CRYSTAL
|
||||||
|
|
||||||
|
expect_correction source, <<-CRYSTAL
|
||||||
|
a.nil?
|
||||||
|
CRYSTAL
|
||||||
end
|
end
|
||||||
|
|
||||||
it "reports rule, location and message" do
|
it "reports rule, location and message" do
|
||||||
|
|
|
@ -34,7 +34,9 @@ module Ameba::Rule::Style
|
||||||
const = node.const
|
const = node.const
|
||||||
return unless path_named?(const, "Nil")
|
return unless path_named?(const, "Nil")
|
||||||
|
|
||||||
issue_for const, MSG
|
issue_for const, MSG do |corrector|
|
||||||
|
corrector.replace(node, "#{node.obj}.nil?")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue