mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Extend StaticComparison
w/ support of ===
operator
This commit is contained in:
parent
849be52618
commit
ea42911c3c
2 changed files with 17 additions and 9 deletions
|
@ -6,13 +6,21 @@ module Ameba::Rule::Lint
|
|||
describe StaticComparison do
|
||||
it "passes for valid cases" do
|
||||
expect_no_issues subject, <<-CRYSTAL
|
||||
/foo/ === "foo"
|
||||
"foo" == foo
|
||||
"foo" != foo
|
||||
foo == "foo"
|
||||
foo != "foo"
|
||||
CRYSTAL
|
||||
end
|
||||
|
||||
it "reports if there is a static comparison evaluating to true" do
|
||||
it "reports if there is a static comparison evaluating to the same" do
|
||||
expect_issue subject, <<-CRYSTAL
|
||||
"foo" === "foo"
|
||||
# ^^^^^^^^^^^^^ error: Comparison always evaluates to the same
|
||||
CRYSTAL
|
||||
end
|
||||
|
||||
it "reports if there is a static comparison evaluating to true (2)" do
|
||||
expect_issue subject, <<-CRYSTAL
|
||||
"foo" == "foo"
|
||||
# ^^^^^^^^^^^^ error: Comparison always evaluates to true
|
||||
|
|
|
@ -21,7 +21,7 @@ module Ameba::Rule::Lint
|
|||
description "Identifies static comparisons"
|
||||
end
|
||||
|
||||
OP_NAMES = %w(== !=)
|
||||
OP_NAMES = %w(=== == !=)
|
||||
MSG = "Comparison always evaluates to %s"
|
||||
|
||||
PRIMITIVES = {
|
||||
|
@ -45,11 +45,11 @@ module Ameba::Rule::Lint
|
|||
return unless (obj = node.obj) && (arg = node.args.first?)
|
||||
return unless obj.class.in?(PRIMITIVES) && arg.class.in?(PRIMITIVES)
|
||||
|
||||
what =
|
||||
case node.name
|
||||
when "=="
|
||||
what = (obj.to_s == arg.to_s).to_s
|
||||
when "!="
|
||||
what = (obj.to_s != arg.to_s).to_s
|
||||
when "===" then "the same"
|
||||
when "==" then (obj.to_s == arg.to_s).to_s
|
||||
when "!=" then (obj.to_s != arg.to_s).to_s
|
||||
end
|
||||
|
||||
issue_for node, MSG % what
|
||||
|
|
Loading…
Reference in a new issue