From 9a4856822609d716bcf7ab1ad51452feed9d93e6 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Thu, 17 Sep 2020 20:44:09 +0200 Subject: [PATCH] =?UTF-8?q?Check=20for=20descriptions=20starting=20with=20?= =?UTF-8?q?=E2=80=9Cthe=E2=80=9D.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Library/Homebrew/rubocops/shared/desc_helper.rb | 8 +++----- Library/Homebrew/test/rubocops/cask/desc_spec.rb | 11 +++++++++-- Library/Homebrew/test/rubocops/formula_desc_spec.rb | 10 +++++++++- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Library/Homebrew/rubocops/shared/desc_helper.rb b/Library/Homebrew/rubocops/shared/desc_helper.rb index e393b7835b..0fed61c689 100644 --- a/Library/Homebrew/rubocops/shared/desc_helper.rb +++ b/Library/Homebrew/rubocops/shared/desc_helper.rb @@ -49,10 +49,8 @@ module RuboCop problem "Description should use \"#{c}ommand-line\" instead of \"#{match}\"." end - # Check if the desc starts with "A" or "An". - if match = regex_match_group(desc, /^(an?)(?=\s)/i) - problem "Description shouldn't start with an indefinite article, i.e. \"#{match}\"." - end + # Check if the desc starts with an article. + problem "Description shouldn't start with an article." if regex_match_group(desc, /^(the|an?)(?=\s)/i) # Check if invalid lowercase words are at the start of a desc. if !VALID_LOWERCASE_WORDS.include?(string_content(desc).split.first) && @@ -91,7 +89,7 @@ module RuboCop correction.gsub!(/^\s+/, "") correction.gsub!(/\s+$/, "") - correction.sub!(/^an?\s+/i, "") + correction.sub!(/^(the|an?)\s+/i, "") first_word = correction.split.first unless VALID_LOWERCASE_WORDS.include?(first_word) diff --git a/Library/Homebrew/test/rubocops/cask/desc_spec.rb b/Library/Homebrew/test/rubocops/cask/desc_spec.rb index 8b06c40a12..8d35342fe1 100644 --- a/Library/Homebrew/test/rubocops/cask/desc_spec.rb +++ b/Library/Homebrew/test/rubocops/cask/desc_spec.rb @@ -6,7 +6,7 @@ require "test/rubocops/cask/shared_examples/cask_cop" describe RuboCop::Cop::Cask::Desc do subject(:cop) { described_class.new } - it "does not start with an indefinite article" do + it "does not start with an article" do expect_no_offenses <<~RUBY cask "foo" do desc "Bar program" @@ -16,7 +16,14 @@ describe RuboCop::Cop::Cask::Desc do expect_offense <<~RUBY, "/homebrew-cask/Casks/foo.rb" cask 'foo' do desc 'A bar program' - ^ Description shouldn\'t start with an indefinite article, i.e. \"A\". + ^ Description shouldn\'t start with an article. + end + RUBY + + expect_offense <<~RUBY, "/homebrew-cask/Casks/foo.rb" + cask 'foo' do + desc 'The bar program' + ^^^ Description shouldn\'t start with an article. end RUBY diff --git a/Library/Homebrew/test/rubocops/formula_desc_spec.rb b/Library/Homebrew/test/rubocops/formula_desc_spec.rb index e3bd25f62a..5d85184ef3 100644 --- a/Library/Homebrew/test/rubocops/formula_desc_spec.rb +++ b/Library/Homebrew/test/rubocops/formula_desc_spec.rb @@ -84,7 +84,15 @@ describe RuboCop::Cop::FormulaAudit::Desc do class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' desc 'An aardvark' - ^^ Description shouldn\'t start with an indefinite article, i.e. \"An\". + ^^ Description shouldn\'t start with an article. + end + RUBY + + expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") + class Foo < Formula + url 'https://brew.sh/foo-1.0.tgz' + desc 'The aardvark' + ^^^ Description shouldn\'t start with an article. end RUBY end