rubocop-rbs_inline 1.5.2 → 1.5.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 493b7e1647144c43522e4942ef4bcfbf5c79212f9fbe8640faf31e4431f9c8bd
4
- data.tar.gz: be48b787c6ca85eab710bd9dbb32cba5a8d0854668d87ea0f86142b330585f27
3
+ metadata.gz: c65d1d4e37ea73dd5b79770f8fc0918073146d2ffd98e0fd586d8aec79aae444
4
+ data.tar.gz: 5159368f17e584d01b6c7154bb26e12786abac1d76f48d1da2374390b4bf7b44
5
5
  SHA512:
6
- metadata.gz: 35ac9302a3b6d02143db3168c5439732461816077b675ad150a6957933284d6124b30065c112f9fdf75364cc6203afef3a3dba68948c9d5edba05571ec3c3a3c
7
- data.tar.gz: 6ce6535243b8f0ef9f17aff0d41ca646ebc07b3fbb6271c1a46715b6c63226e1662795cce9dc864cfbbf3c3f2b5023c8d3729581e495f68f519c0978d4283c9c
6
+ metadata.gz: 1361c8832f82fed8f3ad92943b3d3d563cd109a479b7b6095cc6e8f887712c8a2bcaa06d2a1fc67abab2e122f0a97dd0b181a34b134a16baa707498318d7ac71
7
+ data.tar.gz: 84151f32b0ad2aa4d5b948a0bd4350031cf0112f1548688689f71dc05eccc3f68a39d214494c2ee82f314300a871f80f51509d7c3c3a6564c19deaf08a4fef91
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.5.3 (2026-03-02)
4
+
5
+ ### Enhancements
6
+
7
+ - **Style/RbsInline/MissingTypeAnnotation**: Added `method_type_signature_or_return_annotation` style. Methods with arguments require a leading `#:` method type signature; methods without arguments accept either a leading `#:` signature or a trailing `#:` return type annotation.
8
+
3
9
  ## 1.5.2 (2026-02-26)
4
10
 
5
11
  ### Bug Fixes
data/README.md CHANGED
@@ -204,9 +204,10 @@ Enforces that method definitions and `attr_*` declarations have RBS inline type
204
204
 
205
205
  **Configuration:**
206
206
  - `EnforcedStyle` (default: `doc_style`)
207
- - `method_type_signature`: Requires `#:` annotation comments
208
207
  - `doc_style`: Requires `# @rbs` annotations
209
208
  - `doc_style_and_return_annotation`: Requires `# @rbs` parameters and inline `#:` return type
209
+ - `method_type_signature`: Requires `#:` annotation comments
210
+ - `method_type_signature_or_return_annotation`: Requires `#:` annotation for methods with arguments; accepts either `#:` annotation or trailing `#:` return type for methods without arguments
210
211
  - `Visibility` (default: `all`)
211
212
  - `all`: Checks all methods regardless of visibility
212
213
  - `public`: Only checks public methods and `attr_*` declarations
@@ -228,6 +229,20 @@ def greet(name)
228
229
  end
229
230
  ```
230
231
 
232
+ **Examples (EnforcedStyle: doc_style_and_return_annotation):**
233
+ ```ruby
234
+ # bad - no annotation
235
+ def greet(name)
236
+ "Hello, #{name}"
237
+ end
238
+
239
+ # good
240
+ # @rbs name: String
241
+ def greet(name) #: String
242
+ "Hello, #{name}"
243
+ end
244
+ ```
245
+
231
246
  **Examples (EnforcedStyle: method_type_signature):**
232
247
  ```ruby
233
248
  # bad - no annotation
@@ -242,18 +257,34 @@ def greet(name)
242
257
  end
243
258
  ```
244
259
 
245
- **Examples (EnforcedStyle: doc_style_and_return_annotation):**
260
+ **Examples (EnforcedStyle: method_type_signature_or_return_annotation):**
246
261
  ```ruby
