diff --git a/Library/Homebrew/rubocops/shared/desc_helper.rb b/Library/Homebrew/rubocops/shared/desc_helper.rb index 8f8db703565455ce67f027f55535064e7940e9c9..3ed62a036ba4653b95e06ebe6393f30cfbdee48c 100644 --- a/Library/Homebrew/rubocops/shared/desc_helper.rb +++ b/Library/Homebrew/rubocops/shared/desc_helper.rb @@ -8,6 +8,8 @@ module RuboCop module DescHelper include HelperFunctions + MAX_DESC_LENGTH = 80 + VALID_LOWERCASE_WORDS = %w[ iOS iPhone @@ -27,8 +29,8 @@ module RuboCop desc = desc_call.first_argument # Check if the desc is empty. - pure_desc_length = string_content(desc).length - if pure_desc_length.zero? + desc_length = string_content(desc).length + if desc_length.zero? problem "The desc (description) should not be an empty string." return end @@ -64,13 +66,11 @@ module RuboCop problem "Description shouldn't end with a full stop." end - # Check if the desc length exceeds 80 characters. - desc_length = "#{name}: #{string_content(desc)}".length - max_desc_length = 80 - return if desc_length <= max_desc_length + # Check if the desc length exceeds maximum length. + return if desc_length <= MAX_DESC_LENGTH - problem "Description is too long. \"name: desc\" should be less than #{max_desc_length} characters. " \ - "The current combined length is #{desc_length}." + problem "Description is too long. It should be less than #{MAX_DESC_LENGTH} characters. " \ + "The current length is #{desc_length}." end def autocorrect_desc(node, name) diff --git a/Library/Homebrew/test/rubocops/formula_desc_spec.rb b/Library/Homebrew/test/rubocops/formula_desc_spec.rb index 8f7ea8f8063e9850284a046d750fa580d8e00501..e7c7509e41305edf31bf7d6dbd18f194e1d48cf0 100644 --- a/Library/Homebrew/test/rubocops/formula_desc_spec.rb +++ b/Library/Homebrew/test/rubocops/formula_desc_spec.rb @@ -30,7 +30,7 @@ describe RuboCop::Cop::FormulaAudit::Desc do class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' desc 'Bar#{"bar" * 29}' - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Description is too long. "name: desc" should be less than 80 characters. The current combined length is 95. + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Description is too long. It should be less than 80 characters. The current length is 90. end RUBY end @@ -41,7 +41,7 @@ describe RuboCop::Cop::FormulaAudit::Desc do url 'https://brew.sh/foo-1.0.tgz' desc 'Bar#{"bar" * 9}'\ '#{"foo" * 21}' - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Description is too long. "name: desc" should be less than 80 characters. The current combined length is 98. + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Description is too long. It should be less than 80 characters. The current length is 93. end RUBY end