From adf6278e3c6410155f850274d0085bd59a8ada71 Mon Sep 17 00:00:00 2001 From: Razvan Azamfirei Date: Tue, 20 Jun 2023 08:10:30 -0400 Subject: [PATCH 1/5] 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 From c1009247bfb91f09b4a09820afd3427bf09f3242 Mon Sep 17 00:00:00 2001 From: Razvan Azamfirei Date: Tue, 20 Jun 2023 08:59:01 -0400 Subject: [PATCH 2/5] Apply suggestions from code review Co-authored-by: FX Coudert --- Library/Homebrew/rubocops/shared/desc_helper.rb | 4 ++-- Library/Homebrew/test/rubocops/cask/desc_spec.rb | 2 +- Library/Homebrew/test/rubocops/desc_spec.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/rubocops/shared/desc_helper.rb b/Library/Homebrew/rubocops/shared/desc_helper.rb index 1043130db9..6acab4a3e1 100644 --- a/Library/Homebrew/rubocops/shared/desc_helper.rb +++ b/Library/Homebrew/rubocops/shared/desc_helper.rb @@ -74,9 +74,9 @@ 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. + # 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." + desc_problem "Description shouldn't contain emojis or Unicode characters in the So range." end # Check if the desc length exceeds maximum length. diff --git a/Library/Homebrew/test/rubocops/cask/desc_spec.rb b/Library/Homebrew/test/rubocops/cask/desc_spec.rb index 5b05d1bf44..65ea26fdd2 100644 --- a/Library/Homebrew/test/rubocops/cask/desc_spec.rb +++ b/Library/Homebrew/test/rubocops/cask/desc_spec.rb @@ -113,7 +113,7 @@ describe RuboCop::Cop::Cask::Desc, :config do expect_offense <<~RUBY cask 'foo' do desc 'Description with a 🍺 symbol' - ^ Description shouldn't contain emojis or unicode characters in the So range. + ^ Description shouldn't contain emojis or Unicode characters in the So range. end RUBY diff --git a/Library/Homebrew/test/rubocops/desc_spec.rb b/Library/Homebrew/test/rubocops/desc_spec.rb index b938eb263c..da21c686b8 100644 --- a/Library/Homebrew/test/rubocops/desc_spec.rb +++ b/Library/Homebrew/test/rubocops/desc_spec.rb @@ -139,7 +139,7 @@ describe RuboCop::Cop::FormulaAudit::Desc do 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. + ^ FormulaAudit/Desc: Description shouldn't contain emojis or Unicode characters in the So range. end RUBY From a3ee3650cba754c565591590517f55ac469441bf Mon Sep 17 00:00:00 2001 From: Razvan Azamfirei Date: Tue, 20 Jun 2023 11:24:35 -0400 Subject: [PATCH 3/5] Update Library/Homebrew/rubocops/shared/desc_helper.rb Co-authored-by: Mike McQuaid --- Library/Homebrew/rubocops/shared/desc_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/rubocops/shared/desc_helper.rb b/Library/Homebrew/rubocops/shared/desc_helper.rb index 6acab4a3e1..89b16cb94a 100644 --- a/Library/Homebrew/rubocops/shared/desc_helper.rb +++ b/Library/Homebrew/rubocops/shared/desc_helper.rb @@ -76,7 +76,7 @@ module RuboCop # 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." + desc_problem "Description shouldn't contain Unicode emojis or symbols." end # Check if the desc length exceeds maximum length. From b1baca772021f0408850a3a83097014c0ca61cc3 Mon Sep 17 00:00:00 2001 From: Razvan Azamfirei Date: Tue, 20 Jun 2023 11:33:49 -0400 Subject: [PATCH 4/5] rephrase failure message --- Library/Homebrew/test/rubocops/cask/desc_spec.rb | 2 +- Library/Homebrew/test/rubocops/desc_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/test/rubocops/cask/desc_spec.rb b/Library/Homebrew/test/rubocops/cask/desc_spec.rb index 65ea26fdd2..0a95919bf5 100644 --- a/Library/Homebrew/test/rubocops/cask/desc_spec.rb +++ b/Library/Homebrew/test/rubocops/cask/desc_spec.rb @@ -113,7 +113,7 @@ describe RuboCop::Cop::Cask::Desc, :config do expect_offense <<~RUBY cask 'foo' do desc 'Description with a 🍺 symbol' - ^ Description shouldn't contain emojis or Unicode characters in the So range. + ^ Description shouldn't contain Unicode emojis or symbols. end RUBY diff --git a/Library/Homebrew/test/rubocops/desc_spec.rb b/Library/Homebrew/test/rubocops/desc_spec.rb index da21c686b8..e5aa86d90b 100644 --- a/Library/Homebrew/test/rubocops/desc_spec.rb +++ b/Library/Homebrew/test/rubocops/desc_spec.rb @@ -139,7 +139,7 @@ describe RuboCop::Cop::FormulaAudit::Desc do 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. + ^ FormulaAudit/Desc: Description shouldn't contain Unicode emojis or symbols. end RUBY From c355723fe5b20d0d0ccd34bbc334e832f8b9b695 Mon Sep 17 00:00:00 2001 From: Razvan Azamfirei Date: Tue, 20 Jun 2023 11:36:47 -0400 Subject: [PATCH 5/5] fix desc auto-correct order --- Library/Homebrew/rubocops/shared/desc_helper.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/rubocops/shared/desc_helper.rb b/Library/Homebrew/rubocops/shared/desc_helper.rb index 89b16cb94a..36c0c0a851 100644 --- a/Library/Homebrew/rubocops/shared/desc_helper.rb +++ b/Library/Homebrew/rubocops/shared/desc_helper.rb @@ -74,10 +74,8 @@ 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 Unicode emojis or symbols." - 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 @@ -108,10 +106,10 @@ 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!(/\.$/, "") - correction.gsub!(/\s?\p{So}/, "") corrector.replace(@offensive_node.source_range, "#{quote}#{correction}#{quote}") end