rubocop-rbs_inline 1.2.0 → 1.3.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/.vscode/settings.json +7 -0
- data/Steepfile +1 -0
- data/lib/rubocop/cop/style/rbs_inline/invalid_comment.rb +29 -1
- data/lib/rubocop/cop/style/rbs_inline/parameters_separator.rb +20 -3
- data/lib/rubocop/cop/style/rbs_inline/unmatched_annotations.rb +1 -1
- data/lib/rubocop/rbs_inline/version.rb +1 -1
- data/rbs_collection.lock.yaml +12 -12
- data/sig/rubocop/cop/style/rbs_inline/invalid_comment.rbs +4 -0
- data/sig/rubocop/cop/style/rbs_inline/parameters_separator.rbs +12 -1
- metadata +3 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47291a6a8258c66f219f4fd57230b47b2c575b3f9dd03001efea0f888207d195
|
4
|
+
data.tar.gz: fdd0bdf3849a20c6cd08dfade8da7a65a2b3b6a728295885c79e868c0f465e8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebc94f84cd20a58a90a86dbae1dd76d4500d4d31a2c525823f243c833db301cd9f22f58b23c4c73d85e9096e1ba4c6b40e6c460396d07f47f9f633c2b440209b
|
7
|
+
data.tar.gz: d12b92ebd4cc9acc78c2ee46abf7a55d513dc82de35818ab6ec3d7b0ce6e713a2cf2308bd6f4877f8b3e96fd6ef719cb3213a29ef092047ab1589d747c7ac943
|
data/.vscode/settings.json
CHANGED
data/Steepfile
CHANGED
@@ -30,7 +30,8 @@ module RuboCop
|
|
30
30
|
RBS_INLINE_KEYWORDS = %w[inherits override use module-self generic skip module class].freeze #: Array[String]
|
31
31
|
|
32
32
|
def on_new_investigation #: void
|
33
|
-
processed_source.comments
|
33
|
+
comments = consume_embedded_rbs(processed_source.comments)
|
34
|
+
comments.each do |comment|
|
34
35
|
add_offense(comment) if comment.text =~ /\A#\s+#{SIGNATURE_PATTERN}/
|
35
36
|
add_offense(comment) if comment.text =~ /\A#\s+:\s*#{SIGNATURE_PATTERN}/
|
36
37
|
|
@@ -40,6 +41,33 @@ module RuboCop
|
|
40
41
|
end
|
41
42
|
end
|
42
43
|
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def consume_embedded_rbs(comments) # rubocop:disable Metrics/MethodLength
|
48
|
+
in_embedded = false
|
49
|
+
indent = 1
|
50
|
+
line = 0
|
51
|
+
comments.select do |comment|
|
52
|
+
case comment.text
|
53
|
+
when /\A#(\s+)@rbs!(\s+|\Z)/
|
54
|
+
in_embedded = true
|
55
|
+
indent = Regexp.last_match(1).to_s.size
|
56
|
+
line = comment.loc.line
|
57
|
+
false
|
58
|
+
when /\A#(\s{#{indent + 1},}.*|\s*)\Z/
|
59
|
+
if in_embedded && comment.loc.line == line + 1
|
60
|
+
line += 1
|
61
|
+
false
|
62
|
+
else
|
63
|
+
true
|
64
|
+
end
|
65
|
+
else
|
66
|
+
in_embedded = false
|
67
|
+
true
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
43
71
|
end
|
44
72
|
end
|
45
73
|
end
|
@@ -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
|
@@ -141,7 +141,7 @@ module RuboCop
|
|
141
141
|
# RBS::Inline::AST::Annotations::VarType
|
142
142
|
def add_offense_for(annotation) #: void # rubocop:disable Metrics/AbcSize
|
143
143
|
name = annotation_name(annotation)
|
144
|
-
loc = annotation.source.comments.first
|
144
|
+
loc = annotation.source.comments.first&.location or raise
|
145
145
|
source = processed_source.buffer.source.dup.force_encoding('ASCII')
|
146
146
|
text = source[loc.start_offset...loc.end_offset] or raise
|
147
147
|
comment = text.force_encoding(processed_source.buffer.source.encoding)
|
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: 27243a7d18fd7f7333b9daa35eeca2c37472586e
|
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: 27243a7d18fd7f7333b9daa35eeca2c37472586e
|
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: 27243a7d18fd7f7333b9daa35eeca2c37472586e
|
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: 27243a7d18fd7f7333b9daa35eeca2c37472586e
|
58
58
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
59
59
|
repo_dir: gems
|
60
60
|
- name: pathname
|
@@ -62,7 +62,7 @@ gems:
|
|
62
62
|
source:
|
63
63
|
type: stdlib
|
64
64
|
- name: prism
|
65
|
-
version: 1.
|
65
|
+
version: 1.2.0
|
66
66
|
source:
|
67
67
|
type: rubygems
|
68
68
|
- name: pstore
|
@@ -78,7 +78,7 @@ gems:
|
|
78
78
|
source:
|
79
79
|
type: git
|
80
80
|
name: ruby/gem_rbs_collection
|
81
|
-
revision:
|
81
|
+
revision: 27243a7d18fd7f7333b9daa35eeca2c37472586e
|
82
82
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
83
83
|
repo_dir: gems
|
84
84
|
- name: rake
|
@@ -86,15 +86,15 @@ gems:
|
|
86
86
|
source:
|
87
87
|
type: git
|
88
88
|
name: ruby/gem_rbs_collection
|
89
|
-
revision:
|
89
|
+
revision: 27243a7d18fd7f7333b9daa35eeca2c37472586e
|
90
90
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
91
91
|
repo_dir: gems
|
92
92
|
- name: rbs
|
93
|
-
version: 3.
|
93
|
+
version: 3.8.1
|
94
94
|
source:
|
95
95
|
type: rubygems
|
96
96
|
- name: rbs-inline
|
97
|
-
version: 0.
|
97
|
+
version: 0.10.0
|
98
98
|
source:
|
99
99
|
type: rubygems
|
100
100
|
- name: rdoc
|
@@ -106,7 +106,7 @@ gems:
|
|
106
106
|
source:
|
107
107
|
type: git
|
108
108
|
name: ruby/gem_rbs_collection
|
109
|
-
revision:
|
109
|
+
revision: 27243a7d18fd7f7333b9daa35eeca2c37472586e
|
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: 27243a7d18fd7f7333b9daa35eeca2c37472586e
|
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: 27243a7d18fd7f7333b9daa35eeca2c37472586e
|
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,14 +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.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takeshi KOMIYA
|
8
|
-
autorequire:
|
9
8
|
bindir: exe
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-02-27 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: rbs-inline
|
@@ -87,7 +86,6 @@ metadata:
|
|
87
86
|
source_code_uri: https://github.com/tk0miya/rubocop-rbs_inline
|
88
87
|
changelog_uri: https://github.com/tk0miya/rubocop-rbs_inline
|
89
88
|
rubygems_mfa_required: 'true'
|
90
|
-
post_install_message:
|
91
89
|
rdoc_options: []
|
92
90
|
require_paths:
|
93
91
|
- lib
|
@@ -102,8 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
100
|
- !ruby/object:Gem::Version
|
103
101
|
version: '0'
|
104
102
|
requirements: []
|
105
|
-
rubygems_version: 3.
|
106
|
-
signing_key:
|
103
|
+
rubygems_version: 3.6.2
|
107
104
|
specification_version: 4
|
108
105
|
summary: rubocop extension to check RBS annotation comments
|
109
106
|
test_files: []
|