rubocop-on-rbs 2.0.0.dev → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +53 -0
  3. data/README.md +1 -4
  4. data/config/default.yml +6 -4
  5. data/lib/rubocop/cop/rbs/layout/annotation_indentation.rb +90 -0
  6. data/lib/rubocop/cop/rbs/layout/comment_indentation.rb +34 -32
  7. data/lib/rubocop/cop/rbs/layout/empty_lines_around_access_modifier.rb +4 -3
  8. data/lib/rubocop/cop/rbs/layout/empty_lines_around_body.rb +8 -0
  9. data/lib/rubocop/cop/rbs/layout/empty_lines_around_overloads.rb +22 -6
  10. data/lib/rubocop/cop/rbs/layout/end_alignment.rb +2 -1
  11. data/lib/rubocop/cop/rbs/layout/extra_spacing.rb +1 -0
  12. data/lib/rubocop/cop/rbs/layout/indentation_width.rb +17 -2
  13. data/lib/rubocop/cop/rbs/layout/overload_indentation.rb +16 -6
  14. data/lib/rubocop/cop/rbs/layout/space_after_comma.rb +1 -0
  15. data/lib/rubocop/cop/rbs/layout/space_around_arrow.rb +4 -2
  16. data/lib/rubocop/cop/rbs/layout/space_around_braces.rb +6 -3
  17. data/lib/rubocop/cop/rbs/layout/space_around_operators.rb +19 -1
  18. data/lib/rubocop/cop/rbs/layout/space_before_colon.rb +1 -1
  19. data/lib/rubocop/cop/rbs/layout/space_before_overload.rb +27 -13
  20. data/lib/rubocop/cop/rbs/lint/ambiguous_keyword_argument_key.rb +3 -2
  21. data/lib/rubocop/cop/rbs/lint/ambiguous_operator_precedence.rb +2 -0
  22. data/lib/rubocop/cop/rbs/lint/duplicate_annotation.rb +2 -0
  23. data/lib/rubocop/cop/rbs/lint/duplicate_overload.rb +3 -2
  24. data/lib/rubocop/cop/rbs/lint/new_returns_void.rb +0 -2
  25. data/lib/rubocop/cop/rbs/lint/top_level_interface.rb +6 -4
  26. data/lib/rubocop/cop/rbs/lint/top_level_type_alias.rb +6 -4
  27. data/lib/rubocop/cop/rbs/lint/useless_access_modifier.rb +3 -3
  28. data/lib/rubocop/cop/rbs/style/block_return_boolish.rb +1 -0
  29. data/lib/rubocop/cop/rbs/style/class_with_singleton.rb +1 -1
  30. data/lib/rubocop/cop/rbs/style/classic_type.rb +6 -5
  31. data/lib/rubocop/cop/rbs/style/initialize_return_type.rb +1 -0
  32. data/lib/rubocop/cop/rbs/style/instance_with_instance.rb +1 -1
  33. data/lib/rubocop/cop/rbs/style/optional_nil.rb +1 -1
  34. data/lib/rubocop/cop/rbs/style/redundant_parentheses.rb +19 -5
  35. data/lib/rubocop/cop/rbs/style/true_false.rb +1 -1
  36. data/lib/rubocop/cop/rbs_cops.rb +1 -1
  37. data/lib/rubocop/rbs/cop_base.rb +29 -1
  38. data/lib/rubocop/rbs/on_type_helper.rb +2 -0
  39. data/lib/rubocop/rbs/processed_rbs_source.rb +10 -5
  40. data/lib/rubocop/rbs/version.rb +1 -1
  41. metadata +8 -8
  42. data/lib/rubocop/cop/rbs/lint/will_syntax_error.rb +0 -228
