Module: Rubocop::Stylecheck::Cli

Defined in:
lib/rubocop/stylecheck/cli.rb

Class Method Summary collapse

Class Method Details

.direct_run(options) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rubocop/stylecheck/cli.rb', line 13

def direct_run(options)
  require "rubocop"
  require "benchmark"

  cli = RuboCop::CLI.new
  result = 0

  time = Benchmark.realtime do
    result = cli.run(options)
  end

  puts "Finished in #{time} seconds" if cli.options[:debug]
  exit result
end

.optionsObject



34
35
36
37
38
# File 'lib/rubocop/stylecheck/cli.rb', line 34

def options
  options = ["--fail-level", "refactor"]
  options += ["--rails"] if defined?(Rails)
  options
end

.options_with_auto_correctObject



40
41
42
# File 'lib/rubocop/stylecheck/cli.rb', line 40

def options_with_auto_correct
  options + ["--auto-correct"]
end

.options_with_copObject



44
45
46
# File 'lib/rubocop/stylecheck/cli.rb', line 44

def options_with_cop
  options + ["--display-cop-names"]
end

.run(options) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/rubocop/stylecheck/cli.rb', line 5

def run(options)
  if Rubocop::Stylecheck.direct
    direct_run(options)
  else
    run_via_sh(options)
  end
end

.run_via_sh(options) ⇒ Object



28
29
30
31
32
# File 'lib/rubocop/stylecheck/cli.rb', line 28

def run_via_sh(options)
  system "bundle exec rubocop #{options.join(' ')}" do |ok, _res|
    abort "Fix code style errors" unless ok
  end
end