rubocop-rbs_inline 1.6.1 → 1.7.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 (27) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/README.md +70 -0
  4. data/config/default.yml +15 -0
  5. data/lib/rubocop/cop/rbs_inline_cops.rb +6 -0
  6. data/lib/rubocop/cop/style/rbs_inline/class_comment_alignment.rb +66 -0
  7. data/lib/rubocop/cop/style/rbs_inline/data_class_comment_alignment.rb +5 -86
  8. data/lib/rubocop/cop/style/rbs_inline/data_define_with_block.rb +3 -4
  9. data/lib/rubocop/cop/style/rbs_inline/data_struct_helper.rb +97 -0
  10. data/lib/rubocop/cop/style/rbs_inline/missing_class_annotation.rb +85 -0
  11. data/lib/rubocop/cop/style/rbs_inline/missing_data_class_annotation.rb +5 -135
  12. data/lib/rubocop/cop/style/rbs_inline/missing_struct_class_annotation.rb +56 -0
  13. data/lib/rubocop/cop/style/rbs_inline/missing_type_annotation.rb +1 -1
  14. data/lib/rubocop/cop/style/rbs_inline/struct_class_comment_alignment.rb +58 -0
  15. data/lib/rubocop/cop/style/rbs_inline/struct_new_with_block.rb +54 -0
  16. data/lib/rubocop/rbs_inline/version.rb +1 -1
  17. data/rbs_collection.lock.yaml +5 -1
  18. data/sig/rubocop/cop/style/rbs_inline/class_comment_alignment.rbs +34 -0
  19. data/sig/rubocop/cop/style/rbs_inline/data_class_comment_alignment.rbs +2 -30
  20. data/sig/rubocop/cop/style/rbs_inline/data_define_with_block.rbs +1 -1
  21. data/sig/rubocop/cop/style/rbs_inline/data_struct_helper.rbs +55 -0
  22. data/sig/rubocop/cop/style/rbs_inline/missing_class_annotation.rbs +41 -0
  23. data/sig/rubocop/cop/style/rbs_inline/missing_data_class_annotation.rbs +2 -46
  24. data/sig/rubocop/cop/style/rbs_inline/missing_struct_class_annotation.rbs +46 -0
  25. data/sig/rubocop/cop/style/rbs_inline/struct_class_comment_alignment.rbs +48 -0
  26. data/sig/rubocop/cop/style/rbs_inline/struct_new_with_block.rbs +40 -0
  27. metadata +14 -2
@@ -21,155 +21,25 @@ module RuboCop
21
21
  # )
22
22
  #
23
23
  class MissingDataClassAnnotation < Base
24
- include ASTUtils
25
- include RangeHelp
26
- include SourceCodeHelper
24
+ include MissingClassAnnotation
27
25
  extend AutoCorrector
28
26
 
29
27
  MSG = "Missing inline type annotation for Data attribute (e.g., `#: Type`)."
30
28
 
31
29
  # @rbs node: RuboCop::AST::SendNode
32
30
  def on_send(node) #: void
33
- return unless data_define?(node)
31
+ return unless struct_like_class?(node)
34
32
 
35
- if folded_data_class?(node)
36
- add_offenses_for_folded_data_class(node)
37
- else
38
- check_multiline_data_class(node)
39
- end
33
+ check_missing_annotations(node)
40
34
  end
41
35
 
42
36
  private
43
37
 
44
38
  # @rbs node: RuboCop::AST::SendNode
45
- def data_define?(node) #: bool
39
+ def struct_like_class?(node) #: bool
46
40
  return false unless node.method_name == :define
47
41
 
