Merge pull request #4618 from DomT4/desc_tweaks
formula_desc_cop: add unnecessary whitespace check
This commit is contained in:
commit
172f6559ac
@ -38,6 +38,7 @@ module RuboCop
|
||||
module FormulaAuditStrict
|
||||
# This cop audits `desc` in Formulae
|
||||
#
|
||||
# - Checks for leading/trailing whitespace in `desc`
|
||||
# - Checks if `desc` begins with an article
|
||||
# - Checks for correct usage of `command-line` in `desc`
|
||||
# - Checks description starts with a capital letter
|
||||
@ -62,6 +63,16 @@ module RuboCop
|
||||
|
||||
desc = parameters(desc_call).first
|
||||
|
||||
# Check for leading whitespace.
|
||||
if regex_match_group(desc, /^\s+/)
|
||||
problem "Description shouldn't have a leading space"
|
||||
end
|
||||
|
||||
# Check for trailing whitespace.
|
||||
if regex_match_group(desc, /\s+$/)
|
||||
problem "Description shouldn't have a trailing space"
|
||||
end
|
||||
|
||||
# Check if command-line is wrongly used in formula's desc
|
||||
if match = regex_match_group(desc, /(command ?line)/i)
|
||||
c = match.to_s.chars.first
|
||||
@ -104,6 +115,8 @@ module RuboCop
|
||||
correction.gsub!(/^(['"]?)\s+/, "\\1")
|
||||
correction.gsub!(/\s+(['"]?)$/, "\\1")
|
||||
correction.gsub!(/\.(['"]?)$/, "\\1")
|
||||
correction.gsub!(/^\s+/, "")
|
||||
correction.gsub!(/\s+$/, "")
|
||||
corrector.insert_before(node.source_range, correction)
|
||||
corrector.remove(node.source_range)
|
||||
end
|
||||
|
||||
@ -65,7 +65,7 @@ describe RuboCop::Cop::FormulaAuditStrict::Desc do
|
||||
expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb")
|
||||
class Foo < Formula
|
||||
url 'http://example.com/foo-1.0.tgz'
|
||||
desc 'An '
|
||||
desc 'An aardvark'
|
||||
^^^ Description shouldn\'t start with an indefinite article i.e. \"An\"
|
||||
end
|
||||
RUBY
|
||||
@ -101,6 +101,26 @@ describe RuboCop::Cop::FormulaAuditStrict::Desc do
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "When the description starts with a leading space" do
|
||||
expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb")
|
||||
class Foo < Formula
|
||||
url 'http://example.com/foo-1.0.tgz'
|
||||
desc ' Description with a leading space'
|
||||
^ Description shouldn\'t have a leading space
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "When the description ends with a trailing space" do
|
||||
expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb")
|
||||
class Foo < Formula
|
||||
url 'http://example.com/foo-1.0.tgz'
|
||||
desc 'Description with a trailing space '
|
||||
^ Description shouldn\'t have a trailing space
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "autocorrects all rules" do
|
||||
source = <<~RUBY
|
||||
class Foo < Formula
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user