From adf6278e3c6410155f850274d0085bd59a8ada71 Mon Sep 17 00:00:00 2001 From: Razvan Azamfirei Date: Tue, 20 Jun 2023 08:10:30 -0400 Subject: [PATCH] rubocops: add emoji audit --- Library/Homebrew/rubocops/shared/desc_helper.rb | 6 ++++++ .../Homebrew/test/rubocops/cask/desc_spec.rb | 7 +++++++ Library/Homebrew/test/rubocops/desc_spec.rb | 17 +++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/Library/Homebrew/rubocops/shared/desc_helper.rb b/Library/Homebrew/rubocops/shared/desc_helper.rb index bfde588488..1043130db9 100644 --- a/Library/Homebrew/rubocops/shared/desc_helper.rb +++ b/Library/Homebrew/rubocops/shared/desc_helper.rb @@ -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 diff --git a/Library/Homebrew/test/rubocops/cask/desc_spec.rb b/Library/Homebrew/test/rubocops/cask/desc_spec.rb index d219d39d50..5b05d1bf44 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 emojis or unicode characters in the So range. + 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..b938eb263c 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 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