class Rubydex::CLI::Command::Lint::Explain
‘rdx lint explain <RULE>` — prints documentation for rules with a matching name.
Constants
- BASE_PATHS
Public Class Methods
→ String
Source
# File lib/rubydex/cli/command/lint/explain.rb, line 19 def usage_form "lint explain <RULE>" end
Public Instance Methods
→ void
Source
# File lib/rubydex/cli/command/lint/explain.rb, line 25 def run parse_options! rule_name = argv.shift abort_with_usage("`lint explain` requires a rule name argument") unless rule_name abort_with_usage("unexpected argument: #{argv.first}") unless argv.empty? workspace_path = current_workspace_path graph = Rubydex::Graph.configure_for_workspace(workspace_path) graph.index_all([*BASE_PATHS, *Rubydex::Linter::RuleLoader.paths(workspace_path)]) graph.resolve base_rule = graph["Rubydex::Rule"] abort("Base rule class is not found. This is an issue in Rubydex itself") unless base_rule.is_a?(Rubydex::Class) rule_declarations = base_rule.descendants.grep(Rubydex::Class) #: as Array[Rubydex::Class] matched_rule_names = rule_declarations.filter_map do |declaration| declaration_name = declaration.name next unless declaration_name next if declaration_name == "Rubydex::Rule" || declaration_name == "Rubydex::Linter::CustomRule" next unless declaration_name.end_with?(rule_name) declaration end abort("Rule does not exist: #{rule_name}") if matched_rule_names.empty? puts(matched_rule_names.sort_by(&:name).map { |rule| documentation_for(rule) }.join("\n")) end