@@ -4,20 +4,13 @@ module RBS
44 class CLI
55 class Validate
66 class Errors
7- def initialize ( limit :, exit_error : )
7+ def initialize ( limit :)
88 @limit = limit
9- @exit_error = exit_error
109 @errors = [ ]
11- @has_syntax_error = false
1210 end
1311
1412 def add ( error )
15- if error . instance_of? ( WillSyntaxError )
16- RBS . logger . warn ( build_message ( error ) )
17- @has_syntax_error = true
18- else
19- @errors << error
20- end
13+ @errors << error
2114 finish if @limit == 1
2215 end
2316
@@ -30,13 +23,7 @@ def try(&block)
3023 end
3124
3225 def finish
33- if @errors . empty?
34- if @exit_error && @has_syntax_error
35- throw @tag , 1
36- else
37- # success
38- end
39- else
26+ unless @errors . empty?
4027 @errors . each do |error |
4128 RBS . logger . error ( build_message ( error ) )
4229 end
@@ -63,7 +50,6 @@ def initialize(args:, options:)
6350 @env = Environment . from_loader ( loader ) . resolve_type_names
6451 @builder = DefinitionBuilder . new ( env : @env )
6552 @validator = Validator . new ( env : @env )
66- exit_error = false
6753 limit = nil #: Integer?
6854 OptionParser . new do |opts |
6955 opts . banner = <<EOU
@@ -80,14 +66,14 @@ def initialize(args:, options:)
8066 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." }
8167 end
8268 opts . on ( "--[no-]exit-error-on-syntax-error" , "exit(1) if syntax error is detected" ) { |bool |
83- exit_error = bool
69+ RBS . print_warning { "`--[no-]exit-error-on-syntax-error` option is deprecated because contextual syntax error is checked on parser." }
8470 }
8571 opts . on ( "--fail-fast" , "Exit immediately as soon as a validation error is found." ) do |arg |
8672 limit = 1
8773 end
8874 end . parse! ( args )
8975
90- @errors = Errors . new ( limit : limit , exit_error : exit_error )
76+ @errors = Errors . new ( limit : limit )
9177 end
9278
9379 def run
@@ -122,7 +108,6 @@ def validate_class_module_definition
122108 entry . each_decl do |decl |
123109 if super_class = decl . super_class
124110 super_class . args . each do |arg |
125- no_classish_type_validator ( arg )
126111 @validator . validate_type ( arg , context : nil )
127112 end
128113 end
@@ -131,7 +116,6 @@ def validate_class_module_definition
131116 entry . each_decl do |decl |
132117 decl . self_types . each do |self_type |
133118 self_type . args . each do |arg |
134- no_classish_type_validator ( arg )
135119 @validator . validate_type ( arg , context : nil )
136120 end
137121
@@ -159,17 +143,14 @@ def validate_class_module_definition
159143
160144 d . type_params . each do |param |
161145 if ub = param . upper_bound_type
162- no_classish_type_validator ( ub )
163146 @validator . validate_type ( ub , context : nil )
164147 end
165148
166149 if lb = param . lower_bound_type
167- no_classish_type_validator ( lb )
168150 @validator . validate_type ( lb , context : nil )
169151 end
170152
171153 if dt = param . default_type
172- no_classish_type_validator ( dt )
173154 @validator . validate_type ( dt , context : nil )
174155 end
175156 end
@@ -230,17 +211,14 @@ def validate_interface
230211
231212 decl . decl . type_params . each do |param |
232213 if ub = param . upper_bound_type
233- no_classish_type_validator ( ub )
234214 @validator . validate_type ( ub , context : nil )
235215 end
236216
237217 if lb = param . lower_bound_type
238- no_classish_type_validator ( lb )
239218 @validator . validate_type ( lb , context : nil )
240219 end
241220
242221 if dt = param . default_type
243- no_classish_type_validator ( dt )
244222 @validator . validate_type ( dt , context : nil )
245223 end
246224 end
@@ -251,9 +229,6 @@ def validate_interface
251229 case member
252230 when AST ::Members ::MethodDefinition
253231 @validator . validate_method_definition ( member , type_name : name )
254- member . overloads . each do |ov |
255- no_classish_type_validator ( ov . method_type )
256- end
257232 end
258233 end
259234 rescue BaseError => error
@@ -266,7 +241,6 @@ def validate_constant
266241 RBS . logger . info "Validating constant: `#{ name } `..."
267242 @validator . validate_type const . decl . type , context : const . context
268243 @builder . ensure_namespace! ( name . namespace , location : const . decl . location )
269- no_classish_type_validator ( const . decl . type )
270244 rescue BaseError => error
271245 @errors . add ( error )
272246 end
@@ -276,7 +250,6 @@ def validate_global
276250 @env . global_decls . each do |name , global |
277251 RBS . logger . info "Validating global: `#{ name } `..."
278252 @validator . validate_type global . decl . type , context : nil
279- no_classish_type_validator ( global . decl . type )
280253 rescue BaseError => error
281254 @errors . add ( error )
282255 end
@@ -299,45 +272,23 @@ def validate_type_alias
299272
300273 decl . decl . type_params . each do |param |
301274 if ub = param . upper_bound_type
302- no_classish_type_validator ( ub )
303275 @validator . validate_type ( ub , context : nil )
304276 end
305277
306278 if lb = param . lower_bound_type
307- no_classish_type_validator ( lb )
308279 @validator . validate_type ( lb , context : nil )
309280 end
310281
311282 if dt = param . default_type
312- no_classish_type_validator ( dt )
313283 @validator . validate_type ( dt , context : nil )
314284 end
315285 end
316286
317287 TypeParamDefaultReferenceError . check! ( decl . decl . type_params )
318-
319- no_classish_type_validator ( decl . decl . type )
320288 rescue BaseError => error
321289 @errors . add ( error )
322290 end
323291 end
324-
325- private
326-
327- def no_classish_type_validator ( type )
328- if type . has_classish_type?
329- @errors . add WillSyntaxError . new ( "`instance` or `class` type is not allowed in this context" , location : type . location )
330- end
331- end
332-
333- def void_type_context_validator ( type , allowed_here = false )
334- if allowed_here
335- return if type . is_a? ( Types ::Bases ::Void )
336- end
337- if type . with_nonreturn_void? # steep:ignore DeprecatedReference
338- @errors . add WillSyntaxError . new ( "`void` type is only allowed in return type or generics parameter" , location : type . location )
339- end
340- end
341292 end
342293 end
343294end
0 commit comments