From 9b5a0767cb9d62ae4ce5361e624b6e5284677aaf Mon Sep 17 00:00:00 2001
From: Mike McQuaid <mike@mikemcquaid.com>
Date: Mon, 13 Apr 2020 14:35:03 +0100
Subject: [PATCH] rubocops/formula_desc: merge cops, slim whitelist.

---
 Library/Homebrew/rubocops/formula_desc.rb     | 64 +++++++------------
 Library/Homebrew/test/.rubocop_todo.yml       |  1 +
 .../test/rubocops/formula_desc_spec.rb        |  6 +-
 3 files changed, 24 insertions(+), 47 deletions(-)

diff --git a/Library/Homebrew/rubocops/formula_desc.rb b/Library/Homebrew/rubocops/formula_desc.rb
index aee3ec413e..eb32fcc358 100644
--- a/Library/Homebrew/rubocops/formula_desc.rb
+++ b/Library/Homebrew/rubocops/formula_desc.rb
@@ -10,37 +10,6 @@ module RuboCop
       #
       # - Checks for existence of `desc`
       # - Checks if size of `desc` > 80
-      class DescLength < FormulaCop
-        def audit_formula(_node, _class_node, _parent_class_node, body_node)
-          desc_call = find_node_method_by_name(body_node, :desc)
-
-          # Check if a formula's desc is present
-          if desc_call.nil?
-            problem "Formula should have a desc (Description)."
-            return
-          end
-
-          # Check the formula's desc length. Should be >0 and <80 characters.
-          desc = parameters(desc_call).first
-          pure_desc_length = string_content(desc).length
-          if pure_desc_length.zero?
-            problem "The desc (description) should not be an empty string."
-            return
-          end
-
-          desc_length = "#{@formula_name}: #{string_content(desc)}".length
-          max_desc_length = 80
-          return if desc_length <= max_desc_length
-
-          problem "Description is too long. \"name: desc\" should be less than #{max_desc_length} characters. " \
-                  "Length is calculated as #{@formula_name} + desc. (currently #{desc_length})"
-        end
-      end
-    end
-
-    module FormulaAudit
-      # This cop audits `desc` in Formulae.
-      #
       # - Checks for leading/trailing whitespace in `desc`
       # - Checks if `desc` begins with an article
       # - Checks for correct usage of `command-line` in `desc`
@@ -49,23 +18,27 @@ module RuboCop
       # - Checks if `desc` ends with a full stop (apart from in the case of "etc.")
       class Desc < FormulaCop
         VALID_LOWERCASE_WORDS = %w[
-          ex
-          eXtensible
-          iOS
           macOS
-          malloc
-          ooc
-          preexec
-          x86
-          xUnit
         ].freeze
 
         def audit_formula(_node, _class_node, _parent_class_node, body_node)
           desc_call = find_node_method_by_name(body_node, :desc)
-          return if desc_call.nil?
+
+          # Check if a formula's desc is present
+          if desc_call.nil?
+            problem "Formula should have a desc (Description)."
+            return
+          end
 
           desc = parameters(desc_call).first
 
+          # Check the formula's desc length. Should be >0 and <80 characters.
+          pure_desc_length = string_content(desc).length
+          if pure_desc_length.zero?
+            problem "The desc (description) should not be an empty string."
+            return
+          end
+
           # Check for leading whitespace.
           problem "Description shouldn't have a leading space" if regex_match_group(desc, /^\s+/)
 
@@ -96,9 +69,16 @@ module RuboCop
           end
 
           # Check if a full stop is used at the end of a formula's desc (apart from in the case of "etc.")
-          return unless regex_match_group(desc, /\.$/) && !string_content(desc).end_with?("etc.")
+          if regex_match_group(desc, /\.$/) && !string_content(desc).end_with?("etc.")
+            problem "Description shouldn't end with a full stop"
+          end
 
-          problem "Description shouldn't end with a full stop"
+          desc_length = "#{@formula_name}: #{string_content(desc)}".length
+          max_desc_length = 80
+          return if desc_length <= max_desc_length
+
+          problem "Description is too long. \"name: desc\" should be less than #{max_desc_length} characters. " \
+                  "Length is calculated as #{@formula_name} + desc. (currently #{desc_length})"
         end
 
         def autocorrect(node)
diff --git a/Library/Homebrew/test/.rubocop_todo.yml b/Library/Homebrew/test/.rubocop_todo.yml
index 3dd7ea190e..7962795822 100644
--- a/Library/Homebrew/test/.rubocop_todo.yml
+++ b/Library/Homebrew/test/.rubocop_todo.yml
@@ -50,6 +50,7 @@ RSpec/FilePath:
     - 'rubocops/patches_spec.rb'
     - 'rubocops/text_spec.rb'
     - 'rubocops/uses_from_macos_spec.rb'
+    - 'rubocops/formula_desc_spec.rb'
     - 'search_spec.rb'
     - 'string_spec.rb'
     - 'system_command_result_spec.rb'
diff --git a/Library/Homebrew/test/rubocops/formula_desc_spec.rb b/Library/Homebrew/test/rubocops/formula_desc_spec.rb
index ee1a572f57..0b9f7dcb28 100644
--- a/Library/Homebrew/test/rubocops/formula_desc_spec.rb
+++ b/Library/Homebrew/test/rubocops/formula_desc_spec.rb
@@ -2,7 +2,7 @@
 
 require "rubocops/formula_desc"
 
-describe RuboCop::Cop::FormulaAudit::DescLength do
+describe RuboCop::Cop::FormulaAudit::Desc do
   subject(:cop) { described_class.new }
 
   context "When auditing formula desc" do
@@ -46,10 +46,6 @@ describe RuboCop::Cop::FormulaAudit::DescLength do
       RUBY
     end
   end
-end
-
-describe RuboCop::Cop::FormulaAudit::Desc do
-  subject(:cop) { described_class.new }
 
   context "When auditing formula desc" do
     it "When wrong \"command-line\" usage in desc" do
-- 
GitLab