Skip to content

Commit

Permalink
Never apply to double splat params or splat params without names
Browse files Browse the repository at this point in the history
  • Loading branch information
nobodywasishere committed Jan 9, 2025
1 parent 4ea2cdb commit fd95a13
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
29 changes: 29 additions & 0 deletions spec/ameba/rule/typing/method_param_type_restriction_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/ameba/rule/typing/method_param_type_restriction.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fd95a13

Please sign in to comment.