From 85a08bcdc4ab22e784cb595adcaeacf5e6283ba9 Mon Sep 17 00:00:00 2001 From: Michael Cho Date: Sat, 9 Mar 2024 11:32:16 -0500 Subject: [PATCH] cask/audit: allow @ for versioned casks Signed-off-by: Michael Cho --- Library/Homebrew/cask/audit.rb | 13 +++++--- Library/Homebrew/test/cask/audit_spec.rb | 40 +++++++++++++++++++++--- 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/Library/Homebrew/cask/audit.rb b/Library/Homebrew/cask/audit.rb index 2de2c4d32b..f2805902ef 100644 --- a/Library/Homebrew/cask/audit.rb +++ b/Library/Homebrew/cask/audit.rb @@ -407,17 +407,20 @@ module Cask add_error "cask token contains non-ascii characters" unless cask.token.ascii_only? add_error "cask token + should be replaced by -plus-" if cask.token.include? "+" add_error "cask token whitespace should be replaced by hyphens" if cask.token.include? " " - add_error "cask token @ should be replaced by -at-" if cask.token.include? "@" add_error "cask token underscores should be replaced by hyphens" if cask.token.include? "_" add_error "cask token should not contain double hyphens" if cask.token.include? "--" - if cask.token.match?(/[^a-z0-9-]/) - add_error "cask token should only contain lowercase alphanumeric characters and hyphens" + if cask.token.match?(/[^@a-z0-9-]/) + add_error "cask token should only contain lowercase alphanumeric characters, hyphens and @" end - return if !cask.token.start_with?("-") && !cask.token.end_with?("-") + if cask.token.start_with?("-", "@") || cask.token.end_with?("-", "@") + add_error "cask token should not have leading or trailing hyphens and/or @" + end - add_error "cask token should not have leading or trailing hyphens" + add_error "cask token @ unrelated to versioning should be replaced by -at-" if cask.token.count("@") > 1 + add_error "cask token should not contain a hyphen followed by @" if cask.token.include? "-@" + add_error "cask token should not contain @ followed by a hyphen" if cask.token.include? "@-" end sig { void } diff --git a/Library/Homebrew/test/cask/audit_spec.rb b/Library/Homebrew/test/cask/audit_spec.rb index 07281eb5ed..3c0ae7db0b 100644 --- a/Library/Homebrew/test/cask/audit_spec.rb +++ b/Library/Homebrew/test/cask/audit_spec.rb @@ -220,11 +220,43 @@ RSpec.describe Cask::Audit, :cask do end end - context "when cask token has @" do - let(:cask_token) { "app@stuff" } + context "when cask token is @-versioned with number" do + let(:cask_token) { "app@10" } + + it "does not fail" do + expect(run).to pass + end + end + + context "when cask token is @-versioned with word" do + let(:cask_token) { "app@beta" } + + it "does not fail" do + expect(run).to pass + end + end + + context "when cask token has multiple @" do + let(:cask_token) { "app@stuff@beta" } it "fails" do - expect(run).to error_with(/@ should be replaced by -at-/) + expect(run).to error_with(/@ unrelated to versioning should be replaced by -at-/) + end + end + + context "when cask token has a hyphen followed by @" do + let(:cask_token) { "app-@beta" } + + it "fails" do + expect(run).to error_with(/should not contain a hyphen followed by @/) + end + end + + context "when cask token has @ followed by a hyphen" do + let(:cask_token) { "app@-beta" } + + it "fails" do + expect(run).to error_with(/should not contain @ followed by a hyphen/) end end @@ -248,7 +280,7 @@ RSpec.describe Cask::Audit, :cask do let(:cask_token) { "app(stuff)" } it "fails" do - expect(run).to error_with(/alphanumeric characters and hyphens/) + expect(run).to error_with(/alphanumeric characters, hyphens and @/) end end