48
- case (r = node.receiver)
49
- when RuboCop::AST::ConstNode
50
- r.short_name == :Data
51
- else
52
- false
53
- end
54
- end
55
-
56
- # @rbs arg: RuboCop::AST::Node
57
- def data_attribute?(arg) #: bool
58
- arg.sym_type? || arg.str_type?
59
- end
60
-
61
- # @rbs node: RuboCop::AST::SendNode
62
- def data_attributes(node) #: Array[RuboCop::AST::Node]
63
- node.arguments.select { data_attribute?(_1) }
64
- end
65
-
66
- # @rbs line: Integer
67
- def inline_type_annotation?(line) #: boolish
68
- comment = comment_at(line)
69
- comment&.text&.match?(/\A#:/)
70
- end
71
-
72
- # @rbs node: RuboCop::AST::SendNode
73
- def folded_data_class?(node) #: bool
74
- attrs = data_attributes(node)
75
- return false if attrs.empty?
76
-
77
- lines = attrs.map { _1.location.line }
78
- lines.uniq.length < attrs.length || lines.include?(node.location.line)
79
- end
80
-
81
- # @rbs node: RuboCop::AST::SendNode
82
- def add_offenses_for_folded_data_class(node) #: void
83
- corrected = false
84
- data_attributes(node).each do |arg|
85
- if corrected
86
- add_offense(arg)
87
- else
88
- replacement = build_multiline_replacement(node)
89
- loc = node.loc
90
- if loc.begin && loc.end
91
- add_offense(arg) { _1.replace(loc.begin.join(loc.end), replacement) }
92
- corrected = true
93
- end
94
- end
95
- end
96
- end
97
-
98
- # @rbs node: RuboCop::AST::SendNode
99
- def longest_argname(node) #: String
100
- last_index = node.arguments.size - 1
101
- args = node.arguments.each_with_index.map { |a, i| i < last_index ? "#{a.source}," : a.source.to_s }
102
- args.max_by(&:length) || ""
103
- end
104
-
105
- # @rbs node: RuboCop::AST::SendNode
106
- def build_multiline_replacement(node) #: String # rubocop:disable Metrics/AbcSize
107
- base_indent = source_code_at(node.location.line)[/\A\s*/]
108
- last_index = node.arguments.size - 1
109
- longest = longest_argname(node)
110
-
111
- args_source = node.arguments.each_with_index.map do |arg, i|
112
- comma = i < last_index ? "," : ""
113
- prefix = "#{base_indent} #{arg.source}#{comma}"
114
- padding = " " * (longest.length - source!(arg).length - comma.length + 2)
115
- data_attribute?(arg) ? "#{prefix}#{padding}#: untyped" : prefix
116
- end.join("\n")
117
-
118
- "(\n#{args_source}\n#{base_indent})"
119
- end
120
-
121
- # @rbs node: RuboCop::AST::SendNode
122
- def check_multiline_data_class(node) #: void
123
- data_attributes(node).each do |arg|
124
- next if inline_type_annotation?(arg.location.line)
125
-
126
- add_offense(arg) { correct_multiline(_1, node, arg) }
127
- end
128
- end
129
-
130
- # @rbs corrector: RuboCop::Cop::Corrector
131
- # @rbs node: RuboCop::AST::SendNode
132
- # @rbs arg: RuboCop::AST::Node
133
- def correct_multiline(corrector, node, arg) #: void
134
- existing_comment = find_regular_comment(arg.location.line)
135
-
136
- if existing_comment
137
- comment_text = existing_comment.text.sub(/\A#\s*/, "")
138
- corrector.replace(existing_comment.source_range, "#: untyped -- #{comment_text}")
139
- else
140
- insert_annotation(corrector, node, arg)
141
- end
142
- end
143
-
144
- # @rbs corrector: RuboCop::Cop::Corrector
145
- # @rbs node: RuboCop::AST::SendNode
146
- # @rbs arg: RuboCop::AST::Node
147
- def insert_annotation(corrector, node, arg) #: void
148
- line = arg.location.line
149
- line_source = source_code_at(line)
150
- content_end_col = line_source.rstrip.length
151
- padding = [annotation_column(node) - content_end_col, 1].max || raise
152
- line_begin = processed_source.buffer.line_range(line).begin_pos
153
- insert_pos = line_begin + content_end_col
154
-
155
- corrector.insert_before(range_between(insert_pos, insert_pos), "#{" " * padding}#: untyped")
156
- end
157
-
158
- # @rbs node: RuboCop::AST::SendNode
159
- def annotation_column(node) #: Integer
160
- last_arg = node.arguments.last
161
- max_end_col = node.arguments.map do |arg|
162
- comma_length = arg.equal?(last_arg) ? 0 : 1
163
- arg.location.column + source!(arg).length + comma_length
164
- end.max || 0
165
-
166
- max_end_col + 2
167
- end
168
-
169
- # @rbs line: Integer
170
- def find_regular_comment(line) #: Parser::Source::Comment?
171
- comment = comment_at(line)
172
- comment unless comment&.text&.match?(/\A#:/)
42
+ (r = node.receiver).is_a?(RuboCop::AST::ConstNode) && r.short_name == :Data
173
43
  end
174
44
  end
175
45
  end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Style
6
+ module RbsInline
7
+ # Checks that `Struct.new` attributes have inline type annotations.
8
+ #
9
+ # Each attribute passed to `Struct.new` should have a trailing `#:` type
10
+ # annotation comment on the same line. A leading string argument (the struct
11
+ # name) and the `keyword_init:` keyword argument are not attributes and are
12
+ # ignored.
13
+ #
14
+ # @example
15
+ # # bad
16
+ # Point = Struct.new(:x, :y)
17
+ #
18
+ # # good
19
+ # Point = Struct.new(
20
+ # :x, #: Integer
21
+ # :y #: Integer
22
+ # )
23
+ #
24
+ class MissingStructClassAnnotation < Base
25
+ include MissingClassAnnotation
26
+ extend AutoCorrector
27
+
28
+ MSG = "Missing inline type annotation for Struct attribute (e.g., `#: Type`)."
29
+
30
+ # @rbs node: RuboCop::AST::SendNode
31
+ def on_send(node) #: void
32
+ return unless struct_like_class?(node)
33
+
34
+ check_missing_annotations(node)
35
+ end
36
+
37
+ private
38
+
39
+ # @rbs node: RuboCop::AST::SendNode
40
+ def struct_like_class?(node) #: bool
41
+ return false unless node.method_name == :new
42
+
43
+ (r = node.receiver).is_a?(RuboCop::AST::ConstNode) && r.short_name == :Struct
44
+ end
45
+
46
+ # `Struct.new` treats a leading string argument as the struct name, so only
47
+ # symbol arguments are attributes.
48
+ # @rbs arg: RuboCop::AST::Node
49
+ def attr_argument?(arg) #: bool
50
+ arg.sym_type?
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -320,7 +320,7 @@ module RuboCop
320
320
 
321
321
  candidates = param_candidate_names(argument, name)
322
322
  next unless candidates
323
- next if candidates.any? { annotated_names.include?(_1) }
323
+ next if candidates.intersect?(annotated_names)
324
324
 
325
325
  add_offense(argument, message: format(DOC_STYLE_PARAM_MESSAGE, name: param_display_name(argument)))
326
326
  end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Style
6
+ module RbsInline
7
+ # Checks that `#:` inline type annotations in `Struct.new` blocks are aligned.
8
+ #
9
+ # Each `#:` annotation comment should start at the same column, determined by
10
+ # the longest attribute name (plus trailing comma). Folded `Struct.new` calls
11
+ # (where attributes are not one per line) are excluded.
12
+ #
13
+ # @example
14
+ # # bad
15
+ # Point = Struct.new(
16
+ # :x, #: Integer
17
+ # :y #: Integer
18
+ # )
19
+ #
20
+ # # good
21
+ # Point = Struct.new(
22
+ # :x, #: Integer
23
+ # :y #: Integer
24
+ # )
25
+ #
26
+ class StructClassCommentAlignment < Base
27
+ include ClassCommentAlignment
28
+ extend AutoCorrector
29
+
30
+ MSG = "Misaligned inline type annotation for Struct attribute."
31
+
32
+ # @rbs node: RuboCop::AST::SendNode
33
+ def on_send(node) #: void
34
+ return unless struct_like_class?(node)
35
+
36
+ check_comment_alignment(node)
37
+ end
38
+
39
+ private
40
+
41
+ # @rbs node: RuboCop::AST::SendNode
42
+ def struct_like_class?(node) #: bool
43
+ return false unless node.method_name == :new
44
+
45
+ (r = node.receiver).is_a?(RuboCop::AST::ConstNode) && r.short_name == :Struct
46
+ end
47
+
48
+ # `Struct.new` treats a leading string argument as the struct name, so only
49
+ # symbol arguments are attributes.
50
+ # @rbs arg: RuboCop::AST::Node
51
+ def attr_argument?(arg) #: bool
52
+ arg.sym_type?
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Style
6
+ module RbsInline
7
+ # Checks for `Struct.new` calls with a block.
8
+ #
9
+ # RBS::Inline does not parse the contents of `Struct.new` blocks, so any
10
+ # methods defined inside will not be recognized for type checking. Instead,
11
+ # call `Struct.new` without a block and define additional methods by
12
+ # reopening the class separately.
13
+ #
14
+ # @example
15
+ # # bad
16
+ # User = Struct.new(:name, :role) do
17
+ # def admin? = role == :admin #: bool
18
+ # end
19
+ #
20
+ # # good
21
+ # User = Struct.new(:name, :role)
22
+ #
23
+ # class User
24
+ # def admin? = role == :admin #: bool
25
+ # end
26
+ #
27
+ class StructNewWithBlock < Base
28
+ MSG = "Do not use `Struct.new` with a block. RBS::Inline does not parse block contents, " \
29
+ "so methods defined in the block will not be recognized. " \
30
+ "Use a separate class definition instead."
31
+
32
+ # @rbs node: RuboCop::AST::SendNode
33
+ def on_send(node) #: void
34
+ return unless struct_like_class?(node)
35
+
36
+ block_node = node.parent
37
+ return unless block_node&.block_type?
38
+
39
+ add_offense(node)
40
+ end
41
+
42
+ private
43
+
44
+ # @rbs node: RuboCop::AST::SendNode
45
+ def struct_like_class?(node) #: bool
46
+ return false unless node.method_name == :new
47
+
48
+ (r = node.receiver).is_a?(RuboCop::AST::ConstNode) && r.short_name == :Struct
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module RbsInline
5
- VERSION = "1.6.1"
5
+ VERSION = "1.7.0"
6
6
  end
7
7
  end
@@ -25,6 +25,10 @@ gems:
25
25
  version: '0'
26
26
  source:
27
27
  type: stdlib
28
+ - name: language_server-protocol
29
+ version: 3.17.0.6
30
+ source:
31
+ type: rubygems
28
32
  - name: lint_roller
29
33
  version: '1.1'
30
34
  source:
@@ -122,7 +126,7 @@ gems:
122
126
  remote: https://github.com/ruby/gem_rbs_collection.git
123
127
  repo_dir: gems
124
128
  - name: rubocop-numbered-params
125
- version: 1.0.0
129
+ version: 1.0.1
126
130
  source:
127
131
  type: rubygems
128
132
  - name: strscan
@@ -0,0 +1,34 @@
1
+ # Generated from lib/rubocop/cop/style/rbs_inline/class_comment_alignment.rb with RBS::Inline
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Style
6
+ module RbsInline
7
+ # Shared behavior for cops that ensure `#:` inline type annotations on
8
+ # struct-like class attributes (`Data.define` / `Struct.new`) are aligned.
9
+ #
10
+ # The including cop matches the definition node (e.g. via `struct_like_class?`)
11
+ # and calls {#check_comment_alignment}.
12
+ #
13
+ # @rbs module-self RuboCop::Cop::Base
14
+ module ClassCommentAlignment : RuboCop::Cop::Base
15
+ include DataStructHelper
16
+
17
+ # @rbs node: RuboCop::AST::SendNode
18
+ def check_comment_alignment: (RuboCop::AST::SendNode node) -> void
19
+
20
+ private
21
+
22
+ # @rbs node: RuboCop::AST::SendNode
23
+ def check_annotation_alignment: (RuboCop::AST::SendNode node) -> void
24
+
25
+ # @rbs corrector: RuboCop::Cop::Corrector
26
+ # @rbs arg: RuboCop::AST::Node
27
+ # @rbs comment: Parser::Source::Comment
28
+ # @rbs expected_col: Integer
29
+ def correct_alignment: (RuboCop::Cop::Corrector corrector, RuboCop::AST::Node arg, Parser::Source::Comment comment, Integer expected_col) -> void
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -25,11 +25,7 @@ module RuboCop
25
25
  # :visibility #: Symbol
26
26
  # )
27
27
  class DataClassCommentAlignment < Base
28
- include ASTUtils
29
-
30
- include RangeHelp
31
-
32
- include SourceCodeHelper
28
+ include ClassCommentAlignment
33
29
 
34
30
  extend AutoCorrector
35
31
 
@@ -41,31 +37,7 @@ module RuboCop
41
37
  private
42
38
 
43
39
  # @rbs node: RuboCop::AST::SendNode
44
- def data_define?: (RuboCop::AST::SendNode node) -> bool
45
-
46
- # @rbs arg: RuboCop::AST::Node
47
- def data_attribute?: (RuboCop::AST::Node arg) -> bool
48
-
49
- # @rbs node: RuboCop::AST::SendNode
50
- def data_attributes: (RuboCop::AST::SendNode node) -> Array[RuboCop::AST::Node]
51
-
52
- # @rbs node: RuboCop::AST::SendNode
53
- def folded_data_class?: (RuboCop::AST::SendNode node) -> bool
54
-
55
- # @rbs node: RuboCop::AST::SendNode
56
- def check_annotation_alignment: (RuboCop::AST::SendNode node) -> void
57
-
58
- # @rbs line: Integer
59
- def inline_type_comment: (Integer line) -> Parser::Source::Comment?
60
-
61
- # @rbs node: RuboCop::AST::SendNode
62
- def annotation_column: (RuboCop::AST::SendNode node) -> Integer
63
-
64
- # @rbs corrector: RuboCop::Cop::Corrector
65
- # @rbs arg: RuboCop::AST::Node
66
- # @rbs comment: Parser::Source::Comment
67
- # @rbs expected_col: Integer
68
- def correct_alignment: (RuboCop::Cop::Corrector corrector, RuboCop::AST::Node arg, Parser::Source::Comment comment, Integer expected_col) -> void
40
+ def struct_like_class?: (RuboCop::AST::SendNode node) -> bool
69
41
  end
70
42
  end
71
43
  end
@@ -35,7 +35,7 @@ module RuboCop
35
35
  private
36
36
 
37
37
  # @rbs node: RuboCop::AST::SendNode
38
- def data_define?: (RuboCop::AST::SendNode node) -> bool
38
+ def struct_like_class?: (RuboCop::AST::SendNode node) -> bool
39
39
  end
40
40
  end
41
41
  end
@@ -0,0 +1,55 @@
1
+ # Generated from lib/rubocop/cop/style/rbs_inline/data_struct_helper.rb with RBS::Inline
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Style
6
+ module RbsInline
7
+ # Shared logic for cops that check inline type annotations on struct-like
8
+ # class definitions such as `Data.define` and `Struct.new`.
9
+ #
10
+ # Including cops decide which nodes to check by defining their own matcher
11
+ # (e.g. `struct_like_class?`); this module only provides helpers that operate
12
+ # on an already-matched definition node. Cops may override {#attr_argument?}
13
+ # when the set of attribute arguments differs from the default (e.g.
14
+ # `Struct.new` treats a leading string argument as the struct name rather than
15
+ # an attribute).
16
+ #
17
+ # @rbs module-self RuboCop::Cop::Base
18
+ module DataStructHelper : RuboCop::Cop::Base
19
+ include ASTUtils
20
+
21
+ include SourceCodeHelper
22
+
23
+ include RangeHelp
24
+
25
+ # @rbs arg: RuboCop::AST::Node
26
+ def attr_argument?: (RuboCop::AST::Node arg) -> bool
27
+
28
+ # @rbs node: RuboCop::AST::SendNode
29
+ def attr_arguments: (RuboCop::AST::SendNode node) -> Array[RuboCop::AST::Node]
30
+
31
+ # @rbs node: RuboCop::AST::SendNode
32
+ def folded?: (RuboCop::AST::SendNode node) -> bool
33
+
34
+ # @rbs line: Integer
35
+ def inline_type_annotation?: (Integer line) -> boolish
36
+
37
+ # @rbs line: Integer
38
+ def inline_type_comment: (Integer line) -> Parser::Source::Comment?
39
+
40
+ # @rbs line: Integer
41
+ def find_regular_comment: (Integer line) -> Parser::Source::Comment?
42
+
43
+ # @rbs node: RuboCop::AST::SendNode
44
+ def annotation_column: (RuboCop::AST::SendNode node) -> Integer
45
+
46
+ # @rbs node: RuboCop::AST::SendNode
47
+ def longest_argname: (RuboCop::AST::SendNode node) -> String
48
+
49
+ # @rbs node: RuboCop::AST::SendNode
50
+ def build_multiline_replacement: (RuboCop::AST::SendNode node) -> String
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,41 @@
1
+ # Generated from lib/rubocop/cop/style/rbs_inline/missing_class_annotation.rb with RBS::Inline
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Style
6
+ module RbsInline
7
+ # Shared behavior for cops that ensure struct-like class attributes have
8
+ # inline type annotations (`Data.define` / `Struct.new`).
9
+ #
10
+ # The including cop matches the definition node (e.g. via `struct_like_class?`)
11
+ # and calls {#check_missing_annotations}.
12
+ #
13
+ # @rbs module-self RuboCop::Cop::Base
14
+ module MissingClassAnnotation : RuboCop::Cop::Base
15
+ include DataStructHelper
16
+
17
+ # @rbs node: RuboCop::AST::SendNode
18
+ def check_missing_annotations: (RuboCop::AST::SendNode node) -> void
19
+
20
+ private
21
+
22
+ # @rbs node: RuboCop::AST::SendNode
23
+ def add_offenses_for_folded: (RuboCop::AST::SendNode node) -> void
24
+
25
+ # @rbs node: RuboCop::AST::SendNode
26
+ def check_multiline: (RuboCop::AST::SendNode node) -> void
27
+
28
+ # @rbs corrector: RuboCop::Cop::Corrector
29
+ # @rbs node: RuboCop::AST::SendNode
30
+ # @rbs arg: RuboCop::AST::Node
31
+ def correct_multiline: (RuboCop::Cop::Corrector corrector, RuboCop::AST::SendNode node, RuboCop::AST::Node arg) -> void
32
+
33
+ # @rbs corrector: RuboCop::Cop::Corrector
34
+ # @rbs node: RuboCop::AST::SendNode
35
+ # @rbs arg: RuboCop::AST::Node
36
+ def insert_annotation: (RuboCop::Cop::Corrector corrector, RuboCop::AST::SendNode node, RuboCop::AST::Node arg) -> void
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -20,11 +20,7 @@ module RuboCop
20
20
  # :visibility #: Symbol
21
21
  # )
22
22
  class MissingDataClassAnnotation < Base
23
- include ASTUtils
24
-
25
- include RangeHelp
26
-
27
- include SourceCodeHelper
23
+ include MissingClassAnnotation
28
24
 
29
25
  extend AutoCorrector
30
26
 
@@ -36,47 +32,7 @@ module RuboCop
36
32
  private
37
33
 
38
34
  # @rbs node: RuboCop::AST::SendNode
39
- def data_define?: (RuboCop::AST::SendNode node) -> bool
40
-
41
- # @rbs arg: RuboCop::AST::Node
42
- def data_attribute?: (RuboCop::AST::Node arg) -> bool
43
-
44
- # @rbs node: RuboCop::AST::SendNode
45
- def data_attributes: (RuboCop::AST::SendNode node) -> Array[RuboCop::AST::Node]
46
-
47
- # @rbs line: Integer
48
- def inline_type_annotation?: (Integer line) -> boolish
49
-
50
- # @rbs node: RuboCop::AST::SendNode
51
- def folded_data_class?: (RuboCop::AST::SendNode node) -> bool
52
-
53
- # @rbs node: RuboCop::AST::SendNode
54
- def add_offenses_for_folded_data_class: (RuboCop::AST::SendNode node) -> void
55
-
56
- # @rbs node: RuboCop::AST::SendNode
57
- def longest_argname: (RuboCop::AST::SendNode node) -> String
58
-
59
- # @rbs node: RuboCop::AST::SendNode
60
- def build_multiline_replacement: (RuboCop::AST::SendNode node) -> String
61
-
62
- # @rbs node: RuboCop::AST::SendNode
63
- def check_multiline_data_class: (RuboCop::AST::SendNode node) -> void
64
-
65
- # @rbs corrector: RuboCop::Cop::Corrector
66
- # @rbs node: RuboCop::AST::SendNode
67
- # @rbs arg: RuboCop::AST::Node
68
- def correct_multiline: (RuboCop::Cop::Corrector corrector, RuboCop::AST::SendNode node, RuboCop::AST::Node arg) -> void
69
-
70
- # @rbs corrector: RuboCop::Cop::Corrector
71
- # @rbs node: RuboCop::AST::SendNode
72
- # @rbs arg: RuboCop::AST::Node
73
- def insert_annotation: (RuboCop::Cop::Corrector corrector, RuboCop::AST::SendNode node, RuboCop::AST::Node arg) -> void
74
-
75
- # @rbs node: RuboCop::AST::SendNode
76
- def annotation_column: (RuboCop::AST::SendNode node) -> Integer
77
-
78
- # @rbs line: Integer
79
- def find_regular_comment: (Integer line) -> Parser::Source::Comment?
35
+ def struct_like_class?: (RuboCop::AST::SendNode node) -> bool
80
36
  end
81
37
  end
82
38
  end
@@ -0,0 +1,46 @@
1
+ # Generated from lib/rubocop/cop/style/rbs_inline/missing_struct_class_annotation.rb with RBS::Inline
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Style
6
+ module RbsInline
7
+ # Checks that `Struct.new` attributes have inline type annotations.
8
+ #
9
+ # Each attribute passed to `Struct.new` should have a trailing `#:` type
10
+ # annotation comment on the same line. A leading string argument (the struct
11
+ # name) and the `keyword_init:` keyword argument are not attributes and are
12
+ # ignored.
13
+ #
14
+ # @example
15
+ # # bad
16
+ # Point = Struct.new(:x, :y)
17
+ #
18
+ # # good
19
+ # Point = Struct.new(
20
+ # :x, #: Integer
21
+ # :y #: Integer
22
+ # )
23
+ class MissingStructClassAnnotation < Base
24
+ include MissingClassAnnotation
25
+
26
+ extend AutoCorrector
27
+
28
+ MSG: ::String
29
+
30
+ # @rbs node: RuboCop::AST::SendNode
31
+ def on_send: (RuboCop::AST::SendNode node) -> void
32
+
33
+ private
34
+
35
+ # @rbs node: RuboCop::AST::SendNode
36
+ def struct_like_class?: (RuboCop::AST::SendNode node) -> bool
37
+
38
+ # `Struct.new` treats a leading string argument as the struct name, so only
39
+ # symbol arguments are attributes.
40
+ # @rbs arg: RuboCop::AST::Node
41
+ def attr_argument?: (RuboCop::AST::Node arg) -> bool
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end