Class: Ace::Lint::CLI::Commands::Lint

Inherits:
Support::Cli::Command
  • Object
show all
Includes:
Support::Cli::Base
Defined in:
lib/ace/lint/cli/commands/lint.rb

Overview

ace-support-cli Command class for the lint command

This command provides linting functionality for markdown, YAML, and frontmatter files, with built-in doctor diagnostics via –doctor flag.

Constant Summary collapse

AGENT_FIX_FILE_BLOCK_START =
"<<ACE_FILE:".freeze
AGENT_FIX_FILE_BLOCK_END =
"<<ACE_END_FILE>>".freeze
AGENT_FIX_NO_CHANGES =
"<<ACE_NO_CHANGES>>".freeze
AGENT_FIX_MAX_FILE_BYTES =
200_000
AGENT_FIX_MAX_TOTAL_BYTES =
1_000_000

Instance Method Summary collapse

Instance Method Details

#call(**options) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/ace/lint/cli/commands/lint.rb', line 90

def call(**options)
  if options[:version]
    puts "ace-lint #{Ace::Lint::VERSION}"
    return
  end

  if options[:doctor] || options[:doctor_verbose]
    run_doctor(verbose: !!options[:doctor_verbose], quiet: !!options[:quiet])
    return
  end

  # Reset availability caches to ensure fresh tool detection per invocation
  # This handles cases where tools are installed/removed during long-lived sessions
  Ace::Lint::Atoms::ValidatorRegistry.reset_all_caches!

  # Extract files array from options (ace-support-cli passes it as :files key)
  files = options[:files] || []

  # Remove ace-support-cli specific keys (args is leftover arguments)
  clean_options = options.reject { |k, _| k == :files || k == :args }

  # Type-convert numeric options (ace-support-cli returns strings for integers in some cases)
  # This maintains parity with the Thor implementation
  clean_options[:line_width] = clean_options[:line_width].to_i if clean_options[:line_width]

  # Validate inputs
  if files.empty?
    raise Ace::Support::Cli::Error.new("No files specified\nUsage: ace-lint [FILES...] [OPTIONS]")
  end

  # Expand globs
  expanded_paths = expand_file_paths(files)

  if expanded_paths.empty?
    raise Ace::Support::Cli::Error.new("No files found matching the given patterns")
  end

  # Create orchestrator with ruby groups configuration
  ruby_groups = Ace::Lint.ruby_config&.dig("groups")
  orchestrator = Organisms::LintOrchestrator.new(ruby_groups: ruby_groups)

  # Prepare options
  lint_options = prepare_options(clean_options)

  # Lint files
  if auto_fix_mode?(clean_options)
    warn_format_ignored_if_needed(clean_options)
    auto_fix_orchestrator = build_auto_fix_orchestrator(
      orchestrator,
      lint_options: lint_options,
      options: clean_options
    )
    if clean_options[:dry_run]
      auto_fix_orchestrator.run_dry_run(expanded_paths)
      return
    end

    results = auto_fix_orchestrator.run(expanded_paths)
  else
    results = orchestrator.lint_files(expanded_paths, options: lint_options)
  end

  # Generate report unless --no-report flag is set
  report_dir = nil
  report_files = nil
  unless clean_options[:no_report]
    project_root = find_project_root
    report_result = Organisms::ReportGenerator.generate(
      results,
      project_root: project_root,
      options: lint_options
    )
    if report_result[:success]
      report_dir = report_result[:dir]
      report_files = report_result[:files]
    end
  end

  # Report results
  verbose = !clean_options[:quiet]
  Organisms::ResultReporter.report(results, verbose: verbose, report_dir: report_dir, report_files: report_files)

  # Raise on remaining issues
  if auto_fix_mode?(clean_options)
    remaining_errors = results.sum(&:error_count)
    if remaining_errors.positive?
      raise Ace::Support::Cli::Error.new(
        "#{remaining_errors} error violation(s) remain after auto-fix",
        exit_code: 1
      )
    end
  elsif results.any?(&:failed?)
    failed_count = results.count(&:failed?)
    exit_code = Organisms::ResultReporter.exit_code(results)
    raise Ace::Support::Cli::Error.new("#{failed_count} file(s) had lint errors", exit_code: exit_code)
  end
end