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: 2cb89181193fb2e2b975ef100f2948fb1f89dc6dea644646855cc03a7950baf6
4
- data.tar.gz: 133e570879c25b31253a51dea5915a9ea12c13727c761d78ec3e32556632eb88
3
+ metadata.gz: 330ffc2d84cf5c15d64d2922c93eb97017e4dd585cf52dea2e05ac2ec2ed60ab
4
+ data.tar.gz: 7c550b9d63d636cd52d8ddf285e1dd9220b2764425ef59784685777c38f82963
5
5
  SHA512:
6
- metadata.gz: 56462bcc98368caba914397e84a540b06589050c8f5c442755f16558c158decd34705ba3aa236831976b70f2dc284cb49fb412f98beb3dafa5621bc3ec3f12a2
7
- data.tar.gz: d555d249fb26f8e62979978e1737d9cf72511a60a25a843e8e427750f194f9955d5bdfb920f0ad56caf052a3dc9e72c9bb9f1a8ae352af07f9be6e8230b48139
6
+ metadata.gz: 1365b8c968cbd7341a8f685cdadc7334ac9d53ba78662af77522097df9440b8092821ef30c3445992809f71aedad50d45764a9a1a0e0baf54133d9cf029bc87b
7
+ data.tar.gz: abc24e1e6df83cb0c24ddac363ed1e7b7b623cd9d528c59cc9869715ecf7cb01430f25b3681b8f64d22ebd8c3b94ab2595cfe7710bad6be70897a2676aeea783
data/.rubocop.yml CHANGED
@@ -23,6 +23,9 @@ Naming/FileName:
23
23
  RSpec/ExampleLength:
24
24
  Max: 20
25
25
 
26
+ RSpec/NestedGroups:
27
+ Max: 5
28
+
26
29
  Style/Documentation:
27
30
  Enabled: false
28
31
 
@@ -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
- arguments = arguments_for(node)
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
- result.delete(comment)
40
- comment.each_annotation do |annotation|
41
- case annotation
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[1].children.flat_map do |argument|
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)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module RbsInline
5
- VERSION = '1.0.0'
5
+ VERSION = '1.1.0'
6
6
  end
7
7
  end
@@ -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 |
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-rbs_inline
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takeshi KOMIYA