Skip to content

Commit

Permalink
Remove undocumented config option
Browse files Browse the repository at this point in the history
  • Loading branch information
nobodywasishere committed Dec 28, 2024
1 parent e95663f commit c501a4c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 100 deletions.
101 changes: 6 additions & 95 deletions spec/ameba/rule/typing/method_return_type_restriction_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,20 @@ module Ameba::Rule::Typing
CRYSTAL
end

it "passes if an undocumented method doesn't have a return type" do
it "passes if a private or protected method doesn't have a return type" do
expect_no_issues subject, <<-CRYSTAL
def hello
"hello world"
end
private def hello
"hello world"
end
protected def hello : String
"hello world"
end
# :nodoc:
def hello
"hello world"
end
CRYSTAL
end

it "fails if a documented method doesn't have a return type" do
it "fails if a public method doesn't have a return type" do
expect_issue subject, <<-CRYSTAL
# This method is documented
def hello
# ^^^^^ error: Method should have a return type restriction
"hello world"
Expand Down Expand Up @@ -73,40 +63,24 @@ module Ameba::Rule::Typing
protected def hello : String
"hello world"
end
# :nodoc:
def hello : String
"hello world"
end
CRYSTAL
end

it "passes if an undocumented public or protected method doesn't have a return type" do
it "passes if a protected method doesn't have a return type" do
expect_no_issues rule, <<-CRYSTAL
def hello
"hello world"
end
protected def hello
"hello world"
end
# :nodoc:
def hello
"hello world"
end
CRYSTAL
end

it "fails if a documented public or private method doesn't have a return type" do
it "fails if a public or private method doesn't have a return type" do
expect_issue rule, <<-CRYSTAL
# This method is documented
def hello
# ^^^^^ error: Method should have a return type restriction
"hello world"
end
# This method is also documented
private def hello
# ^^^^^ error: Method should have a return type restriction
"hello world"
Expand All @@ -127,90 +101,27 @@ module Ameba::Rule::Typing
CRYSTAL
end

it "passes if an undocumented public or private method doesn't have a return type" do
it "passes if a private method doesn't have a return type" do
expect_no_issues rule, <<-CRYSTAL
def hello
"hello world"
end
private def hello
"hello world"
end
# :nodoc:
def hello
"hello world"
end
CRYSTAL
end

it "fails if a documented public or protected method doesn't have a return type" do
it "fails if a public or protected method doesn't have a return type" do
expect_issue rule, <<-CRYSTAL
# This method is documented
def hello
# ^^^^^ error: Method should have a return type restriction
"hello world"
end
# This method is also documented
protected def hello
# ^^^^^ error: Method should have a return type restriction
"hello world"
end
CRYSTAL
end
end

context "#undocumented" do
rule = MethodReturnTypeRestriction.new
rule.undocumented = true

it "passes if a documented method has a return type" do
expect_no_issues rule, <<-CRYSTAL
# This method is documented
def hello : String
"hello world"
end
# This method is documented
private def hello : String
"hello world"
end
# This method is documented
protected def hello : String
"hello world"
end
CRYSTAL
end

it "passes if undocumented private or protected methods have a return type" do
expect_no_issues rule, <<-CRYSTAL
private def hello
"hello world"
end
protected def hello
"hello world"
end
CRYSTAL
end

it "fails if an undocumented method doesn't have a return type" do
expect_issue rule, <<-CRYSTAL
def hello
# ^^^^^ error: Method should have a return type restriction
"hello world"
end
# :nodoc:
def hello
# ^^^^^ error: Method should have a return type restriction
"hello world"
end
CRYSTAL
end
end
end
end
5 changes: 0 additions & 5 deletions src/ameba/rule/typing/method_return_type_restriction.cr
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,18 @@ module Ameba::Rule::Typing
# When the config options `PrivateMethods` and `ProtectedMethods`
# are true, this rule is also applied to private and protected methods, respectively.
#
# The config option `Undocumented` controls whether this rule applies to undocumented methods and methods with a `:nodoc:` directive.
#
# YAML configuration example:
#
# ```
# Typing/MethodReturnTypeRestriction:
# Enabled: false
# Undocumented: false
# PrivateMethods: false
# ProtectedMethods: false
# ```
class MethodReturnTypeRestriction < Base
properties do
description "Recommends that methods have a return type restriction"
enabled false
undocumented false
private_methods false
protected_methods false
end
Expand All @@ -59,7 +55,6 @@ module Ameba::Rule::Typing
def valid?(node : Crystal::ASTNode) : Bool
(!private_methods? && node.visibility.private?) ||
(!protected_methods? && node.visibility.protected?) ||
(!undocumented? && (node.doc.nil? || node.doc.try(&.starts_with?(":nodoc:")))) ||
false
end
end
Expand Down

0 comments on commit c501a4c

Please sign in to comment.