2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-04-23 21:16:17 +02:00
|
|
|
require "cli/parser"
|
2020-08-09 01:34:07 +02:00
|
|
|
require "cask/auditor"
|
2020-04-23 21:16:17 +02:00
|
|
|
|
2018-09-06 08:29:14 +02:00
|
|
|
module Cask
|
2018-09-04 08:45:48 +01:00
|
|
|
class Cmd
|
2017-05-20 19:08:03 +02:00
|
|
|
class Audit < AbstractCommand
|
2020-08-01 02:30:46 +02:00
|
|
|
def self.description
|
2020-04-23 21:16:17 +02:00
|
|
|
<<~EOS
|
|
|
|
Check <cask> for Homebrew coding style violations. This should be run before
|
2020-08-01 02:30:46 +02:00
|
|
|
submitting a new cask. If no <cask> is provided, checks all locally
|
2020-04-23 21:16:17 +02:00
|
|
|
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
|
2017-05-21 00:15:56 +02:00
|
|
|
|
2020-08-01 02:30:46 +02:00
|
|
|
def self.parser
|
|
|
|
super do
|
|
|
|
switch "--download",
|
|
|
|
description: "Audit the downloaded file"
|
|
|
|
switch "--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
|
2016-09-24 13:52:43 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def run
|
2020-04-23 21:16:17 +02:00
|
|
|
Homebrew.auditing = true
|
2020-08-01 02:30:46 +02:00
|
|
|
strict = args.new_cask? || args.strict?
|
|
|
|
online = args.new_cask? || args.online?
|
|
|
|
|
|
|
|
options = {
|
|
|
|
audit_download: online || args.download?,
|
|
|
|
audit_appcast: online || args.appcast?,
|
|
|
|
audit_online: online,
|
|
|
|
audit_strict: strict,
|
|
|
|
audit_new_cask: args.new_cask?,
|
|
|
|
audit_token_conflicts: strict || args.token_conflicts?,
|
|
|
|
quarantine: args.quarantine?,
|
|
|
|
language: args.language,
|
|
|
|
}.compact
|
2020-04-23 21:16:17 +02:00
|
|
|
|
2020-08-01 02:30:46 +02:00
|
|
|
options[:quarantine] = true if options[:quarantine].nil?
|
2020-04-23 21:16:17 +02:00
|
|
|
|
2018-04-14 11:32:29 +02:00
|
|
|
failed_casks = casks(alternative: -> { Cask.to_a })
|
2020-04-23 21:16:17 +02:00
|
|
|
.reject do |cask|
|
|
|
|
odebug "Auditing Cask #{cask}"
|
2020-08-01 02:30:46 +02:00
|
|
|
result = Auditor.audit(cask, **options)
|
2020-07-28 09:08:37 +02:00
|
|
|
|
|
|
|
result[:warnings].empty? && result[:errors].empty?
|
2020-04-23 21:16:17 +02:00
|
|
|
end
|
2017-05-19 21:07:25 +02:00
|
|
|
|
|
|
|
return if failed_casks.empty?
|
2018-09-17 02:45:00 +02:00
|
|
|
|
2017-05-19 21:07:25 +02:00
|
|
|
raise CaskError, "audit failed for casks: #{failed_casks.join(" ")}"
|
2016-09-24 13:52:43 +02:00
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|