mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
39 lines
938 B
Crystal
39 lines
938 B
Crystal
require "../../../spec_helper"
|
|
|
|
module Ameba::Rule::Style
|
|
describe IsANil do
|
|
subject = IsANil.new
|
|
|
|
it "doesn't report if there are no is_a?(Nil) calls" do
|
|
expect_no_issues subject, <<-CRYSTAL
|
|
a = 1
|
|
a.nil?
|
|
a.is_a?(NilLiteral)
|
|
a.is_a?(Custom::Nil)
|
|
CRYSTAL
|
|
end
|
|
|
|
it "reports if there is a call to is_a?(Nil) without receiver" do
|
|
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
|
|
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
|
|
end
|
|
end
|