rubocop-rbs_inline 1.2.1 → 1.3.1
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/lib/rubocop/cop/style/rbs_inline/parameters_separator.rb +20 -3
- data/lib/rubocop/cop/style/rbs_inline/unmatched_annotations.rb +3 -1
- data/lib/rubocop/rbs_inline/version.rb +1 -1
- data/rbs_collection.lock.yaml +9 -9
- data/sig/rubocop/cop/style/rbs_inline/parameters_separator.rbs +12 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70dff765f202de632ab9ce95a88018c63308179e9db1745a36019fbd9ef9bc1d
|
4
|
+
data.tar.gz: f8e7aa443700c588433356685931eb7129f9587bfe7b46e1cfbf2da32a49c911
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16ec889e5c2525f8d8d0fad9f4e2a18363ece050d4e1000ee2509bb2c7336dfabb6a0ee4956606fcb06e95be7f7a27ecbcefa9b7d868fd80f77b9b0445f3a909
|
7
|
+
data.tar.gz: 44f8189b13d1887d8ef055b7038b2d15952d9055fa6b7d0c6c0246a62401acf88ad0a584392ea2d29b839e8ab6f708b0e5f379c7690624c5a6e3b2a40b5a9494
|
@@ -4,16 +4,21 @@ module RuboCop
|
|
4
4
|
module Cop
|
5
5
|
module Style
|
6
6
|
module RbsInline
|
7
|
-
# IRB::Inline expects annotations comments for parameters are separeted with
|
7
|
+
# IRB::Inline expects annotations comments for parameters are separeted with `:`or allows annotation comments.
|
8
8
|
# This cop checks for comments that do not match the expected pattern.
|
9
9
|
#
|
10
10
|
# @example
|
11
11
|
# # bad
|
12
12
|
# # @rbs param String
|
13
13
|
#
|
14
|
+
# # bad
|
15
|
+
# # @rbs :param String
|
16
|
+
#
|
14
17
|
# # good
|
15
18
|
# # @rbs param: String
|
16
19
|
#
|
20
|
+
# # good
|
21
|
+
# # @rbs %a{pure}
|
17
22
|
class ParametersSeparator < Base
|
18
23
|
include RangeHelp
|
19
24
|
|
@@ -21,19 +26,31 @@ module RuboCop
|
|
21
26
|
|
22
27
|
# refs: https://github.com/soutaro/rbs-inline/blob/main/lib/rbs/inline/annotation_parser/tokenizer.rb
|
23
28
|
RBS_INLINE_KEYWORDS = %w[inherits override use module-self generic skip module class].freeze #: Array[String]
|
29
|
+
RBS_INLINE_REGEXP_KEYWORDS = [/%a{(\w|-)+}/, /%a\((\w|-)+\)/, /%a\[(\w|-)+\]/].freeze #: Array[Regexp]
|
24
30
|
|
25
31
|
def on_new_investigation #: void
|
26
32
|
processed_source.comments.each do |comment|
|
27
33
|
matched = comment.text.match(/\A#\s+@rbs\s+(\S+)/)
|
34
|
+
|
28
35
|
next unless matched
|
29
|
-
next if
|
36
|
+
next if valid_rbs_inline_comment?(matched[1])
|
30
37
|
|
31
|
-
add_offense(invalid_location_for(comment))
|
38
|
+
add_offense(invalid_location_for(comment))
|
32
39
|
end
|
33
40
|
end
|
34
41
|
|
35
42
|
private
|
36
43
|
|
44
|
+
# @rbs matched: String?
|
45
|
+
def valid_rbs_inline_comment?(matched) #: bool
|
46
|
+
return true if matched.nil?
|
47
|
+
return true if RBS_INLINE_KEYWORDS.include?(matched)
|
48
|
+
return true if RBS_INLINE_REGEXP_KEYWORDS.any? { |regexp| matched =~ regexp }
|
49
|
+
return true if matched.end_with?(':')
|
50
|
+
|
51
|
+
false
|
52
|
+
end
|
53
|
+
|
37
54
|
# @rbs comment: Parser::Source::Comment
|
38
55
|
def invalid_location_for(comment) #: Parser::Source::Range
|
39
56
|
range = comment.source_range
|
@@ -76,7 +76,7 @@ module RuboCop
|
|
76
76
|
|
77
77
|
# @rbs node: Parser::AST::Node
|
78
78
|
def arguments_for(node) #: Array[String] # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
79
|
-
args_for(node).children.flat_map do |argument|
|
79
|
+
args_for(node).children.flat_map do |argument| # rubocop:disable Metrics/BlockLength
|
80
80
|
name = argument.children[0]&.to_s
|
81
81
|
case argument.type
|
82
82
|
when :arg, :optarg, :kwarg, :kwoptarg
|
@@ -99,6 +99,8 @@ module RuboCop
|
|
99
99
|
else
|
100
100
|
['&', '&block']
|
101
101
|
end
|
102
|
+
when :forward_arg
|
103
|
+
['...']
|
102
104
|
else
|
103
105
|
raise
|
104
106
|
end
|
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: 95d9b83e2727af43d6dea2ffb9e9d2d350425fe9
|
10
10
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
11
11
|
repo_dir: gems
|
12
12
|
- name: dbm
|
@@ -18,7 +18,7 @@ gems:
|
|
18
18
|
source:
|
19
19
|
type: git
|
20
20
|
name: ruby/gem_rbs_collection
|
21
|
-
revision:
|
21
|
+
revision: 95d9b83e2727af43d6dea2ffb9e9d2d350425fe9
|
22
22
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
23
23
|
repo_dir: gems
|
24
24
|
- name: fileutils
|
@@ -46,7 +46,7 @@ gems:
|
|
46
46
|
source:
|
47
47
|
type: git
|
48
48
|
name: ruby/gem_rbs_collection
|
49
|
-
revision:
|
49
|
+
revision: 95d9b83e2727af43d6dea2ffb9e9d2d350425fe9
|
50
50
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
51
51
|
repo_dir: gems
|
52
52
|
- name: parser
|
@@ -54,7 +54,7 @@ gems:
|
|
54
54
|
source:
|
55
55
|
type: git
|
56
56
|
name: ruby/gem_rbs_collection
|
57
|
-
revision:
|
57
|
+
revision: 95d9b83e2727af43d6dea2ffb9e9d2d350425fe9
|
58
58
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
59
59
|
repo_dir: gems
|
60
60
|
- name: pathname
|
@@ -78,7 +78,7 @@ gems:
|
|
78
78
|
source:
|
79
79
|
type: git
|
80
80
|
name: ruby/gem_rbs_collection
|
81
|
-
revision:
|
81
|
+
revision: 95d9b83e2727af43d6dea2ffb9e9d2d350425fe9
|
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: 95d9b83e2727af43d6dea2ffb9e9d2d350425fe9
|
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: 95d9b83e2727af43d6dea2ffb9e9d2d350425fe9
|
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: 95d9b83e2727af43d6dea2ffb9e9d2d350425fe9
|
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: 95d9b83e2727af43d6dea2ffb9e9d2d350425fe9
|
126
126
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
127
127
|
repo_dir: gems
|
128
128
|
- name: strscan
|
@@ -4,15 +4,21 @@ module RuboCop
|
|
4
4
|
module Cop
|
5
5
|
module Style
|
6
6
|
module RbsInline
|
7
|
-
# IRB::Inline expects annotations comments for parameters are separeted with
|
7
|
+
# IRB::Inline expects annotations comments for parameters are separeted with `:`or allows annotation comments.
|
8
8
|
# This cop checks for comments that do not match the expected pattern.
|
9
9
|
#
|
10
10
|
# @example
|
11
11
|
# # bad
|
12
12
|
# # @rbs param String
|
13
13
|
#
|
14
|
+
# # bad
|
15
|
+
# # @rbs :param String
|
16
|
+
#
|
14
17
|
# # good
|
15
18
|
# # @rbs param: String
|
19
|
+
#
|
20
|
+
# # good
|
21
|
+
# # @rbs %a{pure}
|
16
22
|
class ParametersSeparator < Base
|
17
23
|
include RangeHelp
|
18
24
|
|
@@ -21,10 +27,15 @@ module RuboCop
|
|
21
27
|
# refs: https://github.com/soutaro/rbs-inline/blob/main/lib/rbs/inline/annotation_parser/tokenizer.rb
|
22
28
|
RBS_INLINE_KEYWORDS: Array[String]
|
23
29
|
|
30
|
+
RBS_INLINE_REGEXP_KEYWORDS: Array[Regexp]
|
31
|
+
|
24
32
|
def on_new_investigation: () -> void
|
25
33
|
|
26
34
|
private
|
27
35
|
|
36
|
+
# @rbs matched: String?
|
37
|
+
def valid_rbs_inline_comment?: (String? matched) -> bool
|
38
|
+
|
28
39
|
# @rbs comment: Parser::Source::Comment
|
29
40
|
def invalid_location_for: (Parser::Source::Comment comment) -> Parser::Source::Range
|
30
41
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-rbs_inline
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takeshi KOMIYA
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-03-04 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: rbs-inline
|