diff --git a/spec/ameba/rule/typing/method_param_type_restriction_spec.cr b/spec/ameba/rule/typing/method_param_type_restriction_spec.cr index eba017614..4dca6e184 100644 --- a/spec/ameba/rule/typing/method_param_type_restriction_spec.cr +++ b/spec/ameba/rule/typing/method_param_type_restriction_spec.cr @@ -8,6 +8,35 @@ module Ameba::Rule::Typing def hello(a : String) : String "hello world" + a end + + def hello(*a : String) : String + "hello world" + a.join(", ") + end + CRYSTAL + end + + it "fails if a splat method param with a name doesn't have a type restriction" do + expect_issue subject, <<-CRYSTAL + def hello(*a) : String + # ^ error: Method parameter should have a type restriction + "hello world" + a + end + CRYSTAL + end + + it "passes if a splat param without a name doesn't have a type restriction" do + expect_no_issues subject, <<-CRYSTAL + def hello(hello : String, *, world : String = "world") : String + hello + world + a + end + CRYSTAL + end + + it "passes if a double splat method param doesn't have a type restriction" do + expect_no_issues subject, <<-CRYSTAL + def hello(a : String, **world) : String + "hello world" + a + end CRYSTAL end diff --git a/src/ameba/rule/typing/method_param_type_restriction.cr b/src/ameba/rule/typing/method_param_type_restriction.cr index e4aba1edc..c30e9afbc 100644 --- a/src/ameba/rule/typing/method_param_type_restriction.cr +++ b/src/ameba/rule/typing/method_param_type_restriction.cr @@ -67,7 +67,7 @@ module Ameba::Rule::Typing return if valid?(node) node.args.each do |arg| - next if arg.restriction || (!default_value? && arg.default_value) + next if arg.restriction || (!default_value? && arg.default_value) || arg.name.empty? issue_for arg, MSG, prefer_name_location: true end