From 6994556d193f42f9e138024aac32a564f8b7e592 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Tue, 1 Sep 2020 13:18:59 +0200 Subject: [PATCH 1/2] Don't allow platform in cask descriptions. --- .../Homebrew/rubocops/shared/desc_helper.rb | 4 +++ .../Homebrew/test/rubocops/cask/desc_spec.rb | 36 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/Library/Homebrew/rubocops/shared/desc_helper.rb b/Library/Homebrew/rubocops/shared/desc_helper.rb index 63cc95537c..5e1e273c51 100644 --- a/Library/Homebrew/rubocops/shared/desc_helper.rb +++ b/Library/Homebrew/rubocops/shared/desc_helper.rb @@ -64,6 +64,10 @@ module RuboCop name_regex = name.delete("-").split("").join('[\s\-]?') problem "Description shouldn't start with the #{type} name." if regex_match_group(desc, /^#{name_regex}\b/i) + if type == :cask && match = regex_match_group(desc, /\b(macOS|Mac( ?OS( ?X)?)?|OS ?X)\b/i) + problem "Description shouldn't contain the platform." unless match[1] == "MAC" + end + # Check if a full stop is used at the end of a desc (apart from in the case of "etc."). if regex_match_group(desc, /\.$/) && !string_content(desc).end_with?("etc.") problem "Description shouldn't end with a full stop." diff --git a/Library/Homebrew/test/rubocops/cask/desc_spec.rb b/Library/Homebrew/test/rubocops/cask/desc_spec.rb index 38793ccf99..8b06c40a12 100644 --- a/Library/Homebrew/test/rubocops/cask/desc_spec.rb +++ b/Library/Homebrew/test/rubocops/cask/desc_spec.rb @@ -63,4 +63,40 @@ describe RuboCop::Cop::Cask::Desc do end RUBY end + + it "does not contain the platform" do + expect_offense <<~RUBY, "/homebrew-cask/Casks/foo.rb" + cask 'foo-bar' do + desc 'macOS status bar monitor' + ^^^^^ Description shouldn\'t contain the platform. + end + RUBY + + expect_offense <<~RUBY, "/homebrew-cask/Casks/foo.rb" + cask 'foo-bar' do + desc 'Toggles dark mode on Mac OS Mojave' + ^^^^^^ Description shouldn\'t contain the platform. + end + RUBY + + expect_offense <<~RUBY, "/homebrew-cask/Casks/foo.rb" + cask 'foo-bar' do + desc 'Better input source switcher for OS X' + ^^^^ Description shouldn\'t contain the platform. + end + RUBY + + expect_offense <<~RUBY, "/homebrew-cask/Casks/foo.rb" + cask 'foo-bar' do + desc 'Media Manager for Mac OS X' + ^^^^^^^^ Description shouldn\'t contain the platform. + end + RUBY + + expect_no_offenses <<~RUBY + cask 'foo' do + desc 'MAC address changer' + end + RUBY + end end From f32b2e0515e6860fd24d3aadad09712a7386d511 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Tue, 1 Sep 2020 13:59:24 +0200 Subject: [PATCH 2/2] Switch `unless` to `if`. 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 5e1e273c51..e780ad4503 100644 --- a/Library/Homebrew/rubocops/shared/desc_helper.rb +++ b/Library/Homebrew/rubocops/shared/desc_helper.rb @@ -65,7 +65,7 @@ module RuboCop problem "Description shouldn't start with the #{type} name." if regex_match_group(desc, /^#{name_regex}\b/i) if type == :cask && match = regex_match_group(desc, /\b(macOS|Mac( ?OS( ?X)?)?|OS ?X)\b/i) - problem "Description shouldn't contain the platform." unless match[1] == "MAC" + problem "Description shouldn't contain the platform." if match[1] != "MAC" end # Check if a full stop is used at the end of a desc (apart from in the case of "etc.").