Class: Cask::Cmd::Style

Inherits:
AbstractCommand show all
Defined in:
brew/Library/Homebrew/cask/cmd/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, run, visible

Methods included from Homebrew::Search

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

Methods included from Options

#process_arguments

Constructor Details

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

Class Method Details

.helpObject



6
7
8
# File 'brew/Library/Homebrew/cask/cmd/style.rb', line 6

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

Instance Method Details

#autocorrect_argsObject



58
59
60
# File 'brew/Library/Homebrew/cask/cmd/style.rb', line 58

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

#cask_pathsObject



32
33
34
35
36
37
38
39
40
# File 'brew/Library/Homebrew/cask/cmd/style.rb', line 32

def cask_paths
  @cask_paths ||= if args.empty?
    Tap.map(&:cask_dir).select(&:directory?)
  elsif args.any? { |file| File.exist?(file) }
    args.map { |path| Pathname(path).expand_path }
  else
    casks.map(&:sourcefile_path)
  end
end

#default_argsObject



46
47
48
49
50
51
52
# File 'brew/Library/Homebrew/cask/cmd/style.rb', line 46

def default_args
  [
    "--force-exclusion",
    "--config", "#{HOMEBREW_LIBRARY}/.rubocop_cask.yml",
    "--format", "simple"
  ]
end

#install_rubocopObject



22
23
24
25
26
27
28
29
30
# File 'brew/Library/Homebrew/cask/cmd/style.rb', line 22

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

#normal_argsObject



54
55
56
# File 'brew/Library/Homebrew/cask/cmd/style.rb', line 54

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

#rubocop_argsObject



42
43
44
# File 'brew/Library/Homebrew/cask/cmd/style.rb', line 42

def rubocop_args
  fix? ? autocorrect_args : normal_args
end

#runObject

Raises:



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

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