Class: Cask::Cmd::Audit Private

Inherits:
AbstractCommand show all
Defined in:
Library/Homebrew/cask/cmd/audit.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Implementation of the brew cask audit command.

Constant Summary

Constants inherited from AbstractCommand

Cask::Cmd::AbstractCommand::OPTIONS

Instance Attribute Summary

Attributes inherited from AbstractCommand

#args

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractCommand

abstract?, banner_args, banner_headline, command_name, help, #initialize, max_named, min_named, run, short_description, visible?

Methods included from Homebrew::Search

#query_regexp, #search_casks, #search_descriptions, #search_formulae, #search_taps

Constructor Details

This class inherits a constructor from Cask::Cmd::AbstractCommand

Class Method Details

.descriptionObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


12
13
14
15
16
17
18
19
# File 'Library/Homebrew/cask/cmd/audit.rb', line 12

def self.description
  <<~EOS
    Check <cask> for Homebrew coding style violations. This should be run before
    submitting a new cask. If no <cask> is provided, checks all locally
    available casks. Will exit with a non-zero status if any errors are
    found, which can be useful for implementing pre-commit hooks.
  EOS
end

.parserObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'Library/Homebrew/cask/cmd/audit.rb', line 21

def self.parser
  super do
    switch "--download",
           description: "Audit the downloaded file"
    switch "--[no-]appcast",
           description: "Audit the appcast"
    switch "--token-conflicts",
           description: "Audit for token conflicts"
    switch "--strict",
           description: "Run additional, stricter style checks"
    switch "--online",
           description: "Run additional, slower style checks that require a network connection"
    switch "--new-cask",
           description: "Run various additional style checks to determine if a new cask is eligible " \
                        "for Homebrew. This should be used when creating new casks and implies " \
                        "`--strict` and `--online`"
  end
end

Instance Method Details

#runObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Raises:


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'Library/Homebrew/cask/cmd/audit.rb', line 40

def run
  require "cask/auditor"

  Homebrew.auditing = true

  options = {
    audit_download:        args.download?,
    audit_appcast:         args.appcast?,
    audit_online:          args.online?,
    audit_strict:          args.strict?,
    audit_new_cask:        args.new_cask?,
    audit_token_conflicts: args.token_conflicts?,
    quarantine:            args.quarantine?,
    language:              args.language,
  }.compact

  options[:quarantine] = true if options[:quarantine].nil?

  casks = args.named.flat_map do |name|
    if File.exist?(name)
      name
    elsif name.count("/") == 1
      Tap.fetch(name).cask_files
    else
      name
    end
  end
  casks = casks.map { |c| CaskLoader.load(c, config: Config.from_args(args)) }
  casks = Cask.to_a if casks.empty?

  failed_casks = casks.reject do |cask|
    odebug "Auditing Cask #{cask}"
    result = Auditor.audit(cask, **options)

    if ENV["GITHUB_ACTIONS"]
      cask_path = cask.sourcefile_path
      annotations = (result[:warnings].map { |w| [:warning, w] } + result[:errors].map { |e| [:error, e] })
                    .map { |type, message| GitHub::Actions::Annotation.new(type, message, file: cask_path) }

      annotations.each do |annotation|
        puts annotation if annotation.relevant?
      end
    end

    result[:errors].empty?
  end

  return if failed_casks.empty?

  raise CaskError, "audit failed for casks: #{failed_casks.join(" ")}"
end