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.



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
78
79
80
81
# File 'lib/rbs/cli/validate.rb', line 51

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, resolver: Resolver::TypeNameResolver.new(@env))
  exit_error = false
  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|
      exit_error = bool
    }
    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, exit_error: exit_error)
end

Instance Method Details

#runObject



83
84
85
86
87
88
89
90
91
92
# File 'lib/rbs/cli/validate.rb', line 83

def run
  validate_class_module_definition
  validate_class_module_alias_definition
  validate_interface
  validate_constant
  validate_global
  validate_type_alias

  @errors.finish
end