From 640b1e9dcb3fb96f6a54c0d63da4fb1985351a83 Mon Sep 17 00:00:00 2001 From: Isabell Long Date: Sat, 17 Jun 2017 07:12:46 +0100 Subject: [PATCH] formula_desc_cop: ensure no full stops at the end of desc - This was a suggestion by Mike McQuaid in my `homebrew-core` audit description PR. Based on ilovezfs's incantation `grep -r -E 'desc ".*\."' *.rb`, some formulae descriptions do end in full stops. (My initial assessment of this failed to account for the fact that descriptions are strings and so end in `"`.) - Add an autocorrect for this cop, too. --- Library/Homebrew/rubocops/formula_desc_cop.rb | 11 +++++++++-- .../Homebrew/test/rubocops/formula_desc_cop_spec.rb | 10 ++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/rubocops/formula_desc_cop.rb b/Library/Homebrew/rubocops/formula_desc_cop.rb index e56a4cc56f..69fbeb56e1 100644 --- a/Library/Homebrew/rubocops/formula_desc_cop.rb +++ b/Library/Homebrew/rubocops/formula_desc_cop.rb @@ -40,6 +40,7 @@ module RuboCop # - Checks for correct usage of `command-line` in `desc` # - Checks description starts with a capital letter # - Checks if `desc` contains the formula name + # - Checks if `desc` ends with a full stop class Desc < FormulaCop VALID_LOWERCASE_WORDS = %w[ ex @@ -78,8 +79,13 @@ module RuboCop end # Check if formula's desc starts with formula's name - return unless regex_match_group(desc, /^#{@formula_name} /i) - problem "Description shouldn't start with the formula name" + if regex_match_group(desc, /^#{@formula_name} /i) + problem "Description shouldn't start with the formula name" + end + + # Check if a full stop is used at the end of a formula's desc + return unless regex_match_group(desc, /\.$/) + problem "Description shouldn't end with a full stop" end private @@ -97,6 +103,7 @@ module RuboCop correction.gsub!(/(^|[^a-z])#{@formula_name}([^a-z]|$)/i, "\\1\\2") correction.gsub!(/^(['"]?)\s+/, "\\1") correction.gsub!(/\s+(['"]?)$/, "\\1") + correction.gsub!(/\.$/, "") corrector.insert_before(node.source_range, correction) corrector.remove(node.source_range) end diff --git a/Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb b/Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb index 3ddc42d344..aacb52ebb4 100644 --- a/Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb @@ -91,6 +91,16 @@ describe RuboCop::Cop::FormulaAuditStrict::Desc do RUBY end + it "When the description ends with a full stop" do + expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") + class Foo < Formula + url 'http://example.com/foo-1.0.tgz' + desc 'Description with a full stop at the end.' + ^ Description shouldn\'t end with a full stop + end + RUBY + end + it "autocorrects all rules" do source = <<~EOS class Foo < Formula