@@ -1,228 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- module RBS
6
- module Lint
7
- # This cop checks the WillSyntaxError in RBS.
8
- # RBS with this diagnostics will fail in `rbs validate` command.
9
- #
10
- # @example
11
- # # bad
12
- # def foo: (void) -> void
13
- #
14
- # # bad
15
- # CONST: self
16
- #
17
- class WillSyntaxError < RuboCop::RBS::CopBase
18
- # @rbs!
19
- # module Types = ::RBS::Types
20
- # module AST = ::RBS::AST
21
-
22
- # @rbs skip
23
- AST = ::RBS::AST
24
- # @rbs skip
25
- Types = ::RBS::Types
26
-
27
- def on_rbs_class(decl)
28
- if super_class = decl.super_class
29
- super_class.args.each do |arg|
30
- void_type_context_validator(arg, true)
31
- no_self_type_validator(arg)
32
- no_classish_type_validator(arg)
33
- end
34
- end
35
- check_module_or_class(decl)
36
- end
37
-
38
- def on_rbs_module(decl)
39
- decl.self_types.each do |self_type|
40
- self_type.args.each do |arg|
41
- void_type_context_validator(arg, true)
42
- no_self_type_validator(arg)
43
- no_classish_type_validator(arg)
44
- end
45
- end
46
- check_module_or_class(decl)
47
- end
48
-
49
- def check_type_params(decl)
50
- decl.type_params.each do |param|
51
- if ub = param.upper_bound
52
- void_type_context_validator(ub)
53
- no_self_type_validator(ub)
54
- no_classish_type_validator(ub)
55
- end
56
-
57
- if param.respond_to?(:default_type)
58
- if dt = param.default_type
59
- void_type_context_validator(dt, true)
60
- no_self_type_validator(dt)
61
- no_classish_type_validator(dt)
62
- end
63
- end
64
- end
65
- end
66
-
67
- def check_module_or_class(decl)
68
- check_type_params(decl)
69
-
70
- decl.each_member do |member|
71
- case member
72
- when AST::Members::MethodDefinition
73
- member.overloads.each do |ov|
74
- void_type_context_validator(ov.method_type)
75
- end
76
- when AST::Members::Attribute
77
- void_type_context_validator(member.type)
78
- when AST::Members::Mixin
79
- member.args.each do |arg|
80
- no_self_type_validator(arg)
81
- unless arg.is_a?(Types::Bases::Void)
82
- void_type_context_validator(arg, true)
83
- end
84
- end
85
- when AST::Members::Var
86
- void_type_context_validator(member.type)
87
- if member.is_a?(AST::Members::ClassVariable)
88
- no_self_type_validator(member.type)
89
- end
90
- end
91
- end
92
- end
93
-
94
- def on_rbs_interface(decl)
95
- check_type_params(decl)
96
-
97
- decl.members.each do |member|
98
- case member
99
- when AST::Members::MethodDefinition
100
- member.overloads.each do |ov|
101
- void_type_context_validator(ov.method_type)
102
- no_classish_type_validator(ov.method_type)
103
- end
104
- end
105
- end
106
- end
107
-
108
- def on_rbs_constant(decl)
109
- no_self_type_validator(decl.type)
110
- no_classish_type_validator(decl.type)
111
- void_type_context_validator(decl.type)
112
- end
113
- alias on_rbs_global on_rbs_constant
114
-
115
- def on_rbs_type_alias(decl)
116
- no_self_type_validator(decl.type)
117
- no_classish_type_validator(decl.type)
118
- void_type_context_validator(decl.type)
119
-
120
- check_type_params(decl)
121
- end
122
-
123
- private
124
-
125
- # @rbs type: ::RBS::Types::t
126
- def no_self_type_validator(type)
127
- case type
128
- when ::RBS::MethodType,
129
- Types::Record,
130
- Types::Tuple,
131
- Types::Union,
132
- Types::Intersection,
133
- Types::Optional,
134
- Types::ClassInstance,
135
- Types::Proc
136
- type.each_type do |t|
137
- no_self_type_validator(t)
138
- end
139
- else
140
- if type.has_self_type?
141
- offence(type, "`self` type is not allowed in this context")
142
- end
143
- end
144
- end
145
-
146
- # @rbs type: ::RBS::MethodType | ::RBS::Types::t
147
- def no_classish_type_validator(type)
148
- case type
149
- when ::RBS::MethodType,
150
- Types::Record,
151
- Types::Tuple,
152
- Types::Union,
153
- Types::Intersection,
154
- Types::Optional,
155
- Types::ClassInstance,
156
- Types::Proc
157
- type.each_type do |t|
158
- no_classish_type_validator(t)
159
- end
160
- when Types::Bases::Instance
161
- offence(type, "`instance` type is not allowed in this context")
162
- when Types::Bases::Class
163
- offence(type, "`class` type is not allowed in this context")
164
- else
165
- if type.has_classish_type?
166
- offence(type, "`instance` or `class` type is not allowed in this context")
167
- end
168
- end
169
- end
170
-
171
- # @rbs type: ::RBS::MethodType | ::RBS::Types::Function | ::RBS::Types::t
172
- # @rbs allowed_here: bool
173
- def void_type_context_validator(type, allowed_here = false)
174
- return if type.is_a?(Types::UntypedFunction)
175
-
176
- case type
177
- when ::RBS::MethodType
178
- void_type_context_validator(type.type)
179
- when Types::Function
180
- type.each_param do |param|
181
- void_type_context_validator(param.type)
182
- end
183
- case type.return_type
184
- when Types::Bases::Void
185
- # `() -> void` is allowed
186
- else
187
- void_type_context_validator(type.return_type, true)
188
- end
189
- when Types::Proc
190
- void_type_context_validator(type.type)
191
- void_type_context_validator(type.self_type) if type.self_type
192
- if type.block
193
- void_type_context_validator(type.block.type)
194
- void_type_context_validator(type.block.self_type) if type.block.self_type
195
- end
196
- when Types::ClassInstance
197
- type.args.each do |arg|
198
- next if arg.is_a?(Types::Bases::Void)
199
-
200
- void_type_context_validator(arg)
201
- end
202
- when Types::Record,
203
- Types::Tuple,
204
- Types::Union,
205
- Types::Intersection,
206
- Types::Optional
207
- type.each_type do |t|
208
- void_type_context_validator(t)
209
- end
210
- else
211
- if allowed_here
212
- return if type.is_a?(Types::Bases::Void)
213
- end
214
- if type.with_nonreturn_void?
215
- offence(type, "`void` type is only allowed in return type or generics parameter")
216
- end
217
- end
218
- end
219
-
220
- def offence(decl, message)
221
- range = location_to_range(decl.location)
222
- add_offense(range, message: message)
223
- end
224
- end
225
- end
226
- end
227
- end
228
- end