def run
if argv.first == "explain"
argv.shift
require "rubydex/cli/command/lint/explain"
Explain.new(argv).run
return
end
parse_options! do |parser|
parser.separator("")
parser.separator("Commands:")
parser.separator(" explain <RULE> Print documentation for matching linter rules")
parser.separator("")
parser.separator("Options:")
end
abort_with_usage("unexpected argument: #{argv.first}") unless argv.empty?
workspace_path = current_workspace_path
require "rubydex/linter"
custom_rules = load_linter_rules(workspace_path)
warn_unknown_rules
graph = build_graph($stderr, workspace_path:, config:)
runner = Rubydex::Linter::Runner.new(graph, custom_rules:, config: linter_config)
$stderr.puts("Linting...")
diagnostics = runner.run
by_severity = diagnostics.group_by { |diagnostic| diagnostic.rule.severity(linter_config) }
if diagnostics.empty?
print_summary(graph.documents.count, by_severity)
return
end
print_offenses(by_severity, graph)
exit(1) if by_severity[Rubydex::Severity::Error]&.any?
end