rubocop-rbs_inline 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 330ffc2d84cf5c15d64d2922c93eb97017e4dd585cf52dea2e05ac2ec2ed60ab
|
4
|
+
data.tar.gz: 7c550b9d63d636cd52d8ddf285e1dd9220b2764425ef59784685777c38f82963
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1365b8c968cbd7341a8f685cdadc7334ac9d53ba78662af77522097df9440b8092821ef30c3445992809f71aedad50d45764a9a1a0e0baf54133d9cf029bc87b
|
7
|
+
data.tar.gz: abc24e1e6df83cb0c24ddac363ed1e7b7b623cd9d528c59cc9869715ecf7cb01430f25b3681b8f64d22ebd8c3b94ab2595cfe7710bad6be70897a2676aeea783
|
data/.rubocop.yml
CHANGED
@@ -17,7 +17,7 @@ module RuboCop
|
|
17
17
|
# # @rbs arg: String
|
18
18
|
# def method(arg); end
|
19
19
|
#
|
20
|
-
class UnmatchedAnnotations < Base
|
20
|
+
class UnmatchedAnnotations < Base # rubocop:disable Metrics/ClassLength
|
21
21
|
include RangeHelp
|
22
22
|
|
23
23
|
MSG = 'target parameter not found.'
|
@@ -31,18 +31,12 @@ module RuboCop
|
|
31
31
|
|
32
32
|
# @rbs node: Parser::AST::Node
|
33
33
|
def on_def(node) #: void
|
34
|
-
|
35
|
-
|
36
|
-
comment = result.find { |r| r.comments.map(&:location).map(&:start_line).include? node.location.line - 1 }
|
37
|
-
return unless comment
|
34
|
+
process(node)
|
35
|
+
end
|
38
36
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
when RBS::Inline::AST::Annotations::VarType, RBS::Inline::AST::Annotations::BlockType
|
43
|
-
add_offense_for(annotation) unless arguments.include?(annotation_name(annotation))
|
44
|
-
end
|
45
|
-
end
|
37
|
+
# @rbs node: Parser::AST::Node
|
38
|
+
def on_defs(node) #: void
|
39
|
+
process(node)
|
46
40
|
end
|
47
41
|
|
48
42
|
def on_investigation_end #: void
|
@@ -62,9 +56,25 @@ module RuboCop
|
|
62
56
|
|
63
57
|
private
|
64
58
|
|
59
|
+
# @rbs node: Parser::AST::Node
|
60
|
+
def process(node) #: void
|
61
|
+
arguments = arguments_for(node)
|
62
|
+
|
63
|
+
comment = result.find { |r| r.comments.map(&:location).map(&:start_line).include? node.location.line - 1 }
|
64
|
+
return unless comment
|
65
|
+
|
66
|
+
result.delete(comment)
|
67
|
+
comment.each_annotation do |annotation|
|
68
|
+
case annotation
|
69
|
+
when RBS::Inline::AST::Annotations::VarType, RBS::Inline::AST::Annotations::BlockType
|
70
|
+
add_offense_for(annotation) unless arguments.include?(annotation_name(annotation))
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
65
75
|
# @rbs node: Parser::AST::Node
|
66
76
|
def arguments_for(node) #: Array[String] # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
67
|
-
node.children
|
77
|
+
args_for(node).children.flat_map do |argument|
|
68
78
|
name = argument.children[0]&.to_s
|
69
79
|
case argument.type
|
70
80
|
when :arg, :optarg, :kwarg, :kwoptarg
|
@@ -87,10 +97,22 @@ module RuboCop
|
|
87
97
|
else
|
88
98
|
['&', '&block']
|
89
99
|
end
|
100
|
+
else
|
101
|
+
raise
|
90
102
|
end
|
91
103
|
end
|
92
104
|
end
|
93
105
|
|
106
|
+
# @rbs node: Parser::AST::Node
|
107
|
+
def args_for(node) #: Parser::AST::Node
|
108
|
+
case node.type
|
109
|
+
when :defs
|
110
|
+
node.children[2]
|
111
|
+
else
|
112
|
+
node.children[1]
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
94
116
|
def parse_comments #: Array[RBS::Inline::AnnotationParser::ParsingResult]
|
95
117
|
parsed_result = Prism.parse(processed_source.buffer.source)
|
96
118
|
RBS::Inline::AnnotationParser.parse(parsed_result.comments)
|
@@ -26,13 +26,22 @@ module RuboCop
|
|
26
26
|
# @rbs node: Parser::AST::Node
|
27
27
|
def on_def: (Parser::AST::Node node) -> void
|
28
28
|
|
29
|
+
# @rbs node: Parser::AST::Node
|
30
|
+
def on_defs: (Parser::AST::Node node) -> void
|
31
|
+
|
29
32
|
def on_investigation_end: () -> void
|
30
33
|
|
31
34
|
private
|
32
35
|
|
36
|
+
# @rbs node: Parser::AST::Node
|
37
|
+
def process: (Parser::AST::Node node) -> void
|
38
|
+
|
33
39
|
# @rbs node: Parser::AST::Node
|
34
40
|
def arguments_for: (Parser::AST::Node node) -> Array[String]
|
35
41
|
|
42
|
+
# @rbs node: Parser::AST::Node
|
43
|
+
def args_for: (Parser::AST::Node node) -> Parser::AST::Node
|
44
|
+
|
36
45
|
def parse_comments: () -> Array[RBS::Inline::AnnotationParser::ParsingResult]
|
37
46
|
|
38
47
|
# @rbs annotation: RBS::Inline::AST::Annotations::BlockType |
|