Class: Ace::Lint::Molecules::ValidatorChain

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/lint/molecules/validator_chain.rb

Overview

Executes multiple validators sequentially and aggregates results Handles validator availability, fallbacks, and result deduplication

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(validators, fallback_validators: [], project_root: nil) ⇒ ValidatorChain

Initialize with validators to run

Parameters:

  • validators (Array<Symbol>)

    Primary validators to run

  • fallback_validators (Array<Symbol>) (defaults to: [])

    Fallback validators if primary unavailable

  • project_root (String, nil) (defaults to: nil)

    Project root for config lookup



19
20
21
22
23
24
# File 'lib/ace/lint/molecules/validator_chain.rb', line 19

def initialize(validators, fallback_validators: [], project_root: nil)
  @validators = Array(validators)
  @fallback_validators = Array(fallback_validators)
  @project_root = project_root || Dir.pwd
  @warnings = []
end

Instance Attribute Details

#fallback_validatorsObject (readonly)

Returns the value of attribute fallback_validators.



13
14
15
# File 'lib/ace/lint/molecules/validator_chain.rb', line 13

def fallback_validators
  @fallback_validators
end

#validatorsObject (readonly)

Returns the value of attribute validators.



13
14
15
# File 'lib/ace/lint/molecules/validator_chain.rb', line 13

def validators
  @validators
end

#warningsObject (readonly)

Returns the value of attribute warnings.



13
14
15
# File 'lib/ace/lint/molecules/validator_chain.rb', line 13

def warnings
  @warnings
end

Instance Method Details

#run(file_paths, fix: false) ⇒ Hash

Run validators on file(s)

Parameters:

  • file_paths (Array<String>)

    Paths to lint

  • fix (Boolean) (defaults to: false)

    Apply autofix

Returns:

  • (Hash)

    Aggregated result with :success, :errors, :warnings, :runners



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/ace/lint/molecules/validator_chain.rb', line 30

def run(file_paths, fix: false)
  paths = Array(file_paths)
  return empty_result if paths.empty?

  # Determine which validators to actually run
  active_validators = resolve_validators

  if active_validators.empty?
    return unavailable_result
  end

  # Run each validator and collect results
  all_results = []
  runners_used = []

  active_validators.each do |validator_name|
    runner = Atoms::ValidatorRegistry.runner_for(validator_name)
    next unless runner

    # Look up config for this validator using ConfigLocator
    config = Atoms::ConfigLocator.locate(validator_name, project_root: @project_root)
    config_path = config[:exists] ? config[:path] : nil

    result = runner.run(paths, fix: fix, config_path: config_path)
    all_results << result
    runners_used << validator_name
  end

  # Aggregate and deduplicate results
  aggregate_results(all_results, runners_used)
end