rubocops: add emoji audit

This commit is contained in:
Razvan Azamfirei 2023-06-20 08:10:30 -04:00
parent 9e747d8769
commit adf6278e3c
No known key found for this signature in database
GPG Key ID: 62E97BFCB12046BD
3 changed files with 30 additions and 0 deletions

View File

@ -74,6 +74,11 @@ module RuboCop
desc_problem "Description shouldn't end with a full stop."
end
# Check if the desc contains unicode characters in the So (emojis or other symbols) range.
if regex_match_group(desc, /\p{So}/)
desc_problem "Description shouldn't contain emojis or unicode characters in the So range."
end
# Check if the desc length exceeds maximum length.
return if desc_length <= MAX_DESC_LENGTH
@ -106,6 +111,7 @@ module RuboCop
correction.gsub!(/^\s+/, "")
correction.gsub!(/\s+$/, "")
correction.gsub!(/\.$/, "")
correction.gsub!(/\s?\p{So}/, "")
corrector.replace(@offensive_node.source_range, "#{quote}#{correction}#{quote}")
end

View File

@ -110,6 +110,13 @@ describe RuboCop::Cop::Cask::Desc, :config do
end
RUBY
expect_offense <<~RUBY
cask 'foo' do
desc 'Description with a 🍺 symbol'
^ Description shouldn't contain emojis or unicode characters in the So range.
end
RUBY
expect_no_offenses <<~RUBY
cask 'foo' do
desc 'MAC address changer'

View File

@ -134,6 +134,23 @@ describe RuboCop::Cop::FormulaAudit::Desc do
RUBY
end
it "reports and corrects an offense when the description contains Unicode So characters" do
expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb")
class Foo < Formula
url 'https://brew.sh/foo-1.0.tgz'
desc 'Description with a 🍺 symbol'
^ FormulaAudit/Desc: Description shouldn't contain emojis or unicode characters in the So range.
end
RUBY
expect_correction(<<~RUBY)
class Foo < Formula
url 'https://brew.sh/foo-1.0.tgz'
desc 'Description with a symbol'
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