From b4d94218666d7ec31ff92bba4f7dbfefb51e4906 Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Fri, 31 Jan 2025 19:08:17 +0100 Subject: [PATCH 1/3] Update proc definitions in specs to the formatted version --- spec/ameba/rule/lint/shadowed_argument_spec.cr | 2 +- spec/ameba/rule/lint/shadowing_outer_local_var_spec.cr | 6 +++--- spec/ameba/rule/lint/shared_var_in_fiber_spec.cr | 2 +- spec/ameba/rule/lint/unused_argument_spec.cr | 8 ++++---- spec/ameba/rule/lint/useless_assign_spec.cr | 8 ++++---- spec/ameba/rule/style/redundant_self_spec.cr | 2 +- .../typing/proc_literal_return_type_restriction_spec.cr | 4 ++-- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/spec/ameba/rule/lint/shadowed_argument_spec.cr b/spec/ameba/rule/lint/shadowed_argument_spec.cr index 540f83d8c..4b07d12f7 100644 --- a/spec/ameba/rule/lint/shadowed_argument_spec.cr +++ b/spec/ameba/rule/lint/shadowed_argument_spec.cr @@ -42,7 +42,7 @@ module Ameba::Rule::Lint it "reports if there is a shadowed proc argument" do s = Source.new %( - ->(x : Int32) { + -> (x : Int32) { x = 20 x } diff --git a/spec/ameba/rule/lint/shadowing_outer_local_var_spec.cr b/spec/ameba/rule/lint/shadowing_outer_local_var_spec.cr index be734f7a9..c853ec704 100644 --- a/spec/ameba/rule/lint/shadowing_outer_local_var_spec.cr +++ b/spec/ameba/rule/lint/shadowing_outer_local_var_spec.cr @@ -13,8 +13,8 @@ module Ameba::Rule::Lint bar end - -> (baz : Int32) {} - -> (bar : String) {} + -> (baz : Int32) { } + -> (bar : String) { } end CRYSTAL end @@ -67,7 +67,7 @@ module Ameba::Rule::Lint def some_method foo = 1 - -> (foo : Int32) {} + -> (foo : Int32) { } # ^^^^^^^^^^^ error: Shadowing outer local variable `foo` end CRYSTAL diff --git a/spec/ameba/rule/lint/shared_var_in_fiber_spec.cr b/spec/ameba/rule/lint/shared_var_in_fiber_spec.cr index fa4b165ba..8f6d26bb9 100644 --- a/spec/ameba/rule/lint/shared_var_in_fiber_spec.cr +++ b/spec/ameba/rule/lint/shared_var_in_fiber_spec.cr @@ -140,7 +140,7 @@ module Ameba::Rule::Lint expect_no_issues subject, <<-CRYSTAL i = 0 while i < 10 - proc = ->(x : Int32) do + proc = -> (x : Int32) do spawn do puts(x) end diff --git a/spec/ameba/rule/lint/unused_argument_spec.cr b/spec/ameba/rule/lint/unused_argument_spec.cr index 540284aa1..1d0fbadaf 100644 --- a/spec/ameba/rule/lint/unused_argument_spec.cr +++ b/spec/ameba/rule/lint/unused_argument_spec.cr @@ -15,7 +15,7 @@ module Ameba::Rule::Lint i + 1 end - ->(i : Int32) { i + 1 } + -> (i : Int32) { i + 1 } CRYSTAL end @@ -296,7 +296,7 @@ module Ameba::Rule::Lint rule.ignore_procs = true expect_no_issues rule, <<-CRYSTAL - ->(a : Int32) {} + -> (a : Int32) { } CRYSTAL end @@ -305,8 +305,8 @@ module Ameba::Rule::Lint rule.ignore_procs = false expect_issue rule, <<-CRYSTAL - ->(a : Int32) {} - # ^^^^^^^^^ error: Unused argument `a`. If it's necessary, use `_a` as an argument name to indicate that it won't be used. + -> (a : Int32) { } + # ^^^^^^^^^ error: Unused argument `a`. If it's necessary, use `_a` as an argument name to indicate that it won't be used. CRYSTAL end end diff --git a/spec/ameba/rule/lint/useless_assign_spec.cr b/spec/ameba/rule/lint/useless_assign_spec.cr index 0183c8056..f9bff88e8 100644 --- a/spec/ameba/rule/lint/useless_assign_spec.cr +++ b/spec/ameba/rule/lint/useless_assign_spec.cr @@ -25,7 +25,7 @@ module Ameba::Rule::Lint it "reports a useless assignment in a proc" do expect_issue subject, <<-CRYSTAL - ->() { + -> () { a = 2 # ^ error: Useless assignment to variable `a` } @@ -46,7 +46,7 @@ module Ameba::Rule::Lint it "reports a useless assignment in a proc inside def" do expect_issue subject, <<-CRYSTAL def method - ->() { + -> () { a = 2 # ^ error: Useless assignment to variable `a` } @@ -65,7 +65,7 @@ module Ameba::Rule::Lint expect_issue subject, <<-CRYSTAL def method 3.times do - ->() { + -> () { a = 2 # ^ error: Useless assignment to variable `a` } @@ -239,7 +239,7 @@ module Ameba::Rule::Lint expect_no_issues subject, <<-CRYSTAL def method called = false - ->() { called = true } + -> () { called = true } called end CRYSTAL diff --git a/spec/ameba/rule/style/redundant_self_spec.cr b/spec/ameba/rule/style/redundant_self_spec.cr index 3b749de32..dc189f120 100644 --- a/spec/ameba/rule/style/redundant_self_spec.cr +++ b/spec/ameba/rule/style/redundant_self_spec.cr @@ -87,7 +87,7 @@ module Ameba::Rule::Style end def bar - ->(foo : Int32) { self.foo + foo } + -> (foo : Int32) { self.foo + foo } end end CRYSTAL diff --git a/spec/ameba/rule/typing/proc_literal_return_type_restriction_spec.cr b/spec/ameba/rule/typing/proc_literal_return_type_restriction_spec.cr index d12427b8b..8f77a3249 100644 --- a/spec/ameba/rule/typing/proc_literal_return_type_restriction_spec.cr +++ b/spec/ameba/rule/typing/proc_literal_return_type_restriction_spec.cr @@ -6,13 +6,13 @@ module Ameba::Rule::Typing it "passes if a proc literal has a return type restriction" do expect_no_issues subject, <<-CRYSTAL - my_proc = ->(var : String) : Nil { puts var } + my_proc = -> (var : String) : Nil { puts var } CRYSTAL end it "fails if a proc literal doesn't have a return type restriction" do expect_issue subject, <<-CRYSTAL - my_proc = ->(var : String) { puts var } + my_proc = -> (var : String) { puts var } # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: Proc literal should have a return type restriction CRYSTAL end From 8b19615b2ddd8a5acaadc8be4d40c9fc73b91ed8 Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Mon, 3 Feb 2025 22:42:48 +0100 Subject: [PATCH 2/3] Refactor the specs for the new rules --- .../rule/lint/require_parentheses_spec.cr | 49 ++++---- .../lint/trailing_rescue_exception_spec.cr | 6 +- ...cro_call_argument_type_restriction_spec.cr | 53 +++++---- .../method_parameter_type_restriction_spec.cr | 110 +++++++++--------- .../method_return_type_restriction_spec.cr | 107 ++++++++++------- ...oc_literal_return_type_restriction_spec.cr | 6 +- 6 files changed, 173 insertions(+), 158 deletions(-) diff --git a/spec/ameba/rule/lint/require_parentheses_spec.cr b/spec/ameba/rule/lint/require_parentheses_spec.cr index 88b5eb414..623130ca3 100644 --- a/spec/ameba/rule/lint/require_parentheses_spec.cr +++ b/spec/ameba/rule/lint/require_parentheses_spec.cr @@ -6,46 +6,45 @@ module Ameba::Rule::Lint it "passes if logical operator in call args has parentheses" do expect_no_issues subject, <<-CRYSTAL - if foo.includes?("bar") || foo.includes?("batz") - puts "this code is bug-free" - end + foo.includes?("bar") || foo.includes?("baz") + foo.includes?("bar" || foo.includes? "baz") + CRYSTAL + end - if foo.includes?("bar" || foo.includes? "batz") - puts "this code is bug-free" - end + it "passes if logical operator in call doesn't involve another method call" do + expect_no_issues subject, <<-CRYSTAL + foo.includes? "bar" || "baz" + CRYSTAL + end - form.add("query", "val_1" || "val_2") - form.add "query", "val_1" || "val_2" - form.add "query", ("val_1" || "val_2") + it "passes if logical operator in call involves another method call with no arguments" do + expect_no_issues subject, <<-CRYSTAL + foo.includes? "bar" || foo.not_nil! CRYSTAL end - it "passes if logical operator in assignment call" do + it "passes if logical operator is used in an assignment call" do expect_no_issues subject, <<-CRYSTAL - hello.there = "world" || method.call - hello.there ||= "world" || method.call + foo.bar = "baz" || bat.call :foo + foo.bar ||= "baz" || bat.call :foo + foo[bar] = "baz" || bat.call :foo CRYSTAL end - it "passes if logical operator in square bracket call" do + it "passes if logical operator is used in a square bracket call" do expect_no_issues subject, <<-CRYSTAL - hello["world" || :thing] - hello["world" || :thing]? - this.is[1 || method.call] + foo["bar" || baz.call :bat] + foo["bar" || baz.call :bat]? CRYSTAL end it "fails if logical operator in call args doesn't have parentheses" do expect_issue subject, <<-CRYSTAL - if foo.includes? "bar" || foo.includes? "batz" - # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: Use parentheses in the method call to avoid confusion about precedence - puts "this code is not bug-free" - end - - if foo.in? "bar", "baz" || foo.ends_with? "qux" - # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: Use parentheses in the method call to avoid confusion about precedence - puts "this code is not bug-free" - end + foo.includes? "bar" || foo.includes? "baz" + # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: Use parentheses in the method call to avoid confusion about precedence + + foo.in? "bar", "baz" || foo.ends_with? "bat" + # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: Use parentheses in the method call to avoid confusion about precedence CRYSTAL end end diff --git a/spec/ameba/rule/lint/trailing_rescue_exception_spec.cr b/spec/ameba/rule/lint/trailing_rescue_exception_spec.cr index 3408f6e3c..7a21ede89 100644 --- a/spec/ameba/rule/lint/trailing_rescue_exception_spec.cr +++ b/spec/ameba/rule/lint/trailing_rescue_exception_spec.cr @@ -6,14 +6,14 @@ module Ameba::Rule::Lint it "passes for trailing rescue with literal values" do expect_no_issues subject, <<-CRYSTAL - puts "hello" rescue "world" - puts :meow rescue 1234 + puts "foo" rescue "bar" + puts :foo rescue 42 CRYSTAL end it "passes for trailing rescue with class initialization" do expect_no_issues subject, <<-CRYSTAL - puts "hello" rescue MyClass.new + puts "foo" rescue MyClass.new CRYSTAL end diff --git a/spec/ameba/rule/typing/macro_call_argument_type_restriction_spec.cr b/spec/ameba/rule/typing/macro_call_argument_type_restriction_spec.cr index 47a8f92e9..f60925f26 100644 --- a/spec/ameba/rule/typing/macro_call_argument_type_restriction_spec.cr +++ b/spec/ameba/rule/typing/macro_call_argument_type_restriction_spec.cr @@ -6,39 +6,42 @@ module Ameba::Rule::Typing it "passes if macro call args have type restrictions" do expect_no_issues subject, <<-CRYSTAL - class Greeter - getter name : String? - class_getter age : Int32 = 0 - setter tasks : Array(String) = [] of String - class_setter queue : Array(Int32)? - property task_mutex : Mutex = Mutex.new - class_property asdf : String + class Foo + getter foo : Int32? + setter bar : Array(Int32)? + property baz : Bool? end record Task, cmd : String, - args : Array(String) = %w[] + args : Array(String) CRYSTAL end - it "fails if a macro call arg doesn't have a type restriction" do - expect_issue subject, <<-CRYSTAL - class Greeter - getter name - # ^^^^ error: Argument should have a type restriction - getter :age - # ^^^^ error: Argument should have a type restriction - getter "height" - # ^^^^^^^^ error: Argument should have a type restriction + it "passes if macro call args have default values" do + expect_no_issues subject, <<-CRYSTAL + class Foo + getter foo = 0 + setter bar = [] of Int32 + property baz = true end + + record Task, + cmd = "", + args = %w[] CRYSTAL end - it "passes if a record call arg with a default value doesn't have a type restriction" do - expect_no_issues subject, <<-CRYSTAL - record Task, - cmd : String, - args = %[] + it "fails if a macro call arg doesn't have a type restriction" do + expect_issue subject, <<-CRYSTAL + class Foo + getter foo + # ^^^ error: Argument should have a type restriction + getter :bar + # ^^^^ error: Argument should have a type restriction + getter "baz" + # ^^^^^ error: Argument should have a type restriction + end CRYSTAL end @@ -49,9 +52,9 @@ module Ameba::Rule::Typing it "fails if a macro call arg with a default value doesn't have a type restriction" do expect_issue rule, <<-CRYSTAL - class Greeter - getter name = "Kenobi" - # ^^^^ error: Argument should have a type restriction + class Foo + getter foo = "bar" + # ^^^ error: Argument should have a type restriction end CRYSTAL end diff --git a/spec/ameba/rule/typing/method_parameter_type_restriction_spec.cr b/spec/ameba/rule/typing/method_parameter_type_restriction_spec.cr index ec363796a..6b602615e 100644 --- a/spec/ameba/rule/typing/method_parameter_type_restriction_spec.cr +++ b/spec/ameba/rule/typing/method_parameter_type_restriction_spec.cr @@ -6,53 +6,50 @@ module Ameba::Rule::Typing 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 + def foo(bar : String, baz : _) : String end + CRYSTAL + end - def hello(*a : String) : String - "hello world" + a.join(", ") + it "passes if a splat method parameter has a type restriction" do + expect_no_issues subject, <<-CRYSTAL + def foo(*bar : String) : String end CRYSTAL end 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.join(", ") + def foo(*bar) : String + # ^ error: Method parameter should have a type restriction end CRYSTAL end 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 + def foo(bar : String, *, baz : String = "bat") : String end CRYSTAL end 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 + def foo(bar : String, **opts) : String end CRYSTAL end 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 + private def foo(bar) end CRYSTAL end 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 + protected def foo(bar) end CRYSTAL end @@ -66,31 +63,31 @@ module Ameba::Rule::Typing 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 - "hello world" + a + def foo(bar) + # ^ error: Method parameter should have a type restriction end + CRYSTAL + end - def hello(a, ext b) - # ^ error: Method parameter should have a type restriction + it "fails if a public method external parameter doesn't have a type restriction" do + expect_issue subject, <<-CRYSTAL + def foo(bar, ext baz) + # ^ error: Method parameter should have a type restriction # ^ error: Method parameter should have a type restriction - "hello world" + a + b end CRYSTAL end 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 + def foo(bar = "baz") end CRYSTAL end it "passes if a block parameter doesn't have a type restriction" do expect_no_issues subject, <<-CRYSTAL - def hello(&) - "hello there" + def foo(&) end CRYSTAL end @@ -102,30 +99,30 @@ module Ameba::Rule::Typing 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 + private def foo(bar : String) : String end CRYSTAL end 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" + protected def foo(bar) end CRYSTAL end - it "fails if a public or private method doesn't have a parameter type restriction" do + it "fails if a public method doesn't have a parameter type restriction" do expect_issue rule, <<-CRYSTAL - def hello(a) - # ^ error: Method parameter should have a type restriction - "hello world" + def foo(bar) + # ^ error: Method parameter should have a type restriction end + CRYSTAL + end - private def hello(a) - # ^ error: Method parameter should have a type restriction - "hello world" + it "fails if a private method doesn't have a parameter type restriction" do + expect_issue rule, <<-CRYSTAL + private def foo(bar) + # ^ error: Method parameter should have a type restriction end CRYSTAL end @@ -137,30 +134,30 @@ module Ameba::Rule::Typing it "passes if a method has a parameter type restriction" do expect_no_issues rule, <<-CRYSTAL - protected def hello(a : String) : String - "hello world" + a + protected def foo(bar : String) : String end CRYSTAL end 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" + private def foo(bar) end CRYSTAL end - it "fails if a public or protected method doesn't have a parameter type restriction" do + it "fails if a public method doesn't have a parameter type restriction" do expect_issue rule, <<-CRYSTAL - def hello(a) - # ^ error: Method parameter should have a type restriction - "hello world" + def foo(bar) + # ^ error: Method parameter should have a type restriction end + CRYSTAL + end - protected def hello(a) - # ^ error: Method parameter should have a type restriction - "hello world" + it "fails if a protected method doesn't have a parameter type restriction" do + expect_issue rule, <<-CRYSTAL + protected def foo(bar) + # ^ error: Method parameter should have a type restriction end CRYSTAL end @@ -171,10 +168,9 @@ module Ameba::Rule::Typing rule = MethodParameterTypeRestriction.new rule.default_value = true - expect_issue rule, <<-'CRYSTAL' - def hello(a = "world") - # ^ error: Method parameter should have a type restriction - "hello #{a}" + expect_issue rule, <<-CRYSTAL + def foo(bar = "baz") + # ^ error: Method parameter should have a type restriction end CRYSTAL end @@ -186,18 +182,16 @@ module Ameba::Rule::Typing 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 - "hello" + def foo(&) + # ^ error: Method parameter should have a type restriction end CRYSTAL end 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 - "hello, #{a.call}" + expect_issue rule, <<-CRYSTAL + def foo(&block) + # ^ error: Method parameter should have a type restriction end CRYSTAL end diff --git a/spec/ameba/rule/typing/method_return_type_restriction_spec.cr b/spec/ameba/rule/typing/method_return_type_restriction_spec.cr index b85c34bf9..b6ec952da 100644 --- a/spec/ameba/rule/typing/method_return_type_restriction_spec.cr +++ b/spec/ameba/rule/typing/method_return_type_restriction_spec.cr @@ -4,35 +4,42 @@ module Ameba::Rule::Typing describe MethodReturnTypeRestriction do subject = MethodReturnTypeRestriction.new - it "passes if a method has a return type restriction" do + it "passes if a public method has a return type restriction" do expect_no_issues subject, <<-CRYSTAL - def hello : String - "hello world" + def foo : String end + CRYSTAL + end - private def hello : String - "hello world" + it "passes if a private method has a return type restriction" do + expect_no_issues subject, <<-CRYSTAL + private def foo : String end + CRYSTAL + end - protected def hello : String - "hello world" + it "passes if a protected method has a return type restriction" do + expect_no_issues subject, <<-CRYSTAL + protected def foo : String end CRYSTAL end - it "passes if a private or protected method doesn't have a return type restriction" do + it "passes if a private method doesn't have a return type restriction" do expect_no_issues subject, <<-CRYSTAL - private def hello - "hello world" + private def foo end + CRYSTAL + end - protected def hello - "hello world" + it "passes if a protected method doesn't have a return type restriction" do + expect_no_issues subject, <<-CRYSTAL + protected def foo end CRYSTAL end - it "passes if a method has a `:nodoc:` annotation" do + it "passes if a public method has a `:nodoc:` annotation" do expect_no_issues subject, <<-CRYSTAL # :nodoc: def foo; end @@ -41,9 +48,8 @@ module Ameba::Rule::Typing it "fails if a public method doesn't have a return type restriction" do expect_issue subject, <<-CRYSTAL - def hello - # ^^^^^^^ error: Method should have a return type restriction - "hello world" + def foo + # ^^^^^ error: Method should have a return type restriction end CRYSTAL end @@ -53,40 +59,46 @@ module Ameba::Rule::Typing rule = MethodReturnTypeRestriction.new rule.private_methods = true - it "passes if a method has a return type restriction" do + it "passes if a public method has a return type restriction" do expect_no_issues rule, <<-CRYSTAL - def hello : String - "hello world" + def foo : String end + CRYSTAL + end - private def hello : String - "hello world" + it "passes if a private method has a return type restriction" do + expect_no_issues rule, <<-CRYSTAL + private def foo : String end + CRYSTAL + end - protected def hello : String - "hello world" + it "passes if a protected method has a return type restriction" do + expect_no_issues rule, <<-CRYSTAL + protected def foo : String end CRYSTAL end it "passes if a protected method doesn't have a return type restriction" do expect_no_issues rule, <<-CRYSTAL - protected def hello - "hello world" + protected def foo end CRYSTAL end - it "fails if a public or private method doesn't have a return type restriction" do + it "fails if a public method doesn't have a return type restriction" do expect_issue rule, <<-CRYSTAL - def hello - # ^^^^^^^ error: Method should have a return type restriction - "hello world" + def foo + # ^^^^^ error: Method should have a return type restriction end + CRYSTAL + end - private def hello - # ^^^^^^^^^ error: Method should have a return type restriction - "hello world" + it "fails if a private method doesn't have a return type restriction" do + expect_issue rule, <<-CRYSTAL + private def foo + # ^^^^^^^ error: Method should have a return type restriction end CRYSTAL end @@ -96,32 +108,39 @@ module Ameba::Rule::Typing rule = MethodReturnTypeRestriction.new rule.protected_methods = true - it "passes if a method has a return type restriction" do + it "passes if a public method has a return type restriction" do expect_no_issues rule, <<-CRYSTAL - protected def hello : String - "hello world" + def foo : String end CRYSTAL end it "passes if a private method doesn't have a return type restriction" do expect_no_issues rule, <<-CRYSTAL - private def hello - "hello world" + private def foo + end + CRYSTAL + end + + it "passes if a protected method has a return type restriction" do + expect_no_issues rule, <<-CRYSTAL + protected def foo : String end CRYSTAL end - it "fails if a public or protected method doesn't have a return type restriction" do + it "fails if a public method doesn't have a return type restriction" do expect_issue rule, <<-CRYSTAL - def hello - # ^^^^^^^ error: Method should have a return type restriction - "hello world" + def foo + # ^^^^^ error: Method should have a return type restriction end + CRYSTAL + end - protected def hello - # ^^^^^^^^^ error: Method should have a return type restriction - "hello world" + it "fails if a protected method doesn't have a return type restriction" do + expect_issue rule, <<-CRYSTAL + protected def foo + # ^^^^^^^ error: Method should have a return type restriction end CRYSTAL end diff --git a/spec/ameba/rule/typing/proc_literal_return_type_restriction_spec.cr b/spec/ameba/rule/typing/proc_literal_return_type_restriction_spec.cr index 8f77a3249..30a2e3dbd 100644 --- a/spec/ameba/rule/typing/proc_literal_return_type_restriction_spec.cr +++ b/spec/ameba/rule/typing/proc_literal_return_type_restriction_spec.cr @@ -6,14 +6,14 @@ module Ameba::Rule::Typing it "passes if a proc literal has a return type restriction" do expect_no_issues subject, <<-CRYSTAL - my_proc = -> (var : String) : Nil { puts var } + foo = -> (bar : String) : Nil { } CRYSTAL end it "fails if a proc literal doesn't have a return type restriction" do expect_issue subject, <<-CRYSTAL - my_proc = -> (var : String) { puts var } - # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: Proc literal should have a return type restriction + foo = -> (bar : String) { } + # ^^^^^^^^^^^^^^^^^^^^^ error: Proc literal should have a return type restriction CRYSTAL end end From 5defa099d546dbbad69ec9686d1e8f01ffb30298 Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Mon, 3 Feb 2025 22:43:12 +0100 Subject: [PATCH 3/3] `Lint/RequireParentheses` comment tweak --- src/ameba/rule/lint/require_parentheses.cr | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ameba/rule/lint/require_parentheses.cr b/src/ameba/rule/lint/require_parentheses.cr index db3e778cd..c6bcf3012 100644 --- a/src/ameba/rule/lint/require_parentheses.cr +++ b/src/ameba/rule/lint/require_parentheses.cr @@ -6,14 +6,16 @@ module Ameba::Rule::Lint # For example, this is considered invalid: # # ``` - # if foo.includes? "bar" || foo.includes? "batz" + # if foo.includes? "bar" || foo.includes? "baz" + # # ... # end # ``` # # And need to be written as: # # ``` - # if foo.includes?("bar") || foo.includes?("batz") + # if foo.includes?("bar") || foo.includes?("baz") + # # ... # end # ``` #