123456789_123456789_123456789_123456789_123456789_

Class: RuboCop::CLI::Command::ShowCops Private

Relationships & Source Files
Namespace Children
Classes:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Base
Instance Chain:
self, CopNames, Base
Inherits: RuboCop::CLI::Command::Base
Defined in: lib/rubocop/cli/command/show_cops.rb

Overview

Shows the given cops, or all cops by default, and their configurations for the current directory.

Class Attribute Summary

Base - Inherited

Class Method Summary

Base - Inherited

Instance Attribute Summary

Base - Inherited

Instance Method Summary

CopNames - Included

#cop_class_for

Not memoized: the MCP server lives long enough for a plugin to register a cop after a lookup has missed it.

#department?, #department_message,
#known_cop_classes

The cops among names that exist, so a command can report on what it understood before #validate_cop_names! objects to the rest.

#unknown_cop_message, #validate_cop_names!

Constructor Details

.new(env) ⇒ ShowCops

[ GitHub ]

  
# File 'lib/rubocop/cli/command/show_cops.rb', line 26

def initialize(env)
  super

  # Load the configs so the require()s are done for custom cops
  @config = @config_store.for(PathUtil.pwd)

  @cop_matchers = @options[:show_cops].map do |pattern|
    if pattern.include?('*')
      WildcardMatcher.new(pattern)
    else
      ExactMatcher.new(pattern)
    end
  end
end

Instance Method Details

#config_lines(cop) (private)

[ GitHub ]

  
# File 'lib/rubocop/cli/command/show_cops.rb', line 95

def config_lines(cop)
  cnf = @config.for_cop(cop)
  cnf.to_yaml.lines.to_a.drop(1).map { |line| "  #{line}" }
end

#cops_of_department(cops, department) (private)

[ GitHub ]

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

def cops_of_department(cops, department)
  cops.with_department(department).sort!
end

#run

[ GitHub ]

  
# File 'lib/rubocop/cli/command/show_cops.rb', line 41

def run
  print_available_cops
  # Checked after printing, so a typo alongside good names still shows
  # what was asked for. Wildcards are patterns, not names, so a pattern
  # that matches nothing is not an error.
  validate_cop_names!(@options[:show_cops].grep_v(/\*/))
end

#selected_cops_of_department(cops, department) (private)

[ GitHub ]

  
# File 'lib/rubocop/cli/command/show_cops.rb', line 83

def selected_cops_of_department(cops, department)
  cops_of_department(cops, department).select do |cop|
    @cop_matchers.any? do |matcher|
      matcher.match?(cop.cop_name)
    end
  end
end