mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Refactor Style/IsANil
rule to use newly added path_named?
helper
This commit is contained in:
parent
f45d6a2ef0
commit
cdf0405496
1 changed files with 4 additions and 4 deletions
|
@ -20,19 +20,19 @@ module Ameba::Rule::Style
|
||||||
# Enabled: true
|
# Enabled: true
|
||||||
# ```
|
# ```
|
||||||
class IsANil < Base
|
class IsANil < Base
|
||||||
|
include AST::Util
|
||||||
|
|
||||||
properties do
|
properties do
|
||||||
description "Disallows calls to `is_a?(Nil)` in favor of `nil?`"
|
description "Disallows calls to `is_a?(Nil)` in favor of `nil?`"
|
||||||
end
|
end
|
||||||
|
|
||||||
MSG = "Use `nil?` instead of `is_a?(Nil)`"
|
MSG = "Use `nil?` instead of `is_a?(Nil)`"
|
||||||
PATH_NIL_NAMES = %w(Nil)
|
|
||||||
|
|
||||||
def test(source, node : Crystal::IsA)
|
def test(source, node : Crystal::IsA)
|
||||||
return if node.nil_check?
|
return if node.nil_check?
|
||||||
|
|
||||||
const = node.const
|
const = node.const
|
||||||
return unless const.is_a?(Crystal::Path)
|
return unless path_named?(const, "Nil")
|
||||||
return unless const.names == PATH_NIL_NAMES
|
|
||||||
|
|
||||||
issue_for const, MSG
|
issue_for const, MSG
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue