mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Do not report if Object#to_s is called without receiver
This commit is contained in:
parent
ff1669ebe8
commit
59bc021e57
2 changed files with 15 additions and 1 deletions
|
@ -52,6 +52,20 @@ module Ameba::Rule::Lint
|
||||||
subject.catch(s).should_not be_valid
|
subject.catch(s).should_not be_valid
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "doesn't report if Object#to_s is called with arguments" do
|
||||||
|
s = Source.new %q(
|
||||||
|
/\w #{name.to_s(io)}/
|
||||||
|
)
|
||||||
|
subject.catch(s).should be_valid
|
||||||
|
end
|
||||||
|
|
||||||
|
it "doesn't report if Object#to_s is called without receiver" do
|
||||||
|
s = Source.new %q(
|
||||||
|
/\w #{to_s}/
|
||||||
|
)
|
||||||
|
subject.catch(s).should be_valid
|
||||||
|
end
|
||||||
|
|
||||||
it "reports rule, location and message" do
|
it "reports rule, location and message" do
|
||||||
s = Source.new %q(
|
s = Source.new %q(
|
||||||
"Hello, #{name1.to_s}"
|
"Hello, #{name1.to_s}"
|
||||||
|
|
|
@ -36,7 +36,7 @@ module Ameba::Rule::Lint
|
||||||
|
|
||||||
private def string_coercion_nodes(node)
|
private def string_coercion_nodes(node)
|
||||||
node.expressions.select do |e|
|
node.expressions.select do |e|
|
||||||
e.is_a?(Crystal::Call) && e.name == "to_s" && e.args.size == 0
|
e.is_a?(Crystal::Call) && e.name == "to_s" && e.args.size.zero? && e.obj
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue