rubocop-rbs_inline 1.0.0 → 1.1.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/.rubocop.yml +3 -0
- data/.vscode/settings.json +3 -1
- data/README.md +12 -13
- data/lib/rubocop/cop/style/rbs_inline/unmatched_annotations.rb +42 -16
- data/lib/rubocop/rbs_inline/version.rb +1 -1
- data/rbs_collection.lock.yaml +11 -11
- data/sig/rubocop/cop/style/rbs_inline/unmatched_annotations.rbs +13 -2
- 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: 4b33ed6ff1d6efff790de931d74d2663e0ca262a761d063114e486948828e9ca
|
4
|
+
data.tar.gz: 2d5678da5232ff06102653fc68a89ced09554eec6a048cc1f6dee322d37228e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a6c443fbc4e058be3aca4ccc5b3e25068b139095c01994bfcd8ea62b406701f44fa5b4b643d7a23902e5c4a7d754b4fb5f741f0f0706ab36bc8cd465801751e
|
7
|
+
data.tar.gz: c6fcb3f88b5685f0a20e7a0c90f723ba4dabd14a029e10585c61bea64258ec29304b53b3e7db3ed962365abacfc21860ef1e65866eacc89b28efcf3aeaae9360
|
data/.rubocop.yml
CHANGED
data/.vscode/settings.json
CHANGED
data/README.md
CHANGED
@@ -1,38 +1,37 @@
|
|
1
|
-
#
|
1
|
+
# rubocop-rbs_inline
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rubocop/rbs_inline`. To experiment with that code, run `bin/console` for an interactive prompt.
|
3
|
+
rubocop-rbs_inline is a RuboCop extension that checks for [RBS::Inline](https://github.com/soutaro/rbs-inline) annotation comments in Ruby code.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
9
|
-
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
10
|
-
|
11
7
|
Install the gem and add to the application's Gemfile by executing:
|
12
8
|
|
13
9
|
```bash
|
14
|
-
bundle add
|
10
|
+
bundle add rubocop-rbs_inline
|
15
11
|
```
|
16
12
|
|
17
13
|
If bundler is not being used to manage dependencies, install the gem by executing:
|
18
14
|
|
19
15
|
```bash
|
20
|
-
gem install
|
16
|
+
gem install rubocop-rbs_inline
|
21
17
|
```
|
22
18
|
|
23
|
-
|
19
|
+
Add the following to your `.rubocop.yml`:
|
24
20
|
|
25
|
-
|
21
|
+
```
|
22
|
+
require:
|
23
|
+
- rubocop-rbs_inline
|
24
|
+
```
|
26
25
|
|
27
26
|
## Development
|
28
27
|
|
29
28
|
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
29
|
|
31
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and
|
30
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and add Git tag named `vX.Y.Z` and push it to the GitHub. Then GitHub Actions will be release the package to [rubygems.org](https://rubygems.org).
|
32
31
|
|
33
32
|
## Contributing
|
34
33
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
34
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/tk0miya/rubocop-rbs_inline. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/tk0miya/rubocop-rbs_inline/blob/main/CODE_OF_CONDUCT.md).
|
36
35
|
|
37
36
|
## License
|
38
37
|
|
@@ -40,4 +39,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
40
39
|
|
41
40
|
## Code of Conduct
|
42
41
|
|
43
|
-
Everyone interacting in the
|
42
|
+
Everyone interacting in the rubocop-rbs_inline project's codebases and issue trackers is expected to follow the [code of conduct](https://github.com/tk0miya/rubocop-rbs_inline/blob/main/CODE_OF_CONDUCT.md).
|
@@ -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,27 +31,21 @@ 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
|
49
43
|
result.each do |comment|
|
50
44
|
comment.each_annotation do |annotation|
|
51
45
|
case annotation
|
52
|
-
when RBS::Inline::AST::Annotations::
|
53
|
-
|
54
|
-
|
46
|
+
when RBS::Inline::AST::Annotations::BlockType,
|
47
|
+
RBS::Inline::AST::Annotations::ReturnType,
|
48
|
+
RBS::Inline::AST::Annotations::VarType
|
55
49
|
add_offense_for(annotation)
|
56
50
|
end
|
57
51
|
end
|
@@ -62,9 +56,27 @@ module RuboCop
|
|
62
56
|
|
63
57
|
private
|
64
58
|
|
59
|
+
# @rbs node: Parser::AST::Node
|
60
|
+
def process(node) #: void # rubocop:disable Metrics/CyclomaticComplexity
|
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::IvarType
|
70
|
+
add_offense_for(annotation)
|
71
|
+
when RBS::Inline::AST::Annotations::VarType, RBS::Inline::AST::Annotations::BlockType
|
72
|
+
add_offense_for(annotation) unless arguments.include?(annotation_name(annotation))
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
65
77
|
# @rbs node: Parser::AST::Node
|
66
78
|
def arguments_for(node) #: Array[String] # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
67
|
-
node.children
|
79
|
+
args_for(node).children.flat_map do |argument|
|
68
80
|
name = argument.children[0]&.to_s
|
69
81
|
case argument.type
|
70
82
|
when :arg, :optarg, :kwarg, :kwoptarg
|
@@ -87,16 +99,29 @@ module RuboCop
|
|
87
99
|
else
|
88
100
|
['&', '&block']
|
89
101
|
end
|
102
|
+
else
|
103
|
+
raise
|
90
104
|
end
|
91
105
|
end
|
92
106
|
end
|
93
107
|
|
108
|
+
# @rbs node: Parser::AST::Node
|
109
|
+
def args_for(node) #: Parser::AST::Node
|
110
|
+
case node.type
|
111
|
+
when :defs
|
112
|
+
node.children[2]
|
113
|
+
else
|
114
|
+
node.children[1]
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
94
118
|
def parse_comments #: Array[RBS::Inline::AnnotationParser::ParsingResult]
|
95
119
|
parsed_result = Prism.parse(processed_source.buffer.source)
|
96
120
|
RBS::Inline::AnnotationParser.parse(parsed_result.comments)
|
97
121
|
end
|
98
122
|
|
99
123
|
# @rbs annotation: RBS::Inline::AST::Annotations::BlockType |
|
124
|
+
# RBS::Inline::AST::Annotations::IvarType |
|
100
125
|
# RBS::Inline::AST::Annotations::ReturnType |
|
101
126
|
# RBS::Inline::AST::Annotations::VarType
|
102
127
|
def annotation_name(annotation) #: String
|
@@ -111,6 +136,7 @@ module RuboCop
|
|
111
136
|
end
|
112
137
|
|
113
138
|
# @rbs annotation: RBS::Inline::AST::Annotations::BlockType |
|
139
|
+
# RBS::Inline::AST::Annotations::IvarType |
|
114
140
|
# RBS::Inline::AST::Annotations::ReturnType |
|
115
141
|
# RBS::Inline::AST::Annotations::VarType
|
116
142
|
def add_offense_for(annotation) #: void # rubocop:disable Metrics/AbcSize
|
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: ddba0c60808c22451a194c1b57504fceb4fafd23
|
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: ddba0c60808c22451a194c1b57504fceb4fafd23
|
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: ddba0c60808c22451a194c1b57504fceb4fafd23
|
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: ddba0c60808c22451a194c1b57504fceb4fafd23
|
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: ddba0c60808c22451a194c1b57504fceb4fafd23
|
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: ddba0c60808c22451a194c1b57504fceb4fafd23
|
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.6.1
|
94
94
|
source:
|
95
95
|
type: rubygems
|
96
96
|
- name: rbs-inline
|
97
|
-
version: 0.
|
97
|
+
version: 0.9.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: ddba0c60808c22451a194c1b57504fceb4fafd23
|
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: ddba0c60808c22451a194c1b57504fceb4fafd23
|
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: ddba0c60808c22451a194c1b57504fceb4fafd23
|
126
126
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
127
127
|
repo_dir: gems
|
128
128
|
- name: strscan
|
@@ -26,24 +26,35 @@ 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 |
|
48
|
+
# RBS::Inline::AST::Annotations::IvarType |
|
39
49
|
# RBS::Inline::AST::Annotations::ReturnType |
|
40
50
|
# RBS::Inline::AST::Annotations::VarType
|
41
|
-
def annotation_name: (RBS::Inline::AST::Annotations::BlockType | RBS::Inline::AST::Annotations::ReturnType | RBS::Inline::AST::Annotations::VarType annotation) -> String
|
51
|
+
def annotation_name: (RBS::Inline::AST::Annotations::BlockType | RBS::Inline::AST::Annotations::IvarType | RBS::Inline::AST::Annotations::ReturnType | RBS::Inline::AST::Annotations::VarType annotation) -> String
|
42
52
|
|
43
53
|
# @rbs annotation: RBS::Inline::AST::Annotations::BlockType |
|
54
|
+
# RBS::Inline::AST::Annotations::IvarType |
|
44
55
|
# RBS::Inline::AST::Annotations::ReturnType |
|
45
56
|
# RBS::Inline::AST::Annotations::VarType
|
46
|
-
def add_offense_for: (RBS::Inline::AST::Annotations::BlockType | RBS::Inline::AST::Annotations::ReturnType | RBS::Inline::AST::Annotations::VarType annotation) -> void
|
57
|
+
def add_offense_for: (RBS::Inline::AST::Annotations::BlockType | RBS::Inline::AST::Annotations::IvarType | RBS::Inline::AST::Annotations::ReturnType | RBS::Inline::AST::Annotations::VarType annotation) -> void
|
47
58
|
|
48
59
|
# @rbs byte_offset: Integer
|
49
60
|
def character_offset: (Integer byte_offset) -> Integer
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takeshi KOMIYA
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rbs-inline
|