Class: RBS::CLI::Validate

Inherits:
Object
  • Object
show all
Defined in:
lib/rbs/cli/validate.rb

Defined Under Namespace

Classes: Errors

Instance Method Summary collapse

Constructor Details

#initialize(args:, options:) ⇒ Validate

Returns a new instance of Validate.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/rbs/cli/validate.rb', line 48

def initialize(args:, options:)
  loader = options.loader()
  @env = Environment.from_loader(loader).resolve_type_names
  @builder = DefinitionBuilder.new(env: @env)
  @validator = Validator.new(env: @env)
  limit = nil #: Integer?
  OptionParser.new do |opts|
    opts.banner = <<EOU
Usage: rbs validate

Validate RBS files. It ensures the type names in RBS files are present and the type applications have correct arity.

Examples:

  $ rbs validate
EOU

    opts.on("--silent", "This option has been deprecated and does nothing.") do
      RBS.print_warning { "`--silent` option is deprecated because it's silent by default. You can use --log-level option of rbs command to display more information." }
    end
    opts.on("--[no-]exit-error-on-syntax-error", "exit(1) if syntax error is detected") {|bool|
      RBS.print_warning { "`--exit-error-on-syntax-error` option is deprecated because it's validated during parsing.." }
    }
    opts.on("--fail-fast", "Exit immediately as soon as a validation error is found.") do |arg|
      limit = 1
    end
  end.parse!(args)

  @errors = Errors.new(limit: limit)
end

Instance Method Details

#runObject



79
80
81
82
83
84
85
86
87
88
# File 'lib/rbs/cli/validate.rb', line 79

def run
  @errors.try do
    validate_class_module_definition
    validate_class_module_alias_definition
    validate_interface
    validate_constant
    validate_global
    validate_type_alias
  end
end