Class: RuboCop::CLI::Command::Explain Private

Inherits:
Base
  • Object
show all
Includes:
CopNames
Defined in:
lib/rubocop/cli/command/explain.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Explains what cops do, as described by RuboCop::Cop::CopExplanation.

Instance Attribute Summary

Attributes inherited from Base

#env

Instance Method Summary collapse

Methods inherited from Base

by_command_name, inherited

Constructor Details

#initialize(env) ⇒ Explain

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Explain.



13
14
15
16
17
# File 'lib/rubocop/cli/command/explain.rb', line 13

def initialize(env)
  super

  @config = @config_store.for(PathUtil.pwd)
end

Instance Method Details

#run ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rubocop/cli/command/explain.rb', line 19

def run
  names = @options[:explain]

  known_cop_classes(names).each_with_index do |cop_class, index|
    puts if index.positive?
    puts Cop::CopExplanation.new(cop_class, @config)
  end

  # Checked after printing, so a typo in a list does not cost you the
  # explanations you asked for alongside it.
  validate_cop_names!(names)
end