
Currently the tests casks found in "/Homebrew/test/support/fixtures/cask/Casks" and "/Homebrew/test/support/fixtures/third-party/Casks" aren't included in the paths checked when running "brew cask style". This change includes these test cask paths in the checked paths, and also includes the auto style fixes made by running `brew cask style --fix`.
71 lines
1.8 KiB
Ruby
71 lines
1.8 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module Cask
|
|
class Cmd
|
|
class Style < AbstractCommand
|
|
def self.help
|
|
"checks Cask style using RuboCop"
|
|
end
|
|
|
|
option "--fix", :fix, false
|
|
|
|
def run
|
|
install_rubocop
|
|
cache_env = { "XDG_CACHE_HOME" => "#{HOMEBREW_CACHE}/style" }
|
|
hide_warnings = debug? ? [] : [ENV["HOMEBREW_RUBY_PATH"], "-W0", "-S"]
|
|
Dir.mktmpdir do |tmpdir|
|
|
system(cache_env, *hide_warnings, "rubocop", *rubocop_args, "--", *cask_paths, chdir: tmpdir)
|
|
end
|
|
raise CaskError, "style check failed" unless $CHILD_STATUS.success?
|
|
end
|
|
|
|
def install_rubocop
|
|
capture_stderr do
|
|
begin
|
|
Homebrew.install_bundler_gems!
|
|
rescue SystemExit
|
|
raise CaskError, Tty.strip_ansi($stderr.string).chomp.sub(/\AError: /, "")
|
|
end
|
|
end
|
|
end
|
|
|
|
def cask_paths
|
|
@cask_paths ||= if args.empty?
|
|
Tap.map(&:cask_dir).select(&:directory?).concat(test_cask_paths)
|
|
elsif args.any? { |file| File.exist?(file) }
|
|
args.map { |path| Pathname(path).expand_path }
|
|
else
|
|
casks.map(&:sourcefile_path)
|
|
end
|
|
end
|
|
|
|
def rubocop_args
|
|
fix? ? autocorrect_args : normal_args
|
|
end
|
|
|
|
def default_args
|
|
[
|
|
"--force-exclusion",
|
|
"--config", "#{HOMEBREW_LIBRARY}/.rubocop_cask.yml",
|
|
"--format", "simple"
|
|
]
|
|
end
|
|
|
|
def test_cask_paths
|
|
[
|
|
Pathname.new("#{HOMEBREW_LIBRARY}/Homebrew/test/support/fixtures/cask/Casks"),
|
|
Pathname.new("#{HOMEBREW_LIBRARY}/Homebrew/test/support/fixtures/third-party/Casks"),
|
|
]
|
|
end
|
|
|
|
def normal_args
|
|
default_args + ["--parallel"]
|
|
end
|
|
|
|
def autocorrect_args
|
|
default_args + ["--auto-correct"]
|
|
end
|
|
end
|
|
end
|
|
end
|