167 lines
5.8 KiB
Ruby
Raw Normal View History

2020-10-10 14:16:11 +02:00
# typed: false
# frozen_string_literal: true
2023-02-20 10:22:39 -08:00
require "rubocops/desc"
describe RuboCop::Cop::FormulaAudit::Desc do
subject(:cop) { described_class.new }
context "when auditing formula `desc` methods" do
2021-01-12 18:12:56 +11:00
it "reports an offense when there is no `desc`" do
2017-10-21 03:12:50 +02:00
expect_offense(<<~RUBY)
class Foo < Formula
2017-10-21 03:12:50 +02:00
^^^^^^^^^^^^^^^^^^^ Formula should have a desc (Description).
url 'https://brew.sh/foo-1.0.tgz'
end
2017-10-21 03:12:50 +02:00
RUBY
end
2021-01-12 18:12:56 +11:00
it "reports an offense when `desc` is an empty string" do
2017-10-21 03:12:50 +02:00
expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb")
class Foo < Formula
url 'https://brew.sh/foo-1.0.tgz'
desc ''
2017-10-21 03:12:50 +02:00
^^^^^^^ The desc (description) should not be an empty string.
end
2017-10-21 03:12:50 +02:00
RUBY
end
2021-01-12 18:12:56 +11:00
it "reports an offense when `desc` is too long" do
2017-10-21 03:12:50 +02:00
expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb")
class Foo < Formula
url 'https://brew.sh/foo-1.0.tgz'
desc 'Bar#{"bar" * 29}'
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Description is too long. It should be less than 80 characters. The current length is 90.
end
2017-10-21 03:12:50 +02:00
RUBY
end
2021-01-12 18:12:56 +11:00
it "reports an offense when `desc` is a multiline string" do
2017-10-21 03:12:50 +02:00
expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb")
class Foo < Formula
url 'https://brew.sh/foo-1.0.tgz'
desc 'Bar#{"bar" * 9}'\
2017-06-01 16:06:51 +02:00
'#{"foo" * 21}'
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Description is too long. It should be less than 80 characters. The current length is 93.
end
2017-10-21 03:12:50 +02:00
RUBY
end
end
context "when auditing formula description texts" do
2021-01-12 18:12:56 +11:00
it "reports an offense when the description starts with a leading space" do
2017-10-21 03:12:50 +02:00
expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb")
class Foo < Formula
url 'https://brew.sh/foo-1.0.tgz'
desc ' Description with a leading space'
2021-01-12 18:12:56 +11:00
^ Description shouldn't have leading spaces.
end
2017-10-21 03:12:50 +02:00
RUBY
end
2021-01-12 18:12:56 +11:00
it "reports an offense when the description ends with a trailing space" do
2017-10-21 03:12:50 +02:00
expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb")
class Foo < Formula
url 'https://brew.sh/foo-1.0.tgz'
desc 'Description with a trailing space '
2021-01-12 18:12:56 +11:00
^ Description shouldn't have trailing spaces.
end
2017-10-21 03:12:50 +02:00
RUBY
end
2021-01-12 18:12:56 +11:00
it "reports an offense when \"command-line\" is incorrectly spelled in the description" do
2017-10-21 03:12:50 +02:00
expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb")
class Foo < Formula
url 'https://brew.sh/foo-1.0.tgz'
desc 'command line'
^ Description should start with a capital letter.
2021-01-12 18:12:56 +11:00
^^^^^^^^^^^^ Description should use "command-line" instead of "command line".
end
2017-10-21 03:12:50 +02:00
RUBY
end
2021-01-12 18:12:56 +11:00
it "reports an offense when an article is used in the description" do
2017-10-21 03:12:50 +02:00
expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb")
class Foo < Formula
url 'https://brew.sh/foo-1.0.tgz'
desc 'An aardvark'
2022-12-13 10:54:22 +00:00
^^ 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'
2022-12-13 10:54:22 +00:00
^^^ Description shouldn't start with an article.
end
2017-10-21 03:12:50 +02:00
RUBY
end
2021-01-12 18:12:56 +11:00
it "reports an offense when the description starts with a lowercase letter" do
expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb")
class Foo < Formula
url 'https://brew.sh/foo-1.0.tgz'
desc 'bar'
^ Description should start with a capital letter.
end
RUBY
end
2021-01-12 18:12:56 +11:00
it "reports an offense when the description starts with the formula name" do
expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb")
class Foo < Formula
url 'https://brew.sh/foo-1.0.tgz'
desc 'Foo is a foobar'
2022-12-13 10:54:22 +00:00
^^^ Description shouldn't start with the formula name.
end
RUBY
end
it "report and corrects an offense when the description ends with a full stop" do
expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb")
class Foo < Formula
url 'https://brew.sh/foo-1.0.tgz'
desc 'Description with a full stop at the end.'
^ Description shouldn't end with a full stop.
end
RUBY
expect_correction(<<~RUBY)
class Foo < Formula
url 'https://brew.sh/foo-1.0.tgz'
desc 'Description with a full stop at the end'
end
RUBY
end
it "does not report an offense when the description ends with 'etc.'" do
expect_no_offenses(<<~RUBY, "/homebrew-core/Formula/foo.rb")
class Foo < Formula
url 'https://brew.sh/foo-1.0.tgz'
desc 'Description of a thing and some more things and some more etc.'
end
RUBY
end
2021-01-12 18:12:56 +11:00
it "reports and corrects all rules for description text" do
expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb")
class Foo < Formula
url 'https://brew.sh/foo-1.0.tgz'
desc ' an bar: commandline foo '
2021-01-12 18:12:56 +11:00
^ Description shouldn't have trailing spaces.
^^^^^^^^^^^ Description should use "command-line" instead of "commandline".
^ Description shouldn't have leading spaces.
end
2018-07-11 15:17:40 +02:00
RUBY
2017-10-21 03:12:50 +02:00
2021-01-12 18:12:56 +11:00
expect_correction(<<~RUBY)
class Foo < Formula
url 'https://brew.sh/foo-1.0.tgz'
desc 'Bar: command-line'
end
2018-07-11 15:17:40 +02:00
RUBY
end
end
end