Improve detection of descriptions starting with cask/formula name.
This commit is contained in:
parent
f8c3a1bd61
commit
3038ff8726
@ -61,7 +61,8 @@ module RuboCop
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Check if the desc starts with the formula's or cask's name.
|
# 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.").
|
# 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.")
|
if regex_match_group(desc, /\.$/) && !string_content(desc).end_with?("etc.")
|
||||||
|
|||||||
@ -4,49 +4,63 @@ require "rubocops/rubocop-cask"
|
|||||||
require "test/rubocops/cask/shared_examples/cask_cop"
|
require "test/rubocops/cask/shared_examples/cask_cop"
|
||||||
|
|
||||||
describe RuboCop::Cop::Cask::Desc do
|
describe RuboCop::Cop::Cask::Desc do
|
||||||
include CaskCop
|
|
||||||
|
|
||||||
subject(:cop) { described_class.new }
|
subject(:cop) { described_class.new }
|
||||||
|
|
||||||
context "with incorrect `desc` stanza" do
|
it "does not start with an indefinite article" do
|
||||||
let(:source) {
|
expect_no_offenses <<~RUBY
|
||||||
<<~RUBY
|
cask "foo" do
|
||||||
cask "foo" do
|
desc "Bar program"
|
||||||
desc "A bar program"
|
end
|
||||||
end
|
RUBY
|
||||||
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"
|
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
|
||||||
|
|
||||||
include_examples "autocorrects source"
|
expect_correction <<~RUBY
|
||||||
|
cask 'foo' do
|
||||||
|
desc 'Bar program'
|
||||||
|
end
|
||||||
|
RUBY
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with correct `desc` stanza" do
|
it "does not start with the cask name" do
|
||||||
let(:source) {
|
expect_offense <<~RUBY, "/homebrew-cask/Casks/foo.rb"
|
||||||
<<~RUBY
|
cask 'foobar' do
|
||||||
cask "foo" do
|
desc 'Foo bar program'
|
||||||
desc "Bar program"
|
^^^^^^^ Description shouldn't start with the cask name.
|
||||||
end
|
end
|
||||||
RUBY
|
RUBY
|
||||||
}
|
|
||||||
|
|
||||||
include_examples "does not report any offenses"
|
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
|
||||||
|
|
||||||
|
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
|
||||||
end
|
end
|
||||||
|
|||||||
@ -104,7 +104,7 @@ 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 'Foo is a foobar'
|
desc 'Foo is a foobar'
|
||||||
^^^^ Description shouldn\'t start with the formula name.
|
^^^ Description shouldn\'t start with the formula name.
|
||||||
end
|
end
|
||||||
RUBY
|
RUBY
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user