Class: Hbc::CLI::Style

Inherits:
AbstractCommand show all
Defined in:
Library/Homebrew/cask/lib/hbc/cli/style.rb

Instance Attribute Summary

Attributes inherited from AbstractCommand

#args

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractCommand

abstract?, command_name, #initialize, needs_init?, run, visible

Methods included from Options

included, #process_arguments

Constructor Details

This class inherits a constructor from Hbc::CLI::AbstractCommand

Class Method Details

.helpObject



4
5
6
# File 'Library/Homebrew/cask/lib/hbc/cli/style.rb', line 4

def self.help
  "checks Cask style using RuboCop"
end

Instance Method Details

#autocorrect_argsObject



54
55
56
# File 'Library/Homebrew/cask/lib/hbc/cli/style.rb', line 54

def autocorrect_args
  default_args + ["--auto-correct"]
end

#cask_pathsObject



28
29
30
31
32
33
34
35
36
# File 'Library/Homebrew/cask/lib/hbc/cli/style.rb', line 28

def cask_paths
  @cask_paths ||= if args.empty?
    Hbc.all_tapped_cask_dirs
  elsif args.any? { |file| File.exist?(file) }
    args
  else
    casks.map(&:sourcefile_path)
  end
end

#default_argsObject



42
43
44
45
46
47
48
# File 'Library/Homebrew/cask/lib/hbc/cli/style.rb', line 42

def default_args
  [
    "--require", "rubocop-cask",
    "--force-default-config",
    "--format", "simple"
  ]
end

#install_rubocopObject



18
19
20
21
22
23
24
25
26
# File 'Library/Homebrew/cask/lib/hbc/cli/style.rb', line 18

def install_rubocop
  capture_stderr do
    begin
      Homebrew.install_gem_setup_path! "rubocop-cask", HOMEBREW_RUBOCOP_CASK_VERSION, "rubocop"
    rescue SystemExit
      raise CaskError, Tty.strip_ansi($stderr.string).chomp.sub(/\AError: /, "")
    end
  end
end

#normal_argsObject



50
51
52
# File 'Library/Homebrew/cask/lib/hbc/cli/style.rb', line 50

def normal_args
  default_args + ["--parallel"]
end

#rubocop_argsObject



38
39
40
# File 'Library/Homebrew/cask/lib/hbc/cli/style.rb', line 38

def rubocop_args
  fix? ? autocorrect_args : normal_args
end

#runObject

Raises:



10
11
12
13
14
15
16
# File 'Library/Homebrew/cask/lib/hbc/cli/style.rb', line 10

def run
  install_rubocop
  cache_env = { "XDG_CACHE_HOME" => "#{HOMEBREW_CACHE}/style" }
  hide_warnings = debug? ? [] : [ENV["HOMEBREW_RUBY_PATH"], "-W0", "-S"]
  system(cache_env, *hide_warnings, "rubocop", *rubocop_args, "--", *cask_paths)
  raise CaskError, "style check failed" unless $CHILD_STATUS.success?
end