style: re-enable sha256 checks for bottle blocks

Follow up PR to #10450
This commit is contained in:
Michka Popoff 2021-01-28 19:32:23 +01:00
parent 26a3d4a544
commit 38ae6e0c0d
3 changed files with 38 additions and 6 deletions

View File

@ -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

View File

@ -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

View File

@ -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