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 Style < AbstractCommand
|
2016-09-24 13:52:43 +02:00
|
|
|
def self.help
|
|
|
|
"checks Cask style using RuboCop"
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2017-05-21 00:15:56 +02:00
|
|
|
option "--fix", :fix, false
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
def run
|
|
|
|
install_rubocop
|
2017-05-28 16:59:53 +01:00
|
|
|
cache_env = { "XDG_CACHE_HOME" => "#{HOMEBREW_CACHE}/style" }
|
2018-01-27 23:29:55 +01:00
|
|
|
hide_warnings = debug? ? [] : [ENV["HOMEBREW_RUBY_PATH"], "-W0", "-S"]
|
2018-10-16 14:54:39 +02:00
|
|
|
Dir.mktmpdir do |tmpdir|
|
|
|
|
system(cache_env, *hide_warnings, "rubocop", *rubocop_args, "--", *cask_paths, chdir: tmpdir)
|
|
|
|
end
|
2017-05-20 03:46:52 +02:00
|
|
|
raise CaskError, "style check failed" unless $CHILD_STATUS.success?
|
2016-09-24 13:52:43 +02:00
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
def install_rubocop
|
2017-03-07 18:02:31 +01:00
|
|
|
capture_stderr do
|
2016-09-24 13:52:43 +02:00
|
|
|
begin
|
2019-01-08 15:08:21 +00:00
|
|
|
Homebrew.install_bundler_gems!
|
2016-09-24 13:52:43 +02:00
|
|
|
rescue SystemExit
|
2016-08-26 16:04:47 +02:00
|
|
|
raise CaskError, Tty.strip_ansi($stderr.string).chomp.sub(/\AError: /, "")
|
2016-09-24 13:52:43 +02:00
|
|
|
end
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
def cask_paths
|
2017-05-21 00:15:56 +02:00
|
|
|
@cask_paths ||= if args.empty?
|
2018-04-14 11:32:29 +02:00
|
|
|
Tap.map(&:cask_dir).select(&:directory?)
|
2017-05-21 00:15:56 +02:00
|
|
|
elsif args.any? { |file| File.exist?(file) }
|
2018-10-17 01:50:39 +02:00
|
|
|
args.map { |path| Pathname(path).expand_path }
|
2016-10-14 20:11:33 +02:00
|
|
|
else
|
2017-06-13 17:14:01 +02:00
|
|
|
casks.map(&:sourcefile_path)
|
2016-10-14 20:11:33 +02:00
|
|
|
end
|
2016-09-24 13:52:43 +02:00
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
def rubocop_args
|
2018-01-29 07:45:30 +10:00
|
|
|
fix? ? autocorrect_args : normal_args
|
2016-09-24 13:52:43 +02:00
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
def default_args
|
2016-10-18 16:10:36 +02:00
|
|
|
[
|
2018-11-07 15:41:46 +00:00
|
|
|
"--force-exclusion",
|
2018-11-12 04:46:47 +01:00
|
|
|
"--config", "#{HOMEBREW_LIBRARY}/.rubocop_cask.yml",
|
2018-01-29 07:45:30 +10:00
|
|
|
"--format", "simple"
|
2016-10-18 16:10:36 +02:00
|
|
|
]
|
2016-09-24 13:52:43 +02:00
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2018-01-29 07:45:30 +10:00
|
|
|
def normal_args
|
|
|
|
default_args + ["--parallel"]
|
|
|
|
end
|
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
def autocorrect_args
|
|
|
|
default_args + ["--auto-correct"]
|
|
|
|
end
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
end
|