diff --git a/Library/Homebrew/rubocops/shared/desc_helper.rb b/Library/Homebrew/rubocops/shared/desc_helper.rb index bfde588488..36c0c0a851 100644 --- a/Library/Homebrew/rubocops/shared/desc_helper.rb +++ b/Library/Homebrew/rubocops/shared/desc_helper.rb @@ -74,6 +74,9 @@ module RuboCop desc_problem "Description shouldn't end with a full stop." end + # Check if the desc contains Unicode emojis or symbols (Unicode Other Symbols category). + desc_problem "Description shouldn't contain Unicode emojis or symbols." if regex_match_group(desc, /\p{So}/) + # Check if the desc length exceeds maximum length. return if desc_length <= MAX_DESC_LENGTH @@ -103,6 +106,7 @@ module RuboCop correction.gsub!(/(ommand ?line)/i, "ommand-line") correction.gsub!(/(^|[^a-z])#{@name}([^a-z]|$)/i, "\\1\\2") + correction.gsub!(/\s?\p{So}/, "") correction.gsub!(/^\s+/, "") correction.gsub!(/\s+$/, "") correction.gsub!(/\.$/, "") diff --git a/Library/Homebrew/test/rubocops/cask/desc_spec.rb b/Library/Homebrew/test/rubocops/cask/desc_spec.rb index d219d39d50..0a95919bf5 100644 --- a/Library/Homebrew/test/rubocops/cask/desc_spec.rb +++ b/Library/Homebrew/test/rubocops/cask/desc_spec.rb @@ -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 Unicode emojis or symbols. + end + RUBY + expect_no_offenses <<~RUBY cask 'foo' do desc 'MAC address changer' diff --git a/Library/Homebrew/test/rubocops/desc_spec.rb b/Library/Homebrew/test/rubocops/desc_spec.rb index e8ad4c8e65..e5aa86d90b 100644 --- a/Library/Homebrew/test/rubocops/desc_spec.rb +++ b/Library/Homebrew/test/rubocops/desc_spec.rb @@ -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 Unicode emojis or symbols. + 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