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
|
||||
|
||||
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)
|
||||
# ^^^ error: Use `nil?` instead of `is_a?(Nil)`
|
||||
CRYSTAL
|
||||
|
||||
expect_correction source, <<-CRYSTAL
|
||||
a = self.nil?
|
||||
CRYSTAL
|
||||
end
|
||||
|
||||
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)
|
||||
# ^^^ error: Use `nil?` instead of `is_a?(Nil)`
|
||||
CRYSTAL
|
||||
|
||||
expect_correction source, <<-CRYSTAL
|
||||
a.nil?
|
||||
CRYSTAL
|
||||
end
|
||||
|
||||
it "reports rule, location and message" do
|
||||
|
|
|
@ -34,7 +34,9 @@ module Ameba::Rule::Style
|
|||
const = node.const
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue