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 Dec 28, 2024
1 parent c501a4c commit 04f99c5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
4 changes: 2 additions & 2 deletions spec/ameba/rule/typing/method_return_type_restriction_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ require "../../../spec_helper"
module Ameba::Rule::Typing
subject = MethodReturnTypeRestriction.new

it "passes if a method has a return type" do
it "passes if a method has a return type restriction" do
expect_no_issues subject, <<-CRYSTAL
def hello : String
"hello world"
Expand All @@ -25,7 +25,7 @@ module Ameba::Rule::Typing
"hello world"
end
protected def hello : String
protected def hello
"hello world"
end
CRYSTAL
Expand Down
23 changes: 8 additions & 15 deletions src/ameba/rule/typing/method_return_type_restriction.cr
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
module Ameba::Rule::Typing
# A rule that enforces method definitions have a return type restriction.
#
# For example, these are considered valid:
# For example, this are considered invalid:
#
# ```
# def hello : String
# "hello world"
# end
#
# def listen(a, b) : Int32
# 0
# def hello(name = "World")
# "Hello #{name}"
# end
# ```
#
# And these are considered invalid:
# And this is valid:
#
# ```
# def hello
# "hello world"
# end
#
# def listen(a, b)
# 0
# def hello(name = "World") : String
# "Hello #{name}"
# end
# ```
#
Expand All @@ -38,6 +30,7 @@ module Ameba::Rule::Typing
# ```
class MethodReturnTypeRestriction < Base
properties do
since_version "1.7.0"
description "Recommends that methods have a return type restriction"
enabled false
private_methods false
Expand All @@ -49,7 +42,7 @@ module Ameba::Rule::Typing
def test(source, node : Crystal::Def)
return if node.return_type || valid?(node)

issue_for node, MSG, prefer_name_location: true
issue_for node, MSG
end

def valid?(node : Crystal::ASTNode) : Bool
Expand Down

0 comments on commit 04f99c5

Please sign in to comment.