rubocop-rbs_inline 1.2.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: df9439ba1e35119fa462bf18e5fa2a95932072807697d9d9a0e6f68e85331a06
4
- data.tar.gz: c78bec5cc75c31720322a082aa87ab085077c01b010ab1c79e7033b236f54308
3
+ metadata.gz: 47291a6a8258c66f219f4fd57230b47b2c575b3f9dd03001efea0f888207d195
4
+ data.tar.gz: fdd0bdf3849a20c6cd08dfade8da7a65a2b3b6a728295885c79e868c0f465e8a
5
5
  SHA512:
6
- metadata.gz: 4bd4daa7ae11ace6793d58d78b06cb65b21fb5f3c8fb956b33b021a4b5aacdf397cff2dbf50d2ce9c888e0492764aa8280c24712c554013bb611a646a02d12bf
7
- data.tar.gz: 020fa5e9e7dff73ba78d14e12b0a9caf4490893efaa422facddbb58097e44dfcd1e2c96e50cdef3beafdc71e9e97229fc4c30e116dc3eacf476fe545a1943b40
6
+ metadata.gz: ebc94f84cd20a58a90a86dbae1dd76d4500d4d31a2c525823f243c833db301cd9f22f58b23c4c73d85e9096e1ba4c6b40e6c460396d07f47f9f633c2b440209b
7
+ data.tar.gz: d12b92ebd4cc9acc78c2ee46abf7a55d513dc82de35818ab6ec3d7b0ce6e713a2cf2308bd6f4877f8b3e96fd6ef719cb3213a29ef092047ab1589d747c7ac943
@@ -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 RBS_INLINE_KEYWORDS.include?(matched[1] || '')
36
+ next if valid_rbs_inline_comment?(matched[1])
30
37
 
31
- add_offense(invalid_location_for(comment)) unless matched[1]&.include?(':')
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module RbsInline
5
- VERSION = '1.2.1'
5
+ VERSION = '1.3.0'
6
6
  end
7
7
  end
@@ -6,7 +6,7 @@ gems:
6
6
  source:
7
7
  type: git
8
8
  name: ruby/gem_rbs_collection
9
- revision: 7651e7b92c15bd5b4bc11fd3dd455be0ea571fd0
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: 7651e7b92c15bd5b4bc11fd3dd455be0ea571fd0
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: 7651e7b92c15bd5b4bc11fd3dd455be0ea571fd0
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: 7651e7b92c15bd5b4bc11fd3dd455be0ea571fd0
57
+ revision: 27243a7d18fd7f7333b9daa35eeca2c37472586e
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: 7651e7b92c15bd5b4bc11fd3dd455be0ea571fd0
81
+ revision: 27243a7d18fd7f7333b9daa35eeca2c37472586e
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: 7651e7b92c15bd5b4bc11fd3dd455be0ea571fd0
89
+ revision: 27243a7d18fd7f7333b9daa35eeca2c37472586e
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: 7651e7b92c15bd5b4bc11fd3dd455be0ea571fd0
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: 7651e7b92c15bd5b4bc11fd3dd455be0ea571fd0
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: 7651e7b92c15bd5b4bc11fd3dd455be0ea571fd0
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,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.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takeshi KOMIYA
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-01-13 00:00:00.000000000 Z
10
+ date: 2025-02-27 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rbs-inline