Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Sijawusz Pur Rahnama <[email protected]>
  • Loading branch information
nobodywasishere and Sija authored Jan 12, 2025
1 parent 136b3ea commit 5ec4fb6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
36 changes: 18 additions & 18 deletions spec/ameba/rule/typing/method_parameter_type_restriction_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Ameba::Rule::Typing
describe MethodParameterTypeRestriction do
subject = MethodParameterTypeRestriction.new

it "passes if a method param has a type restriction" do
it "passes if a method parameter has a type restriction" do
expect_no_issues subject, <<-CRYSTAL
def hello(a : String, b : _) : String
"hello world" + a + b
Expand All @@ -16,48 +16,48 @@ module Ameba::Rule::Typing
CRYSTAL
end

it "fails if a splat method param with a name doesn't have a type restriction" do
it "fails if a splat method parameter 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
"hello world" + a.join(", ")
end
CRYSTAL
end

it "passes if a splat param without a name doesn't have a type restriction" do
it "passes if a splat parameter 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
hello + world
end
CRYSTAL
end

it "passes if a double splat method param doesn't have a type restriction" do
it "passes if a double splat method parameter doesn't have a type restriction" do
expect_no_issues subject, <<-CRYSTAL
def hello(a : String, **world) : String
"hello world" + a
end
CRYSTAL
end

it "passes if a private method method param doesn't have a type restriction" do
it "passes if a private method parameter doesn't have a type restriction" do
expect_no_issues subject, <<-CRYSTAL
private def hello(a)
"hello world" + a
end
CRYSTAL
end

it "passes if a protected method param doesn't have a type restriction" do
it "passes if a protected method parameter doesn't have a type restriction" do
expect_no_issues subject, <<-CRYSTAL
protected def hello(a)
"hello world" + a
end
CRYSTAL
end

it "fails if a public method param doesn't have a type restriction" do
it "fails if a public method parameter doesn't have a type restriction" do
expect_issue subject, <<-CRYSTAL
def hello(a)
# ^ error: Method parameter should have a type restriction
Expand All @@ -72,15 +72,15 @@ module Ameba::Rule::Typing
CRYSTAL
end

it "passes if a method param with a default value doesn't have a type restriction" do
it "passes if a method parameter with a default value doesn't have a type restriction" do
expect_no_issues subject, <<-CRYSTAL
def hello(a = "jim")
"hello there, " + a
end
CRYSTAL
end

it "passes if a block param doesn't have a type restriction" do
it "passes if a block parameter doesn't have a type restriction" do
expect_no_issues subject, <<-CRYSTAL
def hello(&)
"hello there"
Expand All @@ -93,23 +93,23 @@ module Ameba::Rule::Typing
rule = MethodParameterTypeRestriction.new
rule.private_methods = true

it "passes if a method has a return type restriction" do
it "passes if a method has a parameter type restriction" do
expect_no_issues rule, <<-CRYSTAL
private def hello(a : String) : String
"hello world" + a
end
CRYSTAL
end

it "passes if a protected method param doesn't have a type restriction" do
it "passes if a protected method parameter doesn't have a type restriction" do
expect_no_issues rule, <<-CRYSTAL
protected def hello(a)
"hello world"
end
CRYSTAL
end

it "fails if a public or private method doesn't have a return type restriction" do
it "fails if a public or private method doesn't have a parameter type restriction" do
expect_issue rule, <<-CRYSTAL
def hello(a)
# ^ error: Method parameter should have a type restriction
Expand All @@ -136,7 +136,7 @@ module Ameba::Rule::Typing
CRYSTAL
end

it "passes if a private method param doesn't have a type restriction" do
it "passes if a private method parameter doesn't have a type restriction" do
expect_no_issues rule, <<-CRYSTAL
private def hello(a)
"hello world"
Expand All @@ -160,7 +160,7 @@ module Ameba::Rule::Typing
end

context "#default_value" do
it "fails if a method param with a default value doesn't have a type restriction" do
it "fails if a method parameter with a default value doesn't have a type restriction" do
rule = MethodParameterTypeRestriction.new
rule.default_value = true

Expand All @@ -177,7 +177,7 @@ module Ameba::Rule::Typing
rule = MethodParameterTypeRestriction.new
rule.block_param = true

it "fails if a block param without a name doesn't have a type restriction" do
it "fails if a block parameter without a name doesn't have a type restriction" do
expect_issue rule, <<-CRYSTAL
def hello(&)
# ^ error: Method parameter should have a type restriction
Expand All @@ -186,7 +186,7 @@ module Ameba::Rule::Typing
CRYSTAL
end

it "fails if a block param with a name doesn't have a type restriction" do
it "fails if a block parameter with a name doesn't have a type restriction" do
expect_issue rule, <<-CRYSTAL
def hello(&a)
# ^ error: Method parameter should have a type restriction
Expand Down
2 changes: 1 addition & 1 deletion src/ameba/rule/typing/method_parameter_type_restriction.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Ameba::Rule::Typing
# A rule that enforces method parameters have type restrictions, with optional enforcement of block parameters
# A rule that enforces method parameters have type restrictions, with optional enforcement of block parameters.
#
# For example, this is considered invalid:
#
Expand Down

0 comments on commit 5ec4fb6

Please sign in to comment.