Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cask/audit: allow @ for versioned casks #16865

Merged
merged 1 commit into from Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 8 additions & 5 deletions Library/Homebrew/cask/audit.rb
Expand Up @@ -407,17 +407,20 @@ def audit_token_valid
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 }
Expand Down
40 changes: 36 additions & 4 deletions Library/Homebrew/test/cask/audit_spec.rb
Expand Up @@ -220,11 +220,43 @@ def tmp_cask(name, text)
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(/@ 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 be replaced by -at-/)
expect(run).to error_with(/should not contain @ followed by a hyphen/)
end
end

Expand All @@ -248,7 +280,7 @@ def tmp_cask(name, text)
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

Expand Down