Class: Synthra::CLI::Commands::Lint

Inherits:
Base
  • Object
show all
Defined in:
lib/synthra/cli/commands/lint.rb

Overview

Lint command - checks schemas for semantic errors

Examples:

synthra lint schemas/ --strict

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from Synthra::CLI::Commands::Base

Instance Method Details

#callObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/synthra/cli/commands/lint.rb', line 12

def call
  path = args.shift

  unless path
    error "Usage: synthra lint <path|directory>"
    return EXIT_PARSE_ERROR
  end

  registry = Registry.new
  load_path(registry, path, validate: false)

  errors = registry.validate_paths

  if errors.empty?
    success "No lint errors found in #{registry.size} schema(s)"
    if options[:verbose]
      puts "\nSchemas checked:"
      registry.names.sort.each { |name| puts "  - #{name}" }
    end
    EXIT_SUCCESS
  else
    error "Found #{errors.length} lint error(s):\n"

    errors.each_with_index do |err, i|
      puts "#{i + 1}. #{err.message}"
      if err.respond_to?(:suggestions) && err.suggestions&.any?
        puts "   Did you mean: #{err.suggestions.first(3).join(", ")}?"
      end
      puts
    end

    if options[:strict]
      $stderr.puts "Strict mode: #{errors.length} error(s) treated as failures"
    end

    EXIT_PARSE_ERROR
  end
end