Module: RuboCop::CLI::Command::CopNames Private
| Relationships & Source Files | |
| Extension / Inclusion / Inheritance Descendants | |
|
Included In:
| |
| Defined in: | lib/rubocop/cli/command/cop_names.rb |
Overview
Shared handling for commands that take a list of cop names.
Validation happens here rather than during option parsing because the
registry is not complete until the configuration has been loaded, which
is also why --only and --except are validated from the runner.
Instance Method Summary
- #cop_class_for(name) private Internal use only
- #department?(name) ⇒ Boolean private Internal use only
- #department_message(name) private Internal use only
-
#known_cop_classes(names)
private
Internal use only
The cops among
namesthat exist, so a command can report on what it understood before #validate_cop_names! objects to the rest. - #unknown_cop_message(name) private Internal use only
- #validate_cop_names!(names) private Internal use only
Instance Method Details
#cop_class_for(name) (private)
[ GitHub ]
#department?(name) ⇒ Boolean (private)
#department_message(name) (private)
[ GitHub ]#known_cop_classes(names) (private)
The cops among names that exist, so a command can report on what it
understood before #validate_cop_names! objects to the rest.
# File 'lib/rubocop/cli/command/cop_names.rb', line 17
def known_cop_classes(names) names.filter_map { |name| cop_class_for(name) } end
#unknown_cop_message(name) (private)
[ GitHub ]# File 'lib/rubocop/cli/command/cop_names.rb', line 37
def (name) return (name) if department?(name) = "Unrecognized cop: #{name}." similar = NameSimilarity.find_similar_names(name, Cop::Registry.global.names) return if similar.empty? "#{}\nDid you mean? #{similar.join(', ')}" end
#validate_cop_names!(names) (private)
# File 'lib/rubocop/cli/command/cop_names.rb', line 22
def validate_cop_names!(names) unknown = names.reject { |name| cop_class_for(name) } return if unknown.empty? raise IncorrectCopNameError, unknown.map { |name| (name) }.join("\n") end