247
- # bad - no annotation
262
+ # bad - method with arguments requires method_type_signature
248
263
  def greet(name)
249
264
  "Hello, #{name}"
250
265
  end
251
266
 
252
- # good
253
- # @rbs name: String
267
+ # bad - trailing return annotation is not accepted for methods with arguments
254
268
  def greet(name) #: String
255
269
  "Hello, #{name}"
256
270
  end
271
+
272
+ # good - method_type_signature for methods with arguments
273
+ #: (String) -> String
274
+ def greet(name)
275
+ "Hello, #{name}"
276
+ end
277
+
278
+ # good - method_type_signature for methods without arguments
279
+ #: -> String
280
+ def greet
281
+ "Hello"
282
+ end
283
+
284
+ # good - trailing return annotation for methods without arguments
285
+ def greet #: String
286
+ "Hello"
287
+ end
257
288
  ```
258
289
 
259
290
  ### Style/RbsInline/ParametersSeparator
data/config/default.yml CHANGED
@@ -44,9 +44,10 @@ Style/RbsInline/MissingTypeAnnotation:
44
44
  VersionAdded: "1.5.0"
45
45
  EnforcedStyle: doc_style
46
46
  SupportedStyles:
47
- - method_type_signature
48
47
  - doc_style
49
48
  - doc_style_and_return_annotation
49
+ - method_type_signature
50
+ - method_type_signature_or_return_annotation
50
51
  Visibility: all
51
52
 
52
53
  Style/RbsInline/ParametersSeparator:
@@ -11,9 +11,11 @@ module RuboCop
11
11
  #
12
12
  # The `EnforcedStyle` option determines which annotation format is required:
13
13
  #
14
- # - `method_type_signature`: Requires `#:` annotation comments only
15
14
  # - `doc_style`: Requires `# @rbs` annotations
16
15
  # - `doc_style_and_return_annotation`: Requires `# @rbs` parameters and trailing `#:` return type
16
+ # - `method_type_signature`: Requires `#:` annotation comments only
17
+ # - `method_type_signature_or_return_annotation`: Requires `#:` annotation for methods with arguments;
18
+ # accepts either `#:` annotation or trailing `#:` return type for methods without arguments
17
19
  #
18
20
  # The `Visibility` option determines which methods to check:
19
21
  #
@@ -22,7 +24,7 @@ module RuboCop
22
24
  #
23
25
  # Methods annotated with `# @rbs skip` are always excluded from inspection.
24
26
  #
25
- # @example EnforcedStyle: method_type_signature
27
+ # @example EnforcedStyle: doc_style
26
28
  # # bad
27
29
  # def greet(name)
28
30
  # "Hello, #{name}"
@@ -32,16 +34,38 @@ module RuboCop
32
34
  # attr_reader :name
33
35
  #
34
36
  # # good
35
- # #: (String) -> String
37
+ # # @rbs name: String
38
+ # # @rbs return: String
36
39
  # def greet(name)
37
40
  # "Hello, #{name}"
38
41
  # end
39
42
  #
40
43
  # # good
41
- # #: String
44
+ # # @rbs name: String
42
45
  # attr_reader :name
43
46
  #
44
- # @example EnforcedStyle: doc_style
47
+ # @example EnforcedStyle: doc_style_and_return_annotation
48
+ # # bad - no annotation
49
+ # def greet(name)
50
+ # "Hello, #{name}"
51
+ # end
52
+ #
53
+ # # bad - missing trailing return type
54
+ # # @rbs name: String
55
+ # def greet(name)
56
+ # "Hello, #{name}"
57
+ # end
58
+ #
59
+ # # good - @rbs parameters + trailing return type
60
+ # # @rbs name: String
61
+ # def greet(name) #: String
62
+ # "Hello, #{name}"
63
+ # end
64
+ #
65
+ # # good - attr with trailing type
66
+ # attr_reader :name #: String
67
+ #
68
+ # @example EnforcedStyle: method_type_signature
45
69
  # # bad
