From c501a4ceae7f2a24e20755f44345f804b28d2f4f Mon Sep 17 00:00:00 2001 From: Margret Riegert Date: Sat, 28 Dec 2024 09:47:26 -0500 Subject: [PATCH] Remove undocumented config option --- .../method_return_type_restriction_spec.cr | 101 ++---------------- .../typing/method_return_type_restriction.cr | 5 - 2 files changed, 6 insertions(+), 100 deletions(-) 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 2d8658da7..387c376b5 100644 --- a/spec/ameba/rule/typing/method_return_type_restriction_spec.cr +++ b/spec/ameba/rule/typing/method_return_type_restriction_spec.cr @@ -19,12 +19,8 @@ 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 @@ -32,17 +28,11 @@ module Ameba::Rule::Typing 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" @@ -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" @@ -127,32 +101,21 @@ 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" @@ -160,57 +123,5 @@ module Ameba::Rule::Typing 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 diff --git a/src/ameba/rule/typing/method_return_type_restriction.cr b/src/ameba/rule/typing/method_return_type_restriction.cr index 1b46aec96..3e2222af5 100644 --- a/src/ameba/rule/typing/method_return_type_restriction.cr +++ b/src/ameba/rule/typing/method_return_type_restriction.cr @@ -28,14 +28,11 @@ 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 # ``` @@ -43,7 +40,6 @@ module Ameba::Rule::Typing properties do description "Recommends that methods have a return type restriction" enabled false - undocumented false private_methods false protected_methods false end @@ -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