Merge pull request #2795 from issyl0/desc_no_full_stops

formula_desc_cop: ensure no full stops at the end of desc
This commit is contained in:
Mike McQuaid 2017-10-29 16:56:00 +00:00 committed by GitHub
commit 215f49684b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 2 deletions

View File

@ -40,6 +40,7 @@ module RuboCop
# - Checks for correct usage of `command-line` in `desc` # - Checks for correct usage of `command-line` in `desc`
# - Checks description starts with a capital letter # - Checks description starts with a capital letter
# - Checks if `desc` contains the formula name # - Checks if `desc` contains the formula name
# - Checks if `desc` ends with a full stop
class Desc < FormulaCop class Desc < FormulaCop
VALID_LOWERCASE_WORDS = %w[ VALID_LOWERCASE_WORDS = %w[
ex ex
@ -78,8 +79,13 @@ module RuboCop
end end
# Check if formula's desc starts with formula's name # Check if formula's desc starts with formula's name
return unless regex_match_group(desc, /^#{@formula_name} /i) if regex_match_group(desc, /^#{@formula_name} /i)
problem "Description shouldn't start with the formula name" problem "Description shouldn't start with the formula name"
end
# Check if a full stop is used at the end of a formula's desc
return unless regex_match_group(desc, /\.$/)
problem "Description shouldn't end with a full stop"
end end
private private
@ -97,6 +103,7 @@ module RuboCop
correction.gsub!(/(^|[^a-z])#{@formula_name}([^a-z]|$)/i, "\\1\\2") correction.gsub!(/(^|[^a-z])#{@formula_name}([^a-z]|$)/i, "\\1\\2")
correction.gsub!(/^(['"]?)\s+/, "\\1") correction.gsub!(/^(['"]?)\s+/, "\\1")
correction.gsub!(/\s+(['"]?)$/, "\\1") correction.gsub!(/\s+(['"]?)$/, "\\1")
correction.gsub!(/\.$/, "")
corrector.insert_before(node.source_range, correction) corrector.insert_before(node.source_range, correction)
corrector.remove(node.source_range) corrector.remove(node.source_range)
end end

View File

@ -91,6 +91,16 @@ describe RuboCop::Cop::FormulaAuditStrict::Desc do
RUBY RUBY
end end
it "When the description ends with a full stop" do
expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb")
class Foo < Formula
url 'http://example.com/foo-1.0.tgz'
desc 'Description with a full stop at the end.'
^ Description shouldn\'t end with a full stop
end
RUBY
end
it "autocorrects all rules" do it "autocorrects all rules" do
source = <<~EOS source = <<~EOS
class Foo < Formula class Foo < Formula