diff --git a/spec/ameba/rule/lint/redundant_string_cercion_spec.cr b/spec/ameba/rule/lint/redundant_string_cercion_spec.cr index 4389300a..d2c7a824 100644 --- a/spec/ameba/rule/lint/redundant_string_cercion_spec.cr +++ b/spec/ameba/rule/lint/redundant_string_cercion_spec.cr @@ -52,6 +52,20 @@ module Ameba::Rule::Lint subject.catch(s).should_not be_valid 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 s = Source.new %q( "Hello, #{name1.to_s}" diff --git a/src/ameba/rule/lint/redundant_string_coercion.cr b/src/ameba/rule/lint/redundant_string_coercion.cr index 7b92ff23..b8fae386 100644 --- a/src/ameba/rule/lint/redundant_string_coercion.cr +++ b/src/ameba/rule/lint/redundant_string_coercion.cr @@ -36,7 +36,7 @@ module Ameba::Rule::Lint private def string_coercion_nodes(node) 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