Sha256: 73d6bc3ac15de5a261bcb1b40c3368d63e32d706c8d2c162240dfcf2da5f3703

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

module Rubocop
  module Stylecheck
    module Cli
      class << self
        def run(options)
          if Rubocop::Stylecheck.direct
            direct_run(options)
          else
            run_via_sh(options)
          end
        end

        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

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

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

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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rubocop-stylecheck-0.1.2 lib/rubocop/stylecheck/cli.rb