Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve detection of descriptions starting with cask/formula name. #8328

Merged
merged 1 commit into from
Sep 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Library/Homebrew/rubocops/shared/desc_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ def audit_desc(type, name, desc_call)
end

# Check if the desc starts with the formula's or cask's name.
problem "Description shouldn't start with the #{type} name." if regex_match_group(desc, /^#{name} /i)
name_regex = name.delete("-").split("").join('[\s\-]?')
problem "Description shouldn't start with the #{type} name." if regex_match_group(desc, /^#{name_regex}\b/i)

# Check if a full stop is used at the end of a desc (apart from in the case of "etc.").
if regex_match_group(desc, /\.$/) && !string_content(desc).end_with?("etc.")
Expand Down
92 changes: 53 additions & 39 deletions Library/Homebrew/test/rubocops/cask/desc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,63 @@
require "test/rubocops/cask/shared_examples/cask_cop"

describe RuboCop::Cop::Cask::Desc do
include CaskCop

subject(:cop) { described_class.new }

context "with incorrect `desc` stanza" do
let(:source) {
<<~RUBY
cask "foo" do
desc "A bar program"
end
RUBY
}
let(:correct_source) {
<<~RUBY
cask "foo" do
desc "Bar program"
end
RUBY
}
let(:expected_offenses) do
[{
message: "Description shouldn't start with an indefinite article, i.e. \"A\".",
severity: :convention,
line: 2,
column: 8,
source: "A",
}]
end

include_examples "reports offenses"

include_examples "autocorrects source"
it "does not start with an indefinite article" do
expect_no_offenses <<~RUBY
cask "foo" do
desc "Bar program"
end
RUBY

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\".
end
RUBY

expect_correction <<~RUBY
cask 'foo' do
desc 'Bar program'
end
RUBY
end

context "with correct `desc` stanza" do
let(:source) {
<<~RUBY
cask "foo" do
desc "Bar program"
end
RUBY
}
it "does not start with the cask name" do
expect_offense <<~RUBY, "/homebrew-cask/Casks/foo.rb"
cask 'foobar' do
desc 'Foo bar program'
^^^^^^^ Description shouldn't start with the cask name.
end
RUBY

expect_offense <<~RUBY, "/homebrew-cask/Casks/foo.rb"
cask 'foobar' do
desc 'Foo-Bar program'
^^^^^^^ Description shouldn\'t start with the cask name.
end
RUBY

expect_offense <<~RUBY, "/homebrew-cask/Casks/foo.rb"
cask 'foo-bar' do
desc 'Foo bar program'
^^^^^^^ Description shouldn\'t start with the cask name.
end
RUBY

expect_offense <<~RUBY, "/homebrew-cask/Casks/foo.rb"
cask 'foo-bar' do
desc 'Foo-Bar program'
^^^^^^^ Description shouldn\'t start with the cask name.
end
RUBY

include_examples "does not report any offenses"
expect_offense <<~RUBY, "/homebrew-cask/Casks/foo.rb"
cask 'foo-bar' do
desc 'Foo Bar'
^^^^^^^ Description shouldn\'t start with the cask name.
end
RUBY
end
end
2 changes: 1 addition & 1 deletion Library/Homebrew/test/rubocops/formula_desc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class Foo < Formula
class Foo < Formula
url 'https://brew.sh/foo-1.0.tgz'
desc 'Foo is a foobar'
^^^^ Description shouldn\'t start with the formula name.
^^^ Description shouldn\'t start with the formula name.
end
RUBY
end
Expand Down