diff --git a/Library/Homebrew/rubocops/checksum.rb b/Library/Homebrew/rubocops/checksum.rb index be355b7abc..e8035b8ee3 100644 --- a/Library/Homebrew/rubocops/checksum.rb +++ b/Library/Homebrew/rubocops/checksum.rb @@ -32,11 +32,7 @@ module RuboCop return end - checksum_string = string_content(checksum) - - return if checksum_string == "cellar" - - if checksum_string.size != 64 && regex_match_group(checksum, /^\w*$/) + if string_content(checksum).size != 64 && regex_match_group(checksum, /^\w*$/) problem "sha256 should be 64 characters" end diff --git a/Library/Homebrew/rubocops/extend/formula.rb b/Library/Homebrew/rubocops/extend/formula.rb index 5db318c1ef..bc52687969 100644 --- a/Library/Homebrew/rubocops/extend/formula.rb +++ b/Library/Homebrew/rubocops/extend/formula.rb @@ -126,7 +126,17 @@ module RuboCop parameters(call).first # sha256 is passed as a key-value pair in bottle blocks elsif parameters(call).first.hash_type? - parameters(call).first.keys.first + if parameters(call).first.keys.first.value == :cellar + # sha256 :cellar :any, :tag "hexdigest" + parameters(call).first.values.last + elsif parameters(call).first.keys.first.is_a?(RuboCop::AST::SymbolNode) + # sha256 :tag "hexdigest" + parameters(call).first.values.first + else + # Legacy bottle block syntax + # sha256 "hexdigest" => :tag + parameters(call).first.keys.first + end end end diff --git a/Library/Homebrew/test/rubocops/checksum_spec.rb b/Library/Homebrew/test/rubocops/checksum_spec.rb index 0372161d7e..7869f65b0f 100644 --- a/Library/Homebrew/test/rubocops/checksum_spec.rb +++ b/Library/Homebrew/test/rubocops/checksum_spec.rb @@ -63,6 +63,32 @@ describe RuboCop::Cop::FormulaAudit::Checksum do end RUBY end + + it "reports an offense if a checksum is not 64 characters in a bottle block without cellar" do + expect_offense(<<~RUBY) + class Foo < Formula + url 'https://brew.sh/foo-1.0.tgz' + + bottle do + sha256 catalina: "5cf6e1ae0a645b426c0474cc7cd3f7d1605ffa1ac5756a39a8b2268ddc7ea0e9ad" + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ sha256 should be 64 characters + end + end + RUBY + end + + it "reports an offense if a checksum is not 64 characters in a bottle block" do + expect_offense(<<~RUBY) + class Foo < Formula + url 'https://brew.sh/foo-1.0.tgz' + + bottle do + sha256 cellar: :any, catalina: "5cf6e1ae0a645b426c0474cc7cd3f7d1605ffa1ac5756a39a8b2268ddc7ea0e9ad" + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ sha256 should be 64 characters + end + end + RUBY + end end end