Check for descriptions starting with “the”.

This commit is contained in:
Markus Reiter 2020-09-17 20:44:09 +02:00
parent 21d4c1ffc7
commit 9a48568226
3 changed files with 21 additions and 8 deletions

View File

@ -49,10 +49,8 @@ module RuboCop
problem "Description should use \"#{c}ommand-line\" instead of \"#{match}\"." problem "Description should use \"#{c}ommand-line\" instead of \"#{match}\"."
end end
# Check if the desc starts with "A" or "An". # Check if the desc starts with an article.
if match = regex_match_group(desc, /^(an?)(?=\s)/i) problem "Description shouldn't start with an article." if regex_match_group(desc, /^(the|an?)(?=\s)/i)
problem "Description shouldn't start with an indefinite article, i.e. \"#{match}\"."
end
# Check if invalid lowercase words are at the start of a desc. # Check if invalid lowercase words are at the start of a desc.
if !VALID_LOWERCASE_WORDS.include?(string_content(desc).split.first) && if !VALID_LOWERCASE_WORDS.include?(string_content(desc).split.first) &&
@ -91,7 +89,7 @@ module RuboCop
correction.gsub!(/^\s+/, "") correction.gsub!(/^\s+/, "")
correction.gsub!(/\s+$/, "") correction.gsub!(/\s+$/, "")
correction.sub!(/^an?\s+/i, "") correction.sub!(/^(the|an?)\s+/i, "")
first_word = correction.split.first first_word = correction.split.first
unless VALID_LOWERCASE_WORDS.include?(first_word) unless VALID_LOWERCASE_WORDS.include?(first_word)

View File

@ -6,7 +6,7 @@ require "test/rubocops/cask/shared_examples/cask_cop"
describe RuboCop::Cop::Cask::Desc do describe RuboCop::Cop::Cask::Desc do
subject(:cop) { described_class.new } 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 expect_no_offenses <<~RUBY
cask "foo" do cask "foo" do
desc "Bar program" desc "Bar program"
@ -16,7 +16,14 @@ describe RuboCop::Cop::Cask::Desc do
expect_offense <<~RUBY, "/homebrew-cask/Casks/foo.rb" expect_offense <<~RUBY, "/homebrew-cask/Casks/foo.rb"
cask 'foo' do cask 'foo' do
desc 'A bar program' 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 end
RUBY RUBY

View File

@ -84,7 +84,15 @@ describe RuboCop::Cop::FormulaAudit::Desc do
class Foo < Formula class Foo < Formula
url 'https://brew.sh/foo-1.0.tgz' url 'https://brew.sh/foo-1.0.tgz'
desc 'An aardvark' 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 end
RUBY RUBY
end end