Cask::Auditor: update language_blocks condition

I recently modified `Cask::DSL` to define instance variables in the
`#initialize` method and this involved some changes to the `language`,
`language_eval`, and `languages` methods. One of those was to
initialize `@language_blocks` to an empty hash instead of using a
`nil` default. I updated the related condition in the `language_eval`
method but I missed that `language_blocks` is used in `Cask::Auditor`
and it specifically relies on a false-y value to check if the variable
is set. An empty hash isn't false-y, so this is causing issues for
`brew audit`.

This updates the condition in `Cask::Auditor` to check for a non-empty
hash instead, which resolves the issue.
This commit is contained in:
Sam Ford 2025-04-23 09:16:38 -04:00
parent 8db1a1f639
commit c0f23acdcd
No known key found for this signature in database
GPG Key ID: 7AF5CBEE1DD6F76D

View File

@ -74,7 +74,7 @@ module Cask
def audit
errors = Set.new
if !language && (blocks = language_blocks)
if !language && !(blocks = language_blocks).empty?
sample_languages = if blocks.length > LANGUAGE_BLOCK_LIMIT && !@audit_new_cask
sample_keys = T.must(blocks.keys.sample(LANGUAGE_BLOCK_LIMIT))
ohai "Auditing a sample of available languages for #{cask}: " \
@ -140,7 +140,7 @@ module Cask
audit.run!
end
sig { returns(T.nilable(T::Hash[T::Array[String], T.proc.returns(T.untyped)])) }
sig { returns(T::Hash[T::Array[String], T.proc.returns(T.untyped)]) }
def language_blocks
cask.instance_variable_get(:@dsl).instance_variable_get(:@language_blocks)
end