rubocop-rbs_inline 1.7.0 → 2.0.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.
- checksums.yaml +4 -4
- data/.claude/hooks/pre-commit-check.sh +42 -2
- data/.claude/hooks/protect-sig-files.sh +45 -0
- data/.claude/hooks/self-review.sh +89 -0
- data/.claude/settings.json +16 -1
- data/.rubocop.yml +17 -12
- data/CHANGELOG.md +30 -0
- data/CLAUDE.md +11 -14
- data/README.md +51 -6
- data/Rakefile +12 -3
- data/config/default.yml +2 -4
- data/lib/rubocop/cop/rbs_inline_cops.rb +16 -7
- data/lib/rubocop/cop/style/rbs_inline/data_class_comment_alignment.rb +2 -9
- data/lib/rubocop/cop/style/rbs_inline/data_define_with_block.rb +13 -7
- data/lib/rubocop/cop/style/rbs_inline/embedded_rbs_spacing.rb +3 -2
- data/lib/rubocop/cop/style/rbs_inline/invalid_comment.rb +2 -2
- data/lib/rubocop/cop/style/rbs_inline/invalid_types.rb +1 -0
- data/lib/rubocop/cop/style/rbs_inline/keyword_separator.rb +2 -2
- data/lib/rubocop/cop/style/rbs_inline/method_comment_spacing.rb +3 -2
- data/lib/rubocop/cop/style/rbs_inline/missing_data_class_annotation.rb +2 -9
- data/lib/rubocop/cop/style/rbs_inline/missing_struct_class_annotation.rb +2 -16
- data/lib/rubocop/cop/style/rbs_inline/missing_type_annotation.rb +3 -16
- data/lib/rubocop/cop/style/rbs_inline/mixin/annotation_keywords.rb +16 -0
- data/lib/rubocop/cop/style/rbs_inline/mixin/ast_utils.rb +75 -0
- data/lib/rubocop/cop/style/rbs_inline/{comment_parser.rb → mixin/comment_parser.rb} +8 -0
- data/lib/rubocop/cop/style/rbs_inline/mixin/data_class_matcher.rb +22 -0
- data/lib/rubocop/cop/style/rbs_inline/{data_struct_helper.rb → mixin/data_struct_helper.rb} +14 -5
- data/lib/rubocop/cop/style/rbs_inline/mixin/file_filter.rb +72 -0
- data/lib/rubocop/cop/style/rbs_inline/mixin/mode_config.rb +39 -0
- data/lib/rubocop/cop/style/rbs_inline/{source_code_helper.rb → mixin/source_code_helper.rb} +3 -5
- data/lib/rubocop/cop/style/rbs_inline/mixin/struct_class_matcher.rb +32 -0
- data/lib/rubocop/cop/style/rbs_inline/parameters_separator.rb +2 -2
- data/lib/rubocop/cop/style/rbs_inline/redundant_annotation_with_skip.rb +2 -11
- data/lib/rubocop/cop/style/rbs_inline/redundant_instance_variable_annotation.rb +1 -0
- data/lib/rubocop/cop/style/rbs_inline/redundant_type_annotation.rb +6 -15
- data/lib/rubocop/cop/style/rbs_inline/require_rbs_inline_comment.rb +35 -23
- data/lib/rubocop/cop/style/rbs_inline/struct_class_comment_alignment.rb +2 -16
- data/lib/rubocop/cop/style/rbs_inline/struct_new_with_block.rb +13 -7
- data/lib/rubocop/cop/style/rbs_inline/unmatched_annotations.rb +31 -6
- data/lib/rubocop/cop/style/rbs_inline/untyped_instance_variable.rb +16 -6
- data/lib/rubocop/cop/style/rbs_inline/variable_comment_spacing.rb +3 -2
- data/lib/rubocop/rbs_inline/version.rb +1 -1
- data/rbs_collection.lock.yaml +11 -11
- data/sig/gems/rubocop/rubocop.rbs +14 -0
- data/sig/rubocop/cop/style/rbs_inline/data_class_comment_alignment.rbs +4 -5
- data/sig/rubocop/cop/style/rbs_inline/data_define_with_block.rbs +9 -2
- data/sig/rubocop/cop/style/rbs_inline/embedded_rbs_spacing.rbs +2 -0
- data/sig/rubocop/cop/style/rbs_inline/invalid_comment.rbs +4 -3
- data/sig/rubocop/cop/style/rbs_inline/invalid_types.rbs +2 -0
- data/sig/rubocop/cop/style/rbs_inline/keyword_separator.rbs +4 -3
- data/sig/rubocop/cop/style/rbs_inline/method_comment_spacing.rbs +2 -0
- data/sig/rubocop/cop/style/rbs_inline/missing_data_class_annotation.rbs +4 -5
- data/sig/rubocop/cop/style/rbs_inline/missing_struct_class_annotation.rbs +4 -10
- data/sig/rubocop/cop/style/rbs_inline/missing_type_annotation.rbs +4 -8
- data/sig/rubocop/cop/style/rbs_inline/mixin/annotation_keywords.rbs +16 -0
- data/sig/rubocop/cop/style/rbs_inline/{ast_utils.rbs → mixin/ast_utils.rbs} +14 -1
- data/sig/rubocop/cop/style/rbs_inline/{class_comment_alignment.rbs → mixin/class_comment_alignment.rbs} +1 -1
- data/sig/rubocop/cop/style/rbs_inline/{comment_parser.rbs → mixin/comment_parser.rbs} +5 -1
- data/sig/rubocop/cop/style/rbs_inline/mixin/data_class_matcher.rbs +18 -0
- data/sig/rubocop/cop/style/rbs_inline/{data_struct_helper.rbs → mixin/data_struct_helper.rbs} +6 -1
- data/sig/rubocop/cop/style/rbs_inline/mixin/file_filter.rbs +53 -0
- data/sig/rubocop/cop/style/rbs_inline/{missing_class_annotation.rbs → mixin/missing_class_annotation.rbs} +1 -1
- data/sig/rubocop/cop/style/rbs_inline/mixin/mode_config.rbs +27 -0
- data/sig/rubocop/cop/style/rbs_inline/{source_code_helper.rbs → mixin/source_code_helper.rbs} +1 -1
- data/sig/rubocop/cop/style/rbs_inline/mixin/struct_class_matcher.rbs +26 -0
- data/sig/rubocop/cop/style/rbs_inline/parameters_separator.rbs +4 -3
- data/sig/rubocop/cop/style/rbs_inline/redundant_annotation_with_skip.rbs +4 -4
- data/sig/rubocop/cop/style/rbs_inline/redundant_instance_variable_annotation.rbs +2 -0
- data/sig/rubocop/cop/style/rbs_inline/redundant_type_annotation.rbs +4 -4
- data/sig/rubocop/cop/style/rbs_inline/require_rbs_inline_comment.rbs +22 -5
- data/sig/rubocop/cop/style/rbs_inline/struct_class_comment_alignment.rbs +4 -10
- data/sig/rubocop/cop/style/rbs_inline/struct_new_with_block.rbs +9 -2
- data/sig/rubocop/cop/style/rbs_inline/unmatched_annotations.rbs +13 -0
- data/sig/rubocop/cop/style/rbs_inline/untyped_instance_variable.rbs +10 -0
- data/sig/rubocop/cop/style/rbs_inline/variable_comment_spacing.rbs +2 -0
- metadata +28 -18
- data/lib/rubocop/cop/style/rbs_inline/ast_utils.rb +0 -46
- data/sig/rubocop/cop/style/rbs_inline/redundant_argument_type.rbs +0 -85
- data/sig/rubocop/cop/style/rbs_inline/redundant_return_type.rbs +0 -109
- /data/.claude/hooks/{setup.sh → claude-code-web-session-start.sh} +0 -0
- /data/lib/rubocop/cop/style/rbs_inline/{class_comment_alignment.rb → mixin/class_comment_alignment.rb} +0 -0
- /data/lib/rubocop/cop/style/rbs_inline/{missing_class_annotation.rb → mixin/missing_class_annotation.rb} +0 -0
|
@@ -10,7 +10,7 @@ module RuboCop
|
|
|
10
10
|
# opt-out (processes all files by default). This cop enforces consistency in which
|
|
11
11
|
# mode your codebase uses.
|
|
12
12
|
#
|
|
13
|
-
# @example
|
|
13
|
+
# @example Mode: opt_in
|
|
14
14
|
# # bad
|
|
15
15
|
# # (no rbs_inline comment)
|
|
16
16
|
# class Foo
|
|
@@ -26,7 +26,17 @@ module RuboCop
|
|
|
26
26
|
# class Foo
|
|
27
27
|
# end
|
|
28
28
|
#
|
|
29
|
-
# @example
|
|
29
|
+
# @example Mode: opt_in, AllowMissingComment: true
|
|
30
|
+
# # good - the cop does not enforce the magic comment
|
|
31
|
+
# class Foo
|
|
32
|
+
# end
|
|
33
|
+
#
|
|
34
|
+
# # good
|
|
35
|
+
# # rbs_inline: enabled
|
|
36
|
+
# class Foo
|
|
37
|
+
# end
|
|
38
|
+
#
|
|
39
|
+
# @example Mode: opt_out
|
|
30
40
|
# # bad
|
|
31
41
|
# # rbs_inline: enabled
|
|
32
42
|
# class Foo
|
|
@@ -43,6 +53,7 @@ module RuboCop
|
|
|
43
53
|
# end
|
|
44
54
|
#
|
|
45
55
|
class RequireRbsInlineComment < Base
|
|
56
|
+
include ModeConfig
|
|
46
57
|
include RangeHelp
|
|
47
58
|
extend AutoCorrector
|
|
48
59
|
|
|
@@ -55,10 +66,9 @@ module RuboCop
|
|
|
55
66
|
magic_comment = find_rbs_inline_magic_comment
|
|
56
67
|
return if disabled?(magic_comment)
|
|
57
68
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
check_never_style(magic_comment)
|
|
69
|
+
case configured_mode
|
|
70
|
+
when :opt_in then check_opt_in(magic_comment)
|
|
71
|
+
when :opt_out then check_opt_out(magic_comment)
|
|
62
72
|
end
|
|
63
73
|
end
|
|
64
74
|
|
|
@@ -76,41 +86,45 @@ module RuboCop
|
|
|
76
86
|
end
|
|
77
87
|
|
|
78
88
|
# @rbs magic_comment: Parser::Source::Comment?
|
|
79
|
-
def
|
|
80
|
-
# disabled is already filtered out by early return
|
|
81
|
-
# magic_comment is either nil or enabled
|
|
89
|
+
def check_opt_in(magic_comment) #: void
|
|
82
90
|
return if magic_comment
|
|
91
|
+
return if allow_missing_comment?
|
|
83
92
|
|
|
84
|
-
# Insert after the first comment block or at the beginning of the file
|
|
85
93
|
insert_position = find_insert_position
|
|
86
94
|
add_offense(first_line_range, message: MSG_MISSING) do |corrector|
|
|
87
95
|
insert_range = Parser::Source::Range.new(processed_source.buffer, insert_position, insert_position)
|
|
88
|
-
corrector.insert_before(insert_range,
|
|
96
|
+
corrector.insert_before(insert_range, insertion_text(insert_position))
|
|
89
97
|
end
|
|
90
98
|
end
|
|
91
99
|
|
|
92
100
|
# @rbs magic_comment: Parser::Source::Comment?
|
|
93
|
-
def
|
|
94
|
-
# disabled is already filtered out by early return
|
|
95
|
-
# magic_comment is either nil or enabled
|
|
101
|
+
def check_opt_out(magic_comment) #: void
|
|
96
102
|
return unless magic_comment
|
|
97
103
|
|
|
98
104
|
add_offense(magic_comment.source_range, message: MSG_FORBIDDEN) do |corrector|
|
|
99
|
-
# Remove the entire line including newline
|
|
100
105
|
range = range_with_surrounding_space(magic_comment.source_range, side: :right, newlines: true)
|
|
101
106
|
corrector.remove(range)
|
|
102
107
|
end
|
|
103
108
|
end
|
|
104
109
|
|
|
105
110
|
def find_insert_position #: Integer
|
|
106
|
-
# Find the end of the first comment block (e.g., magic comments)
|
|
107
|
-
# and insert after it
|
|
108
111
|
first_comment = processed_source.comments.first
|
|
109
|
-
# If the first comment doesn't exist or doesn't start at line 1, insert at the beginning
|
|
110
112
|
return 0 unless first_comment&.source_range&.first_line == 1
|
|
111
113
|
|
|
112
114
|
last_comment_in_block = find_last_comment_in_first_block
|
|
113
|
-
|
|
115
|
+
# `end_pos` points at the newline terminating the comment, so `+ 1` moves past it.
|
|
116
|
+
# A file without a trailing newline has none, so clamp to the end of the buffer.
|
|
117
|
+
(last_comment_in_block.source_range.end_pos + 1).clamp(0, processed_source.buffer.source.length)
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
# The insert position lands at the end of the buffer when the file has no trailing
|
|
121
|
+
# newline. The magic comment then needs its own newline to stay on a separate line.
|
|
122
|
+
# @rbs insert_position: Integer
|
|
123
|
+
def insertion_text(insert_position) #: String
|
|
124
|
+
source = processed_source.buffer.source
|
|
125
|
+
return "# rbs_inline: enabled\n" if insert_position.zero? || source[insert_position - 1] == "\n"
|
|
126
|
+
|
|
127
|
+
"\n# rbs_inline: enabled\n"
|
|
114
128
|
end
|
|
115
129
|
|
|
116
130
|
def find_last_comment_in_first_block #: Parser::Source::Comment
|
|
@@ -127,13 +141,11 @@ module RuboCop
|
|
|
127
141
|
comments[last_idx] || raise
|
|
128
142
|
end
|
|
129
143
|
|
|
130
|
-
def
|
|
131
|
-
cop_config["
|
|
144
|
+
def allow_missing_comment? #: bool
|
|
145
|
+
cop_config["AllowMissingComment"] == true
|
|
132
146
|
end
|
|
133
147
|
|
|
134
148
|
def first_line_range #: Parser::Source::Range
|
|
135
|
-
# Find the first line of actual code (not comment-only lines)
|
|
136
|
-
# If there's no AST (e.g., file with only comments), use the first line
|
|
137
149
|
first_line = processed_source.ast&.source_range&.first_line || 1
|
|
138
150
|
processed_source.buffer.line_range(first_line)
|
|
139
151
|
end
|
|
@@ -24,7 +24,9 @@ module RuboCop
|
|
|
24
24
|
# )
|
|
25
25
|
#
|
|
26
26
|
class StructClassCommentAlignment < Base
|
|
27
|
+
prepend FileFilter
|
|
27
28
|
include ClassCommentAlignment
|
|
29
|
+
include StructClassMatcher
|
|
28
30
|
extend AutoCorrector
|
|
29
31
|
|
|
30
32
|
MSG = "Misaligned inline type annotation for Struct attribute."
|
|
@@ -35,22 +37,6 @@ module RuboCop
|
|
|
35
37
|
|
|
36
38
|
check_comment_alignment(node)
|
|
37
39
|
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
40
|
end
|
|
55
41
|
end
|
|
56
42
|
end
|
|
@@ -25,9 +25,13 @@ module RuboCop
|
|
|
25
25
|
# end
|
|
26
26
|
#
|
|
27
27
|
class StructNewWithBlock < Base
|
|
28
|
+
prepend FileFilter
|
|
29
|
+
include StructClassMatcher
|
|
30
|
+
include ASTUtils
|
|
31
|
+
|
|
28
32
|
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
|
-
"
|
|
33
|
+
"so methods defined in the block will not be recognized. Keep the `Struct.new` call " \
|
|
34
|
+
"and move the methods into %<destination>s."
|
|
31
35
|
|
|
32
36
|
# @rbs node: RuboCop::AST::SendNode
|
|
33
37
|
def on_send(node) #: void
|
|
@@ -36,16 +40,18 @@ module RuboCop
|
|
|
36
40
|
block_node = node.parent
|
|
37
41
|
return unless block_node&.block_type?
|
|
38
42
|
|
|
39
|
-
add_offense(node)
|
|
43
|
+
add_offense(node, message: format(MSG, destination: destination(block_node)))
|
|
40
44
|
end
|
|
41
45
|
|
|
42
46
|
private
|
|
43
47
|
|
|
44
|
-
#
|
|
45
|
-
|
|
46
|
-
|
|
48
|
+
# The constant the definition is assigned to is the class to reopen.
|
|
49
|
+
# @rbs node: RuboCop::AST::Node
|
|
50
|
+
def destination(node) #: String
|
|
51
|
+
class_name = assigned_constant_name(node)
|
|
52
|
+
return "a `class` that reopens it" unless class_name
|
|
47
53
|
|
|
48
|
-
|
|
54
|
+
"`class #{class_name} ... end` written after it"
|
|
49
55
|
end
|
|
50
56
|
end
|
|
51
57
|
end
|
|
@@ -18,14 +18,18 @@ module RuboCop
|
|
|
18
18
|
# def method(arg); end
|
|
19
19
|
#
|
|
20
20
|
class UnmatchedAnnotations < Base
|
|
21
|
+
prepend FileFilter
|
|
21
22
|
include CommentParser
|
|
22
23
|
include RangeHelp
|
|
23
24
|
include SourceCodeHelper
|
|
24
25
|
|
|
25
26
|
MSG = "target parameter not found."
|
|
26
27
|
|
|
28
|
+
attr_reader :processed_comments #: Set[RBS::Inline::AnnotationParser::ParsingResult] -- matched to a def node
|
|
29
|
+
|
|
27
30
|
def on_new_investigation #: void
|
|
28
31
|
super
|
|
32
|
+
@processed_comments = Set.new
|
|
29
33
|
parse_comments
|
|
30
34
|
end
|
|
31
35
|
|
|
@@ -41,6 +45,8 @@ module RuboCop
|
|
|
41
45
|
|
|
42
46
|
def on_investigation_end #: void
|
|
43
47
|
parsed_comments.each do |comment|
|
|
48
|
+
next if processed?(comment)
|
|
49
|
+
|
|
44
50
|
comment.each_annotation do |annotation|
|
|
45
51
|
case annotation
|
|
46
52
|
when RBS::Inline::AST::Annotations::BlockType,
|
|
@@ -57,15 +63,13 @@ module RuboCop
|
|
|
57
63
|
private
|
|
58
64
|
|
|
59
65
|
# @rbs node: RuboCop::AST::DefNode
|
|
60
|
-
def process(node) #: void
|
|
66
|
+
def process(node) #: void
|
|
61
67
|
arguments = arguments_for(node)
|
|
62
68
|
|
|
63
|
-
comment =
|
|
64
|
-
r.comments.map(&:location).map(&:start_line).include?(node.location.line - 1)
|
|
65
|
-
end
|
|
69
|
+
comment = leading_comment_for(node)
|
|
66
70
|
return unless comment
|
|
67
71
|
|
|
68
|
-
|
|
72
|
+
mark_processed(comment)
|
|
69
73
|
comment.each_annotation do |annotation|
|
|
70
74
|
case annotation
|
|
71
75
|
when RBS::Inline::AST::Annotations::IvarType
|
|
@@ -76,6 +80,25 @@ module RuboCop
|
|
|
76
80
|
end
|
|
77
81
|
end
|
|
78
82
|
|
|
83
|
+
# @rbs node: RuboCop::AST::DefNode
|
|
84
|
+
def leading_comment_for(node) #: RBS::Inline::AnnotationParser::ParsingResult?
|
|
85
|
+
parsed_comments.find do |comment|
|
|
86
|
+
next if processed?(comment)
|
|
87
|
+
|
|
88
|
+
comment.comments.map(&:location).map(&:start_line).include?(node.location.line - 1)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# @rbs comment: RBS::Inline::AnnotationParser::ParsingResult
|
|
93
|
+
def mark_processed(comment) #: void
|
|
94
|
+
processed_comments << comment
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# @rbs comment: RBS::Inline::AnnotationParser::ParsingResult
|
|
98
|
+
def processed?(comment) #: bool
|
|
99
|
+
processed_comments.include?(comment)
|
|
100
|
+
end
|
|
101
|
+
|
|
79
102
|
# @rbs node: RuboCop::AST::DefNode
|
|
80
103
|
def arguments_for(node) #: Array[String] # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
81
104
|
args_for(node).children.flat_map do |argument| # rubocop:disable Metrics/BlockLength
|
|
@@ -104,7 +127,9 @@ module RuboCop
|
|
|
104
127
|
when :forward_arg
|
|
105
128
|
["..."]
|
|
106
129
|
else
|
|
107
|
-
|
|
130
|
+
# Unnamed parameters (ex. destructuring arguments; `def foo((a, b))`) are not
|
|
131
|
+
# annotatable because RBS::Inline does not generate types for them.
|
|
132
|
+
[]
|
|
108
133
|
end
|
|
109
134
|
end
|
|
110
135
|
end
|
|
@@ -59,6 +59,7 @@ module RuboCop
|
|
|
59
59
|
# end
|
|
60
60
|
#
|
|
61
61
|
class UntypedInstanceVariable < Base
|
|
62
|
+
prepend FileFilter
|
|
62
63
|
include ASTUtils
|
|
63
64
|
include CommentParser
|
|
64
65
|
include RangeHelp
|
|
@@ -185,12 +186,21 @@ module RuboCop
|
|
|
185
186
|
def collect_typed_ivars_for_scope(node) #: void
|
|
186
187
|
class_start = node.location.line
|
|
187
188
|
class_end = end_line(node, default: class_start)
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
189
|
+
lines = class_start..class_end
|
|
190
|
+
move_annotations(ivar_type_annotations, current_scope[:typed_ivars], lines)
|
|
191
|
+
move_annotations(civar_type_annotations, current_scope[:typed_class_ivars], lines)
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
# Moves the annotations placed within +lines+ from +annotations+ into +typed+
|
|
195
|
+
# so that outer scopes no longer see them.
|
|
196
|
+
#
|
|
197
|
+
# @rbs annotations: Hash[Integer, Symbol]
|
|
198
|
+
# @rbs typed: Set[Symbol]
|
|
199
|
+
# @rbs lines: Range[Integer]
|
|
200
|
+
def move_annotations(annotations, typed, lines) #: void
|
|
201
|
+
inside, outside = annotations.partition { |line, _name| lines.cover?(line) }
|
|
202
|
+
typed.merge(inside.map { |_line, name| name })
|
|
203
|
+
annotations.replace(outside.to_h)
|
|
194
204
|
end
|
|
195
205
|
|
|
196
206
|
def collect_ivar_type_annotations #: [Hash[Integer, Symbol], Hash[Integer, Symbol]]
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative "source_code_helper"
|
|
4
|
-
require_relative "comment_parser"
|
|
3
|
+
require_relative "mixin/source_code_helper"
|
|
4
|
+
require_relative "mixin/comment_parser"
|
|
5
5
|
|
|
6
6
|
module RuboCop
|
|
7
7
|
module Cop
|
|
@@ -31,6 +31,7 @@ module RuboCop
|
|
|
31
31
|
# end
|
|
32
32
|
#
|
|
33
33
|
class VariableCommentSpacing < Base
|
|
34
|
+
prepend FileFilter
|
|
34
35
|
extend AutoCorrector
|
|
35
36
|
include SourceCodeHelper
|
|
36
37
|
include CommentParser
|
data/rbs_collection.lock.yaml
CHANGED
|
@@ -6,7 +6,7 @@ gems:
|
|
|
6
6
|
source:
|
|
7
7
|
type: git
|
|
8
8
|
name: ruby/gem_rbs_collection
|
|
9
|
-
revision:
|
|
9
|
+
revision: 82762423fc5694b82888ea89a972847cf19838c2
|
|
10
10
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
11
11
|
repo_dir: gems
|
|
12
12
|
- name: diff-lcs
|
|
@@ -14,7 +14,7 @@ gems:
|
|
|
14
14
|
source:
|
|
15
15
|
type: git
|
|
16
16
|
name: ruby/gem_rbs_collection
|
|
17
|
-
revision:
|
|
17
|
+
revision: 82762423fc5694b82888ea89a972847cf19838c2
|
|
18
18
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
19
19
|
repo_dir: gems
|
|
20
20
|
- name: fileutils
|
|
@@ -34,7 +34,7 @@ gems:
|
|
|
34
34
|
source:
|
|
35
35
|
type: git
|
|
36
36
|
name: ruby/gem_rbs_collection
|
|
37
|
-
revision:
|
|
37
|
+
revision: 82762423fc5694b82888ea89a972847cf19838c2
|
|
38
38
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
39
39
|
repo_dir: gems
|
|
40
40
|
- name: logger
|
|
@@ -42,7 +42,7 @@ gems:
|
|
|
42
42
|
source:
|
|
43
43
|
type: git
|
|
44
44
|
name: ruby/gem_rbs_collection
|
|
45
|
-
revision:
|
|
45
|
+
revision: 82762423fc5694b82888ea89a972847cf19838c2
|
|
46
46
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
47
47
|
repo_dir: gems
|
|
48
48
|
- name: monitor
|
|
@@ -58,7 +58,7 @@ gems:
|
|
|
58
58
|
source:
|
|
59
59
|
type: git
|
|
60
60
|
name: ruby/gem_rbs_collection
|
|
61
|
-
revision:
|
|
61
|
+
revision: 82762423fc5694b82888ea89a972847cf19838c2
|
|
62
62
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
63
63
|
repo_dir: gems
|
|
64
64
|
- name: parser
|
|
@@ -66,7 +66,7 @@ gems:
|
|
|
66
66
|
source:
|
|
67
67
|
type: git
|
|
68
68
|
name: ruby/gem_rbs_collection
|
|
69
|
-
revision:
|
|
69
|
+
revision: 82762423fc5694b82888ea89a972847cf19838c2
|
|
70
70
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
71
71
|
repo_dir: gems
|
|
72
72
|
- name: prism
|
|
@@ -78,7 +78,7 @@ gems:
|
|
|
78
78
|
source:
|
|
79
79
|
type: git
|
|
80
80
|
name: ruby/gem_rbs_collection
|
|
81
|
-
revision:
|
|
81
|
+
revision: 82762423fc5694b82888ea89a972847cf19838c2
|
|
82
82
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
83
83
|
repo_dir: gems
|
|
84
84
|
- name: rake
|
|
@@ -86,7 +86,7 @@ gems:
|
|
|
86
86
|
source:
|
|
87
87
|
type: git
|
|
88
88
|
name: ruby/gem_rbs_collection
|
|
89
|
-
revision:
|
|
89
|
+
revision: 82762423fc5694b82888ea89a972847cf19838c2
|
|
90
90
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
91
91
|
repo_dir: gems
|
|
92
92
|
- name: rbs
|
|
@@ -106,7 +106,7 @@ gems:
|
|
|
106
106
|
source:
|
|
107
107
|
type: git
|
|
108
108
|
name: ruby/gem_rbs_collection
|
|
109
|
-
revision:
|
|
109
|
+
revision: 82762423fc5694b82888ea89a972847cf19838c2
|
|
110
110
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
111
111
|
repo_dir: gems
|
|
112
112
|
- name: rubocop
|
|
@@ -114,7 +114,7 @@ gems:
|
|
|
114
114
|
source:
|
|
115
115
|
type: git
|
|
116
116
|
name: ruby/gem_rbs_collection
|
|
117
|
-
revision:
|
|
117
|
+
revision: 82762423fc5694b82888ea89a972847cf19838c2
|
|
118
118
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
119
119
|
repo_dir: gems
|
|
120
120
|
- name: rubocop-ast
|
|
@@ -122,7 +122,7 @@ gems:
|
|
|
122
122
|
source:
|
|
123
123
|
type: git
|
|
124
124
|
name: ruby/gem_rbs_collection
|
|
125
|
-
revision:
|
|
125
|
+
revision: 82762423fc5694b82888ea89a972847cf19838c2
|
|
126
126
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
127
127
|
repo_dir: gems
|
|
128
128
|
- name: rubocop-numbered-params
|
|
@@ -25,19 +25,18 @@ module RuboCop
|
|
|
25
25
|
# :visibility #: Symbol
|
|
26
26
|
# )
|
|
27
27
|
class DataClassCommentAlignment < Base
|
|
28
|
+
prepend FileFilter
|
|
29
|
+
|
|
28
30
|
include ClassCommentAlignment
|
|
29
31
|
|
|
32
|
+
include DataClassMatcher
|
|
33
|
+
|
|
30
34
|
extend AutoCorrector
|
|
31
35
|
|
|
32
36
|
MSG: ::String
|
|
33
37
|
|
|
34
38
|
# @rbs node: RuboCop::AST::SendNode
|
|
35
39
|
def on_send: (RuboCop::AST::SendNode node) -> void
|
|
36
|
-
|
|
37
|
-
private
|
|
38
|
-
|
|
39
|
-
# @rbs node: RuboCop::AST::SendNode
|
|
40
|
-
def struct_like_class?: (RuboCop::AST::SendNode node) -> bool
|
|
41
40
|
end
|
|
42
41
|
end
|
|
43
42
|
end
|
|
@@ -27,6 +27,12 @@ module RuboCop
|
|
|
27
27
|
# def admin? = role == :admin #: bool
|
|
28
28
|
# end
|
|
29
29
|
class DataDefineWithBlock < Base
|
|
30
|
+
prepend FileFilter
|
|
31
|
+
|
|
32
|
+
include DataClassMatcher
|
|
33
|
+
|
|
34
|
+
include ASTUtils
|
|
35
|
+
|
|
30
36
|
MSG: ::String
|
|
31
37
|
|
|
32
38
|
# @rbs node: RuboCop::AST::SendNode
|
|
@@ -34,8 +40,9 @@ module RuboCop
|
|
|
34
40
|
|
|
35
41
|
private
|
|
36
42
|
|
|
37
|
-
#
|
|
38
|
-
|
|
43
|
+
# The constant the definition is assigned to is the class to reopen.
|
|
44
|
+
# @rbs node: RuboCop::AST::Node
|
|
45
|
+
def destination: (RuboCop::AST::Node node) -> String
|
|
39
46
|
end
|
|
40
47
|
end
|
|
41
48
|
end
|
|
@@ -17,12 +17,13 @@ module RuboCop
|
|
|
17
17
|
# #: () -> void
|
|
18
18
|
# # @rbs param: String
|
|
19
19
|
class InvalidComment < Base
|
|
20
|
+
prepend FileFilter
|
|
21
|
+
|
|
20
22
|
extend AutoCorrector
|
|
21
23
|
|
|
22
|
-
|
|
24
|
+
include AnnotationKeywords
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
RBS_INLINE_KEYWORDS: Array[String]
|
|
26
|
+
MSG: ::String
|
|
26
27
|
|
|
27
28
|
RBS_INLINE_KEYWORD_PATTERN: String
|
|
28
29
|
|
|
@@ -14,17 +14,18 @@ module RuboCop
|
|
|
14
14
|
# # good
|
|
15
15
|
# # @rbs module-self String
|
|
16
16
|
class KeywordSeparator < Base
|
|
17
|
+
prepend FileFilter
|
|
18
|
+
|
|
17
19
|
extend AutoCorrector
|
|
18
20
|
|
|
21
|
+
include AnnotationKeywords
|
|
22
|
+
|
|
19
23
|
include CommentParser
|
|
20
24
|
|
|
21
25
|
include RangeHelp
|
|
22
26
|
|
|
23
27
|
MSG: ::String
|
|
24
28
|
|
|
25
|
-
# refs: https://github.com/soutaro/rbs-inline/blob/main/lib/rbs/inline/annotation_parser/tokenizer.rb
|
|
26
|
-
RBS_INLINE_KEYWORDS: Array[String]
|
|
27
|
-
|
|
28
29
|
# `override` and `skip` are standalone markers that take no arguments.
|
|
29
30
|
# Even before a method definition they may not be followed by `:` alone,
|
|
30
31
|
# because `# @rbs override:` (no type) is not a valid parameter annotation.
|
|
@@ -20,19 +20,18 @@ module RuboCop
|
|
|
20
20
|
# :visibility #: Symbol
|
|
21
21
|
# )
|
|
22
22
|
class MissingDataClassAnnotation < Base
|
|
23
|
+
prepend FileFilter
|
|
24
|
+
|
|
23
25
|
include MissingClassAnnotation
|
|
24
26
|
|
|
27
|
+
include DataClassMatcher
|
|
28
|
+
|
|
25
29
|
extend AutoCorrector
|
|
26
30
|
|
|
27
31
|
MSG: ::String
|
|
28
32
|
|
|
29
33
|
# @rbs node: RuboCop::AST::SendNode
|
|
30
34
|
def on_send: (RuboCop::AST::SendNode node) -> void
|
|
31
|
-
|
|
32
|
-
private
|
|
33
|
-
|
|
34
|
-
# @rbs node: RuboCop::AST::SendNode
|
|
35
|
-
def struct_like_class?: (RuboCop::AST::SendNode node) -> bool
|
|
36
35
|
end
|
|
37
36
|
end
|
|
38
37
|
end
|
|
@@ -21,24 +21,18 @@ module RuboCop
|
|
|
21
21
|
# :y #: Integer
|
|
22
22
|
# )
|
|
23
23
|
class MissingStructClassAnnotation < Base
|
|
24
|
+
prepend FileFilter
|
|
25
|
+
|
|
24
26
|
include MissingClassAnnotation
|
|
25
27
|
|
|
28
|
+
include StructClassMatcher
|
|
29
|
+
|
|
26
30
|
extend AutoCorrector
|
|
27
31
|
|
|
28
32
|
MSG: ::String
|
|
29
33
|
|
|
30
34
|
# @rbs node: RuboCop::AST::SendNode
|
|
31
35
|
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
36
|
end
|
|
43
37
|
end
|
|
44
38
|
end
|
|
@@ -20,7 +20,8 @@ module RuboCop
|
|
|
20
20
|
# - `all`: Checks all methods regardless of visibility (default)
|
|
21
21
|
# - `public`: Only checks public methods and `attr_*` declarations
|
|
22
22
|
#
|
|
23
|
-
# Methods annotated with `# @rbs skip`
|
|
23
|
+
# Methods annotated with `# @rbs skip` or `# @rbs override`, parameters with a leading
|
|
24
|
+
# `_`, and the `...` parameter are always excluded.
|
|
24
25
|
#
|
|
25
26
|
# @example EnforcedStyle: doc_style
|
|
26
27
|
# # bad
|
|
@@ -113,6 +114,8 @@ module RuboCop
|
|
|
113
114
|
# # good - attr with trailing type
|
|
114
115
|
# attr_reader :name #: String
|
|
115
116
|
class MissingTypeAnnotation < Base
|
|
117
|
+
prepend FileFilter
|
|
118
|
+
|
|
116
119
|
include ASTUtils
|
|
117
120
|
|
|
118
121
|
include CommentParser
|
|
@@ -227,13 +230,6 @@ module RuboCop
|
|
|
227
230
|
# @rbs node: RuboCop::AST::SendNode
|
|
228
231
|
def check_attribute_method: (RuboCop::AST::SendNode node) -> void
|
|
229
232
|
|
|
230
|
-
# Returns the last line of the method parameter list (the closing ) line, or the def line if no parens).
|
|
231
|
-
# @rbs node: RuboCop::AST::DefNode
|
|
232
|
-
def method_parameter_list_end_line: (RuboCop::AST::DefNode node) -> Integer
|
|
233
|
-
|
|
234
|
-
# @rbs node: RuboCop::AST::DefNode
|
|
235
|
-
def args_node_for: (RuboCop::AST::DefNode node) -> RuboCop::AST::Node
|
|
236
|
-
|
|
237
233
|
# @rbs node: RuboCop::AST::DefNode
|
|
238
234
|
def method_has_arguments?: (RuboCop::AST::DefNode node) -> bool
|
|
239
235
|
|