46
70
  # def greet(name)
47
71
  # "Hello, #{name}"
@@ -51,34 +75,43 @@ module RuboCop
51
75
  # attr_reader :name
52
76
  #
53
77
  # # good
54
- # # @rbs name: String
55
- # # @rbs return: String
78
+ # #: (String) -> String
56
79
  # def greet(name)
57
80
  # "Hello, #{name}"
58
81
  # end
59
82
  #
60
83
  # # good
61
- # # @rbs name: String
84
+ # #: String
62
85
  # attr_reader :name
63
86
  #
64
- # @example EnforcedStyle: doc_style_and_return_annotation
65
- # # bad - no annotation
87
+ # @example EnforcedStyle: method_type_signature_or_return_annotation
88
+ # # bad - method with arguments requires method_type_signature
66
89
  # def greet(name)
67
90
  # "Hello, #{name}"
68
91
  # end
69
92
  #
70
- # # bad - missing trailing return type
71
- # # @rbs name: String
72
- # def greet(name)
93
+ # # bad - inline trailing comment is not accepted for methods with arguments
94
+ # def greet(name) #: String
73
95
  # "Hello, #{name}"
74
96
  # end
75
97
  #
76
- # # good - @rbs parameters + trailing return type
77
- # # @rbs name: String
78
- # def greet(name) #: String
98
+ # # good - method_type_signature for methods with arguments
99
+ # #: (String) -> String
100
+ # def greet(name)
79
101
  # "Hello, #{name}"
80
102
  # end
81
103
  #
104
+ # # good - method_type_signature for methods without arguments
105
+ # #: -> String
106
+ # def greet
107
+ # "Hello"
108
+ # end
109
+ #
110
+ # # good - trailing return type annotation for methods without arguments
111
+ # def greet #: String
112
+ # "Hello"
113
+ # end
114
+ #
82
115
  # # good - attr with trailing type
83
116
  # attr_reader :name #: String
84
117
  #
@@ -88,6 +121,8 @@ module RuboCop
88
121
  include RangeHelp
89
122
 
90
123
  METHOD_TYPE_SIGNATURE_MESSAGE = 'Missing annotation comment (e.g., `#: (Type) -> ReturnType`).'
124
+ METHOD_TYPE_SIGNATURE_OR_RETURN_ANNOTATION_MESSAGE =
125
+ 'Missing type annotation (e.g., `#: -> ReturnType` or trailing `#: ReturnType`).'
91
126
  DOC_STYLE_PARAM_MESSAGE = 'Missing `@rbs %<name>s:` annotation.'
92
127
  DOC_STYLE_RETURN_MESSAGE = 'Missing `@rbs return:` annotation.'
93
128
  DOC_STYLE_TRAILING_RETURN_MESSAGE = 'Missing trailing return type annotation (e.g., `#: void`).'
@@ -227,14 +262,16 @@ module RuboCop
227
262
  return if overload_type_signatures?(line)
228
263
 
229
264
  case style
230
- when :method_type_signature
231
- check_method_type_signature(node)
232
265
  when :doc_style
233
266
  check_method_parameters_in_doc_style(node)
234
267
  check_return_type_in_doc_style(node)
235
268
  when :doc_style_and_return_annotation
236
269
  check_method_parameters_in_doc_style(node)
237
270
  check_return_type_in_return_annotation(node)
271
+ when :method_type_signature
272
+ check_method_type_signature(node)
273
+ when :method_type_signature_or_return_annotation
274
+ check_method_type_signature_or_return_annotation_style(node)
238
275
  end
239
276
  end
240
277
 
@@ -245,6 +282,23 @@ module RuboCop
245
282
  add_offense(offense_range_for_def(node), message: METHOD_TYPE_SIGNATURE_MESSAGE)
246
283
  end
247
284
 
