Class: RuboCop::Cop::Cask::Sha256ArchOrder Private
Overview
This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.
This cop checks that the architecture keys of a cask's sha256 stanza are ordered
like the tags of a formula's bottle block: macOS before Linux, ARM before Intel.
Example
# bad
sha256 x86_64_linux: "...",
arm: "..."
# good
sha256 arm: "...",
x86_64_linux: "..."
Constant Summary collapse
- ARCH_ORDER =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
[:arm, :intel, :x86_64, :arm64_linux, :x86_64_linux].freeze
- MESSAGE =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
"`sha256` architecture keys should be ordered: arm, intel (or x86_64), arm64_linux, x86_64_linux"- STANZA_PREFIX =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
"sha256 "
Instance Method Summary collapse
Methods included from CaskHelp
#cask_tap, #inner_stanzas, #on_block, #on_cask, #on_system_methods
Instance Method Details
#on_cask_stanza_block(cask_stanza_block) ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'rubocops/cask/sha256_arch_order.rb', line 32 def on_cask_stanza_block(cask_stanza_block) cask_stanza_block.stanzas.each do |stanza| node = stanza.stanza_node next if stanza.stanza_name != :sha256 || !node.is_a?(RuboCop::AST::SendNode) hash_node = node.last_argument next if hash_node.nil? || !hash_node.hash_type? pairs = hash_node.pairs next unless pairs.all? { |pair| pair.key.sym_type? && ARCH_ORDER.include?(pair.key.value) } sorted = pairs.each_with_index .sort_by { |pair, index| [ARCH_ORDER.index(pair.key.value), index] } .map(&:first) next if pairs == sorted add_offense(node, message: MESSAGE) do |corrector| next if comments_in_range(node).any? corrector.replace(node.source_range, rebuild(node, sorted)) end end end |