123456789_123456789_123456789_123456789_123456789_

Class: RuboCop::CLI::Command::ExecuteRunner Private

Do not use. This class is for internal use only.
Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Base
Instance Chain:
Inherits: RuboCop::CLI::Command::Base
Defined in: lib/rubocop/cli/command/execute_runner.rb

Overview

Run all the selected cops and report the result.

Constant Summary

Class Attribute Summary

Base - Inherited

Class Method Summary

Instance Attribute Summary

Base - Inherited

Instance Method Summary

::RuboCop::Formatter::TextUtil - Included

Instance Method Details

#bug_tracker_uri (private)

[ GitHub ]

  
# File 'lib/rubocop/cli/command/execute_runner.rb', line 85

def bug_tracker_uri
  return unless Gem.loaded_specs.key?('rubocop')

  "#{Gem.loaded_specs['rubocop'].['bug_tracker_uri']}\n"
end

#display_error_summary(errors) (private)

[ GitHub ]

  
# File 'lib/rubocop/cli/command/execute_runner.rb', line 69

def display_error_summary(errors)
  return if errors.empty?

  warn Rainbow("\n#{pluralize(errors.size, 'error')} occurred:").red

  errors.each { |error| warn error }

  warn <<~WARNING
    Errors are usually caused by RuboCop bugs.
    Please, report your problems to RuboCop's issue tracker.
    #{bug_tracker_uri}
    Mention the following information in the issue report:
    #{RuboCop::Version.verbose}
  WARNING
end

#display_summary(runner) (private)

[ GitHub ]

  
# File 'lib/rubocop/cli/command/execute_runner.rb', line 56

def display_summary(runner)
  display_warning_summary(runner.warnings)
  display_error_summary(runner.errors)
end

#display_warning_summary(warnings) (private)

[ GitHub ]

  
# File 'lib/rubocop/cli/command/execute_runner.rb', line 61

def display_warning_summary(warnings)
  return if warnings.empty?

  warn Rainbow("\n#{pluralize(warnings.size, 'warning')}:").yellow

  warnings.each { |warning| warn warning }
end

#execute_runner(paths) (private)

[ GitHub ]

  
# File 'lib/rubocop/cli/command/execute_runner.rb', line 22

def execute_runner(paths)
  runner = Runner.new(@options, @config_store)

  all_pass_or_excluded = with_redirect do
    all_passed = runner.run(paths)
    display_summary(runner)
    all_passed || @options[:auto_gen_config]
  end

  maybe_print_corrected_source

  if runner.aborting?
    STATUS_INTERRUPTED
  elsif all_pass_or_excluded && runner.errors.empty?
    STATUS_SUCCESS
  else
    STATUS_OFFENSES
  end
end

#maybe_print_corrected_source (private)

[ GitHub ]

  
# File 'lib/rubocop/cli/command/execute_runner.rb', line 91

def maybe_print_corrected_source
  # Integration tools (like RubyMine) expect to have only the JSON result
  # when specifying JSON format. Similar HTML and JUnit are targeted as well.
  # See: https://github.com/rubocop/rubocop/issues/8673
  return if INTEGRATION_FORMATTERS.include?(@options[:format])

  return unless @options[:stdin] && @options[:autocorrect]

  (@options[:stderr] ? $stderr : $stdout).puts '=' * 20
  print @options[:stdin]
end

#run

[ GitHub ]

  
# File 'lib/rubocop/cli/command/execute_runner.rb', line 16

def run
  execute_runner(@paths)
end

#with_redirect (private)

[ GitHub ]

  
# File 'lib/rubocop/cli/command/execute_runner.rb', line 42

def with_redirect
  if @options[:stderr]
    orig_stdout = $stdout
    begin
      $stdout = $stderr
      yield
    ensure
      $stdout = orig_stdout
    end
  else
    yield
  end
end