285
+ # @rbs node: Parser::AST::Node
286
+ def check_method_type_signature_or_return_annotation_style(node) #: void
287
+ if method_has_arguments?(node)
288
+ check_method_type_signature(node)
289
+ else
290
+ check_method_type_signature_or_return_annotation(node)
291
+ end
292
+ end
293
+
294
+ # @rbs node: Parser::AST::Node
295
+ def check_method_type_signature_or_return_annotation(node) #: void
296
+ return if find_method_type_signature_comments(node.location.line)
297
+ return if find_trailing_comment(method_parameter_list_end_line(node))
298
+
299
+ add_offense(offense_range_for_def(node), message: METHOD_TYPE_SIGNATURE_OR_RETURN_ANNOTATION_MESSAGE)
300
+ end
301
+
248
302
  # @rbs node: Parser::AST::Node
249
303
  def check_method_parameters_in_doc_style(node) #: void # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
250
304
  line = node.location.line
@@ -298,6 +352,11 @@ module RuboCop
298
352
  end
299
353
  end
300
354
 
355
+ # @rbs node: Parser::AST::Node
356
+ def method_has_arguments?(node) #: bool
357
+ args_node_for(node).children.any?
358
+ end
359
+
301
360
  # @rbs line: Integer
302
361
  def annotated_attribute_method?(line) #: boolish
303
362
  # attr_* always requires inline comment regardless of style
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module RbsInline
5
- VERSION = '1.5.2'
5
+ VERSION = '1.5.3'
6
6
  end
7
7
  end
@@ -9,9 +9,11 @@ module RuboCop
9
9
  #
10
10
  # The `EnforcedStyle` option determines which annotation format is required:
11
11
  #
12
- # - `method_type_signature`: Requires `#:` annotation comments only
13
12
  # - `doc_style`: Requires `# @rbs` annotations
14
13
  # - `doc_style_and_return_annotation`: Requires `# @rbs` parameters and trailing `#:` return type
14
+ # - `method_type_signature`: Requires `#:` annotation comments only
15
+ # - `method_type_signature_or_return_annotation`: Requires `#:` annotation for methods with arguments;
16
+ # accepts either `#:` annotation or trailing `#:` return type for methods without arguments
15
17
  #
16
18
  # The `Visibility` option determines which methods to check:
17
19
  #
@@ -20,7 +22,7 @@ module RuboCop
20
22
  #
21
23
  # Methods annotated with `# @rbs skip` are always excluded from inspection.
22
24
  #
23
- # @example EnforcedStyle: method_type_signature
25
+ # @example EnforcedStyle: doc_style
24
26
  # # bad
25
27
  # def greet(name)
26
28
  # "Hello, #{name}"
@@ -30,16 +32,38 @@ module RuboCop
30
32
  # attr_reader :name
31
33
  #
32
34
  # # good
33
- # #: (String) -> String
35
+ # # @rbs name: String
36
+ # # @rbs return: String
34
37
  # def greet(name)
35
38
  # "Hello, #{name}"
36
39
  # end
37
40
  #
38
41
  # # good
39
- # #: String
42
+ # # @rbs name: String
40
43
  # attr_reader :name
41
44
  #
42
- # @example EnforcedStyle: doc_style
45
+ # @example EnforcedStyle: doc_style_and_return_annotation
46
+ # # bad - no annotation
47
+ # def greet(name)
48
+ # "Hello, #{name}"
49
+ # end
50
+ #
51
+ # # bad - missing trailing return type
52
+ # # @rbs name: String
53
+ # def greet(name)
54
+ # "Hello, #{name}"
55
+ # end
56
+ #
57
+ # # good - @rbs parameters + trailing return type
58
+ # # @rbs name: String
59
+ # def greet(name) #: String
60
+ # "Hello, #{name}"
61
+ # end
62
+ #
63
+ # # good - attr with trailing type
64
+ # attr_reader :name #: String
65
+ #
66
+ # @example EnforcedStyle: method_type_signature
43
67
  # # bad
