rubocop-rbs_inline 1.7.0 → 1.8.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/self-review.sh +89 -0
- data/.claude/settings.json +8 -0
- data/.rubocop.yml +9 -3
- data/CHANGELOG.md +19 -0
- data/CLAUDE.md +9 -14
- data/README.md +54 -6
- data/config/default.yml +3 -4
- data/lib/rubocop/cop/rbs_inline_cops.rb +15 -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 +3 -9
- 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/{ast_utils.rb → mixin/ast_utils.rb} +16 -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 +110 -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 +74 -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 +3 -9
- 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/sig/gems/rubocop/rubocop.rbs +8 -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 +4 -5
- 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} +9 -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 +63 -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/{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 +30 -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 +4 -5
- 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 +24 -17
- 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/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
|
@@ -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
|
|
@@ -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,15 +27,14 @@ module RuboCop
|
|
|
27
27
|
# def admin? = role == :admin #: bool
|
|
28
28
|
# end
|
|
29
29
|
class DataDefineWithBlock < Base
|
|
30
|
-
|
|
30
|
+
prepend FileFilter
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
def on_send: (RuboCop::AST::SendNode node) -> void
|
|
32
|
+
include DataClassMatcher
|
|
34
33
|
|
|
35
|
-
|
|
34
|
+
MSG: ::String
|
|
36
35
|
|
|
37
36
|
# @rbs node: RuboCop::AST::SendNode
|
|
38
|
-
def
|
|
37
|
+
def on_send: (RuboCop::AST::SendNode node) -> void
|
|
39
38
|
end
|
|
40
39
|
end
|
|
41
40
|
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
|
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Generated from lib/rubocop/cop/style/rbs_inline/mixin/annotation_keywords.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module RuboCop
|
|
4
|
+
module Cop
|
|
5
|
+
module Style
|
|
6
|
+
module RbsInline
|
|
7
|
+
# Provides the list of keywords that may follow `# @rbs` in an annotation comment.
|
|
8
|
+
#
|
|
9
|
+
# refs: https://github.com/soutaro/rbs-inline/blob/main/lib/rbs/inline/annotation_parser/tokenizer.rb
|
|
10
|
+
module AnnotationKeywords
|
|
11
|
+
RBS_INLINE_KEYWORDS: Array[String]
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Generated from lib/rubocop/cop/style/rbs_inline/ast_utils.rb with RBS::Inline
|
|
1
|
+
# Generated from lib/rubocop/cop/style/rbs_inline/mixin/ast_utils.rb with RBS::Inline
|
|
2
2
|
|
|
3
3
|
module RuboCop
|
|
4
4
|
module Cop
|
|
@@ -9,6 +9,14 @@ module RuboCop
|
|
|
9
9
|
# @rbs default: Integer
|
|
10
10
|
def end_line: (RuboCop::AST::Node node, default: Integer) -> Integer
|
|
11
11
|
|
|
12
|
+
# Returns the arguments node of a method definition.
|
|
13
|
+
# @rbs node: RuboCop::AST::DefNode
|
|
14
|
+
def args_node_for: (RuboCop::AST::DefNode node) -> RuboCop::AST::Node
|
|
15
|
+
|
|
16
|
+
# Returns the last line of the method parameter list (the closing ) line, or the def line if no parens).
|
|
17
|
+
# @rbs node: RuboCop::AST::DefNode
|
|
18
|
+
def method_parameter_list_end_line: (RuboCop::AST::DefNode node) -> Integer
|
|
19
|
+
|
|
12
20
|
# @rbs node: RuboCop::AST::Node
|
|
13
21
|
def name_location: (RuboCop::AST::Node node) -> untyped
|
|
14
22
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Generated from lib/rubocop/cop/style/rbs_inline/comment_parser.rb with RBS::Inline
|
|
1
|
+
# Generated from lib/rubocop/cop/style/rbs_inline/mixin/comment_parser.rb with RBS::Inline
|
|
2
2
|
|
|
3
3
|
module RuboCop
|
|
4
4
|
module Cop
|
|
@@ -9,6 +9,10 @@ module RuboCop
|
|
|
9
9
|
module CommentParser : RuboCop::Cop::Base
|
|
10
10
|
attr_reader parsed_comments: Array[RBS::Inline::AnnotationParser::ParsingResult]
|
|
11
11
|
|
|
12
|
+
# Fallback for cops that include CommentParser without prepending FileFilter;
|
|
13
|
+
# `FileFilter` overrides this to return the real per-file decision.
|
|
14
|
+
def rbs_inline_file_skipped?: () -> bool
|
|
15
|
+
|
|
12
16
|
# Parse comments from the source code
|
|
13
17
|
def parse_comments: () -> Array[RBS::Inline::AnnotationParser::ParsingResult]
|
|
14
18
|
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Generated from lib/rubocop/cop/style/rbs_inline/mixin/data_class_matcher.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module RuboCop
|
|
4
|
+
module Cop
|
|
5
|
+
module Style
|
|
6
|
+
module RbsInline
|
|
7
|
+
# Matcher for `Data.define` calls, shared by the cops that check
|
|
8
|
+
# `Data.define` class definitions.
|
|
9
|
+
module DataClassMatcher
|
|
10
|
+
private
|
|
11
|
+
|
|
12
|
+
# @rbs node: RuboCop::AST::SendNode
|
|
13
|
+
def struct_like_class?: (RuboCop::AST::SendNode node) -> bool
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
data/sig/rubocop/cop/style/rbs_inline/{data_struct_helper.rbs → mixin/data_struct_helper.rbs}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Generated from lib/rubocop/cop/style/rbs_inline/data_struct_helper.rb with RBS::Inline
|
|
1
|
+
# Generated from lib/rubocop/cop/style/rbs_inline/mixin/data_struct_helper.rb with RBS::Inline
|
|
2
2
|
|
|
3
3
|
module RuboCop
|
|
4
4
|
module Cop
|
|
@@ -40,9 +40,14 @@ module RuboCop
|
|
|
40
40
|
# @rbs line: Integer
|
|
41
41
|
def find_regular_comment: (Integer line) -> Parser::Source::Comment?
|
|
42
42
|
|
|
43
|
+
# The column is determined by the attribute arguments only; non-attribute
|
|
44
|
+
# arguments (e.g. the `Struct.new` name or a `keyword_init:` keyword argument)
|
|
45
|
+
# never carry an annotation and so must not influence the alignment.
|
|
43
46
|
# @rbs node: RuboCop::AST::SendNode
|
|
44
47
|
def annotation_column: (RuboCop::AST::SendNode node) -> Integer
|
|
45
48
|
|
|
49
|
+
# Only attribute arguments are considered, for the same reason as
|
|
50
|
+
# {#annotation_column}.
|
|
46
51
|
# @rbs node: RuboCop::AST::SendNode
|
|
47
52
|
def longest_argname: (RuboCop::AST::SendNode node) -> String
|
|
48
53
|
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Generated from lib/rubocop/cop/style/rbs_inline/mixin/file_filter.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module RuboCop
|
|
4
|
+
module Cop
|
|
5
|
+
module Style
|
|
6
|
+
module RbsInline
|
|
7
|
+
# Filters files a cop reports offenses on, based on `Mode` configuration.
|
|
8
|
+
#
|
|
9
|
+
# When `Mode` is `opt_in`, offenses are only reported for files that contain
|
|
10
|
+
# a `# rbs_inline: enabled` magic comment. When `Mode` is `opt_out`, all files
|
|
11
|
+
# are checked unless they contain `# rbs_inline: disabled`. When `Mode` is not
|
|
12
|
+
# set, all files are checked (legacy behavior).
|
|
13
|
+
#
|
|
14
|
+
# This module is designed to be `prepend`ed to a cop so that it can short-circuit
|
|
15
|
+
# the cop's heavy work (annotation parsing via `parse_comments`) and suppress any
|
|
16
|
+
# residual offense reporting for files that should be skipped.
|
|
17
|
+
#
|
|
18
|
+
# @rbs module-self RuboCop::Cop::Base
|
|
19
|
+
module FileFilter : RuboCop::Cop::Base
|
|
20
|
+
type mode = :opt_in | :opt_out
|
|
21
|
+
|
|
22
|
+
MAGIC_COMMENT_ENABLED: Regexp
|
|
23
|
+
|
|
24
|
+
MAGIC_COMMENT_DISABLED: Regexp
|
|
25
|
+
|
|
26
|
+
SUPPORTED_MODES: Array[mode]
|
|
27
|
+
|
|
28
|
+
self.@warned_invalid_modes: Hash[String, bool]
|
|
29
|
+
|
|
30
|
+
# @rbs raw: untyped
|
|
31
|
+
def self.warn_invalid_mode: (untyped raw) -> void
|
|
32
|
+
|
|
33
|
+
@rbs_inline_skip_file: bool
|
|
34
|
+
|
|
35
|
+
def on_new_investigation: () -> void
|
|
36
|
+
|
|
37
|
+
# @rbs *args: untyped
|
|
38
|
+
# @rbs **kwargs: untyped
|
|
39
|
+
def add_offense: (*untyped args, **untyped kwargs) ?{ (?) -> untyped } -> void
|
|
40
|
+
|
|
41
|
+
# Exposes the FileFilter's per-file skip decision as a proper method so
|
|
42
|
+
# helper modules (e.g. `CommentParser`) can consult it explicitly instead
|
|
43
|
+
# of poking at `@rbs_inline_skip_file` directly.
|
|
44
|
+
def rbs_inline_file_skipped?: () -> bool
|
|
45
|
+
|
|
46
|
+
private
|
|
47
|
+
|
|
48
|
+
def skip_by_mode?: () -> bool
|
|
49
|
+
|
|
50
|
+
def configured_mode: () -> mode?
|
|
51
|
+
|
|
52
|
+
# Iterate the already-materialized `processed_source.comments` so this
|
|
53
|
+
# matches RequireRbsInlineComment's detection exactly (line endings,
|
|
54
|
+
# indented comments, heredoc/string content are all handled correctly
|
|
55
|
+
# by the parser).
|
|
56
|
+
def rbs_inline_enabled?: () -> bool
|
|
57
|
+
|
|
58
|
+
def rbs_inline_disabled?: () -> bool
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Generated from lib/rubocop/cop/style/rbs_inline/mixin/struct_class_matcher.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module RuboCop
|
|
4
|
+
module Cop
|
|
5
|
+
module Style
|
|
6
|
+
module RbsInline
|
|
7
|
+
# Matcher for `Struct.new` calls, shared by the cops that check `Struct.new`
|
|
8
|
+
# class definitions.
|
|
9
|
+
#
|
|
10
|
+
# Also overrides {DataStructHelper#attr_argument?} for `Struct.new` semantics,
|
|
11
|
+
# so cops that include both must include this module last.
|
|
12
|
+
module StructClassMatcher
|
|
13
|
+
private
|
|
14
|
+
|
|
15
|
+
# @rbs node: RuboCop::AST::SendNode
|
|
16
|
+
def struct_like_class?: (RuboCop::AST::SendNode node) -> bool
|
|
17
|
+
|
|
18
|
+
# `Struct.new` treats a leading string argument as the struct name, so only
|
|
19
|
+
# symbol arguments are attributes.
|
|
20
|
+
# @rbs arg: RuboCop::AST::Node
|
|
21
|
+
def attr_argument?: (RuboCop::AST::Node arg) -> bool
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -20,15 +20,16 @@ module RuboCop
|
|
|
20
20
|
# # good
|
|
21
21
|
# # @rbs %a{pure}
|
|
22
22
|
class ParametersSeparator < Base
|
|
23
|
+
prepend FileFilter
|
|
24
|
+
|
|
23
25
|
extend AutoCorrector
|
|
24
26
|
|
|
27
|
+
include AnnotationKeywords
|
|
28
|
+
|
|
25
29
|
include RangeHelp
|
|
26
30
|
|
|
27
31
|
MSG: ::String
|
|
28
32
|
|
|
29
|
-
# refs: https://github.com/soutaro/rbs-inline/blob/main/lib/rbs/inline/annotation_parser/tokenizer.rb
|
|
30
|
-
RBS_INLINE_KEYWORDS: Array[String]
|
|
31
|
-
|
|
32
33
|
RBS_INLINE_REGEXP_KEYWORDS: Array[Regexp]
|
|
33
34
|
|
|
34
35
|
def on_new_investigation: () -> void
|
|
@@ -55,8 +55,12 @@ module RuboCop
|
|
|
55
55
|
# def method(a)
|
|
56
56
|
# end
|
|
57
57
|
class RedundantAnnotationWithSkip < Base
|
|
58
|
+
prepend FileFilter
|
|
59
|
+
|
|
58
60
|
extend AutoCorrector
|
|
59
61
|
|
|
62
|
+
include ASTUtils
|
|
63
|
+
|
|
60
64
|
include CommentParser
|
|
61
65
|
|
|
62
66
|
include RangeHelp
|
|
@@ -105,10 +109,6 @@ module RuboCop
|
|
|
105
109
|
|
|
106
110
|
# @rbs param_list_end_line: Integer
|
|
107
111
|
def check_trailing_return: (Integer param_list_end_line) -> void
|
|
108
|
-
|
|
109
|
-
# Returns the last line of the method parameter list (the closing ) line, or the def line if no parens).
|
|
110
|
-
# @rbs node: RuboCop::AST::DefNode
|
|
111
|
-
def method_parameter_list_end_line: (RuboCop::AST::DefNode node) -> Integer
|
|
112
112
|
end
|
|
113
113
|
end
|
|
114
114
|
end
|
|
@@ -77,8 +77,12 @@ module RuboCop
|
|
|
77
77
|
# def method(a) #: String
|
|
78
78
|
# end
|
|
79
79
|
class RedundantTypeAnnotation < Base
|
|
80
|
+
prepend FileFilter
|
|
81
|
+
|
|
80
82
|
extend AutoCorrector
|
|
81
83
|
|
|
84
|
+
include ASTUtils
|
|
85
|
+
|
|
82
86
|
include CommentParser
|
|
83
87
|
|
|
84
88
|
include ConfigurableEnforcedStyle
|
|
@@ -110,10 +114,6 @@ module RuboCop
|
|
|
110
114
|
# @rbs def_line: Integer
|
|
111
115
|
def check_parameter_redundancy: (Integer def_line) -> void
|
|
112
116
|
|
|
113
|
-
# Returns the last line of the method parameter list (the closing ) line, or the def line if no parens).
|
|
114
|
-
# @rbs node: RuboCop::AST::DefNode
|
|
115
|
-
def method_parameter_list_end_line: (RuboCop::AST::DefNode node) -> Integer
|
|
116
|
-
|
|
117
117
|
# @rbs def_line: Integer
|
|
118
118
|
# @rbs parameter_list_end_line: Integer
|
|
119
119
|
def check_return_type_redundancy: (Integer def_line, Integer parameter_list_end_line) -> void
|
|
@@ -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
|
|
@@ -50,6 +60,12 @@ module RuboCop
|
|
|
50
60
|
|
|
51
61
|
MSG_FORBIDDEN: ::String
|
|
52
62
|
|
|
63
|
+
self.@enforced_style_deprecation_warned: bool
|
|
64
|
+
|
|
65
|
+
def self.enforced_style_deprecation_warned?: () -> bool
|
|
66
|
+
|
|
67
|
+
def self.mark_enforced_style_deprecation_warned!: () -> void
|
|
68
|
+
|
|
53
69
|
def on_new_investigation: () -> void
|
|
54
70
|
|
|
55
71
|
private
|
|
@@ -60,16 +76,25 @@ module RuboCop
|
|
|
60
76
|
def disabled?: (Parser::Source::Comment? magic_comment) -> bool
|
|
61
77
|
|
|
62
78
|
# @rbs magic_comment: Parser::Source::Comment?
|
|
63
|
-
def
|
|
79
|
+
def check_opt_in: (Parser::Source::Comment? magic_comment) -> void
|
|
64
80
|
|
|
65
81
|
# @rbs magic_comment: Parser::Source::Comment?
|
|
66
|
-
def
|
|
82
|
+
def check_opt_out: (Parser::Source::Comment? magic_comment) -> void
|
|
67
83
|
|
|
68
84
|
def find_insert_position: () -> Integer
|
|
69
85
|
|
|
86
|
+
# The insert position lands at the end of the buffer when the file has no trailing
|
|
87
|
+
# newline. The magic comment then needs its own newline to stay on a separate line.
|
|
88
|
+
# @rbs insert_position: Integer
|
|
89
|
+
def insertion_text: (Integer insert_position) -> String
|
|
90
|
+
|
|
70
91
|
def find_last_comment_in_first_block: () -> Parser::Source::Comment
|
|
71
92
|
|
|
72
|
-
def
|
|
93
|
+
def effective_mode: () -> FileFilter::mode
|
|
94
|
+
|
|
95
|
+
def allow_missing_comment?: () -> bool
|
|
96
|
+
|
|
97
|
+
def warn_deprecated_enforced_style: () -> void
|
|
73
98
|
|
|
74
99
|
def first_line_range: () -> Parser::Source::Range
|
|
75
100
|
end
|