44
68
  # def greet(name)
45
69
  # "Hello, #{name}"
@@ -49,34 +73,43 @@ module RuboCop
49
73
  # attr_reader :name
50
74
  #
51
75
  # # good
52
- # # @rbs name: String
53
- # # @rbs return: String
76
+ # #: (String) -> String
54
77
  # def greet(name)
55
78
  # "Hello, #{name}"
56
79
  # end
57
80
  #
58
81
  # # good
59
- # # @rbs name: String
82
+ # #: String
60
83
  # attr_reader :name
61
84
  #
62
- # @example EnforcedStyle: doc_style_and_return_annotation
63
- # # bad - no annotation
85
+ # @example EnforcedStyle: method_type_signature_or_return_annotation
86
+ # # bad - method with arguments requires method_type_signature
64
87
  # def greet(name)
65
88
  # "Hello, #{name}"
66
89
  # end
67
90
  #
68
- # # bad - missing trailing return type
69
- # # @rbs name: String
70
- # def greet(name)
91
+ # # bad - inline trailing comment is not accepted for methods with arguments
92
+ # def greet(name) #: String
71
93
  # "Hello, #{name}"
72
94
  # end
73
95
  #
74
- # # good - @rbs parameters + trailing return type
75
- # # @rbs name: String
76
- # def greet(name) #: String
96
+ # # good - method_type_signature for methods with arguments
97
+ # #: (String) -> String
98
+ # def greet(name)
77
99
  # "Hello, #{name}"
78
100
  # end
79
101
  #
102
+ # # good - method_type_signature for methods without arguments
103
+ # #: -> String
104
+ # def greet
105
+ # "Hello"
106
+ # end
107
+ #
108
+ # # good - trailing return type annotation for methods without arguments
109
+ # def greet #: String
110
+ # "Hello"
111
+ # end
112
+ #
80
113
  # # good - attr with trailing type
81
114
  # attr_reader :name #: String
82
115
  class MissingTypeAnnotation < Base
@@ -88,6 +121,8 @@ module RuboCop
88
121
 
89
122
  METHOD_TYPE_SIGNATURE_MESSAGE: ::String
90
123
 
124
+ METHOD_TYPE_SIGNATURE_OR_RETURN_ANNOTATION_MESSAGE: ::String
125
+
91
126
  DOC_STYLE_PARAM_MESSAGE: ::String
92
127
 
93
128
  DOC_STYLE_RETURN_MESSAGE: ::String
@@ -172,6 +207,12 @@ module RuboCop
172
207
  # @rbs node: Parser::AST::Node
173
208
  def check_method_type_signature: (Parser::AST::Node node) -> void
174
209
 
210
+ # @rbs node: Parser::AST::Node
211
+ def check_method_type_signature_or_return_annotation_style: (Parser::AST::Node node) -> void
212
+
213
+ # @rbs node: Parser::AST::Node
214
+ def check_method_type_signature_or_return_annotation: (Parser::AST::Node node) -> void
215
+
175
216
  # @rbs node: Parser::AST::Node
176
217
  def check_method_parameters_in_doc_style: (Parser::AST::Node node) -> void
177
218
 
@@ -191,6 +232,9 @@ module RuboCop
191
232
  # @rbs node: Parser::AST::Node
192
233
  def args_node_for: (Parser::AST::Node node) -> Parser::AST::Node
193
234
 
235
+ # @rbs node: Parser::AST::Node
236
+ def method_has_arguments?: (Parser::AST::Node node) -> bool
237
+
194
238
  # @rbs line: Integer
195
239
  def annotated_attribute_method?: (Integer line) -> boolish
196
240
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-rbs_inline
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.2
4
+ version: 1.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takeshi KOMIYA
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-02-26 00:00:00.000000000 Z
11
+ date: 2026-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lint_roller