rubocop-yard 0.1.0 → 0.2.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/CHANGELOG.md +5 -0
- data/README.md +16 -6
- data/lib/rubocop/cop/yard/tag_type_syntax.rb +61 -6
- data/lib/rubocop/cop/yard_cops.rb +1 -0
- data/lib/rubocop/yard/version.rb +1 -1
- data/sig/rubocop/yard.rbs +12 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77c23358faa88b10e005e0f455dcf16283fe9fbf64c92276e5bff6bb201de43a
|
4
|
+
data.tar.gz: a1fb8bfe577565d31294920356f176fd9bc71b856ee7db0a11031347473602c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 478b94fe6b6bd5f310fc5774554888a5aa0f99245cc8a13ff8f5225668e5486213eeec4f7621f84b3a4790a9989a9b03a0ebc47c848fda1e757194353d3d1049
|
7
|
+
data.tar.gz: debd8aa21c9d08430fd666a239e6e6114fd1dc091053f76254def0f62d37b9d1698c291c3d91ac716fc80682b07593512bd512ecd143327d3995573dacf603fb
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,24 +1,34 @@
|
|
1
|
-
#
|
1
|
+
# RuboCop::YARD
|
2
2
|
|
3
3
|
You can check YARD format in Ruby code comment by RuboCop.
|
4
4
|
|
5
|
+
<img src="https://github.com/ksss/rubocop-yard/blob/main/demo.png?raw=true" width=700 />
|
6
|
+
|
5
7
|
## Features
|
6
8
|
|
7
9
|
### `YARD/TagTypeSyntax`
|
8
10
|
|
9
11
|
Check tag type syntax error.
|
10
12
|
|
11
|
-
|
13
|
+
```
|
14
|
+
@param [Symbol|String]
|
15
|
+
^^^^^^^^^^^^^ SyntaxError as YARD tag type
|
16
|
+
```
|
12
17
|
|
13
|
-
|
18
|
+
```
|
19
|
+
@param [Hash<Symbol, String>]
|
20
|
+
^^^^^^^^^^^^^^^^^^^^ <Type> is the collection type syntax. Did you mean {KeyType => ValueType} or Hash{KeyType => ValueType}
|
21
|
+
```
|
22
|
+
|
23
|
+
## Installation
|
14
24
|
|
15
25
|
Install the gem and add to the application's Gemfile by executing:
|
16
26
|
|
17
|
-
$ bundle add
|
27
|
+
$ bundle add rubocop-yard --require=false
|
18
28
|
|
19
29
|
If bundler is not being used to manage dependencies, install the gem by executing:
|
20
30
|
|
21
|
-
$ gem install
|
31
|
+
$ gem install rubocop-yard
|
22
32
|
|
23
33
|
## Usage
|
24
34
|
|
@@ -44,4 +54,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
44
54
|
|
45
55
|
## Code of Conduct
|
46
56
|
|
47
|
-
Everyone interacting in the
|
57
|
+
Everyone interacting in the RuboCop::YARD project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ksss/rubocop-yard/blob/main/CODE_OF_CONDUCT.md).
|
@@ -8,15 +8,30 @@ module RuboCop
|
|
8
8
|
# @param [Integer String]
|
9
9
|
#
|
10
10
|
# # bad
|
11
|
-
# @
|
11
|
+
# @param [Hash<Symbol, String>]
|
12
|
+
#
|
13
|
+
# # bad
|
14
|
+
# @param [Hash(String)]
|
15
|
+
#
|
16
|
+
# # bad
|
17
|
+
# @param [Array{Symbol => String}]
|
12
18
|
#
|
13
19
|
# # good
|
14
20
|
# @param [Integer, String]
|
15
21
|
#
|
16
22
|
# # good
|
17
|
-
# @
|
23
|
+
# @param [<String>]
|
24
|
+
# @param [Array<String>]
|
25
|
+
#
|
26
|
+
# # good
|
27
|
+
# @param [(String)]
|
28
|
+
# @param [Array(String)]
|
29
|
+
#
|
30
|
+
# # good
|
31
|
+
# @param [{KeyType => ValueType}]
|
32
|
+
# @param [Hash{KeyType => ValueType}]
|
18
33
|
class TagTypeSyntax < Base
|
19
|
-
MSG = '
|
34
|
+
MSG = ''
|
20
35
|
include RangeHelp # @return [void,]
|
21
36
|
|
22
37
|
def on_new_investigation
|
@@ -33,9 +48,49 @@ module RuboCop
|
|
33
48
|
def check(comment)
|
34
49
|
docstring = comment.text.gsub(/\A#\s*/, '')
|
35
50
|
::YARD::DocstringParser.new.parse(docstring).tags.each do |tag|
|
36
|
-
::YARD::Tags::TypesExplainer::Parser.parse(tag.types.join(', '))
|
51
|
+
::YARD::Tags::TypesExplainer::Parser.parse(tag.types.join(', ')).each do |types_explainer|
|
52
|
+
check_mismatch_collection_type(comment, types_explainer)
|
53
|
+
end
|
37
54
|
rescue SyntaxError
|
38
|
-
add_offense(
|
55
|
+
add_offense(tag_range_for_comment(comment), message: 'SyntaxError as YARD tag type')
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def check_mismatch_collection_type(comment, types_explainer)
|
60
|
+
case types_explainer
|
61
|
+
when ::YARD::Tags::TypesExplainer::HashCollectionType
|
62
|
+
if types_explainer.name == 'Hash'
|
63
|
+
types_explainer.key_types.each { |t| check_mismatch_collection_type(comment, t) }
|
64
|
+
types_explainer.value_types.each { |t| check_mismatch_collection_type(comment, t) }
|
65
|
+
else
|
66
|
+
message = "`{KeyType => ValueType}` is the hash collection type syntax. #{did_you_mean_type(types_explainer.name)}"
|
67
|
+
add_offense(tag_range_for_comment(comment), message: message)
|
68
|
+
end
|
69
|
+
when ::YARD::Tags::TypesExplainer::FixedCollectionType
|
70
|
+
if types_explainer.name == 'Array'
|
71
|
+
types_explainer.types.each { |t| check_mismatch_collection_type(comment, t) }
|
72
|
+
else
|
73
|
+
message = "`(Type)` is the fixed collection type syntax. #{did_you_mean_type(types_explainer.name)}"
|
74
|
+
add_offense(tag_range_for_comment(comment), message: message)
|
75
|
+
end
|
76
|
+
when ::YARD::Tags::TypesExplainer::CollectionType
|
77
|
+
if types_explainer.name == 'Array'
|
78
|
+
types_explainer.types.each { |t| check_mismatch_collection_type(comment, t) }
|
79
|
+
else
|
80
|
+
message = "`<Type>` is the collection type syntax. #{did_you_mean_type(types_explainer.name)}"
|
81
|
+
add_offense(tag_range_for_comment(comment), message: message)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def did_you_mean_type(name)
|
87
|
+
case name
|
88
|
+
when 'Hash'
|
89
|
+
'Did you mean `{KeyType => ValueType}` or `Hash{KeyType => ValueType}`'
|
90
|
+
when 'Array'
|
91
|
+
'Did you mean `<Type>` or `Array<Type>`'
|
92
|
+
else
|
93
|
+
''
|
39
94
|
end
|
40
95
|
end
|
41
96
|
|
@@ -47,7 +102,7 @@ module RuboCop
|
|
47
102
|
comment.source.match?(/@(?:param|return)\s+\[.*\]/)
|
48
103
|
end
|
49
104
|
|
50
|
-
def
|
105
|
+
def tag_range_for_comment(comment)
|
51
106
|
start_column = comment.source.index(/\[/) + 1
|
52
107
|
end_column = comment.source.index(/\]/)
|
53
108
|
offense_start = comment.location.column + start_column
|
data/lib/rubocop/yard/version.rb
CHANGED
data/sig/rubocop/yard.rbs
CHANGED
@@ -1,6 +1,17 @@
|
|
1
|
-
module
|
1
|
+
module RuboCop
|
2
2
|
module YARD
|
3
3
|
VERSION: String
|
4
4
|
# See the writing guide of rbs: https://github.com/ruby/rbs#guides
|
5
5
|
end
|
6
|
+
module Cop
|
7
|
+
module YARD
|
8
|
+
class TagTypeSyntax
|
9
|
+
type t = YARD::Tags::TypesExplainer::Type
|
10
|
+
| ::YARD::Tags::TypesExplainer::CollectionType
|
11
|
+
| ::YARD::Tags::TypesExplainer::FixedCollectionType
|
12
|
+
| ::YARD::Tags::TypesExplainer::HashCollectionType
|
13
|
+
private def check_mismatch_collection_type: (untyped comment, t types_explainer) -> void
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
6
17
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-yard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ksss
|
@@ -57,13 +57,13 @@ files:
|
|
57
57
|
- lib/rubocop/yard/inject.rb
|
58
58
|
- lib/rubocop/yard/version.rb
|
59
59
|
- sig/rubocop/yard.rbs
|
60
|
-
homepage: https://
|
60
|
+
homepage: https://github.com/ksss/rubocop-yard
|
61
61
|
licenses:
|
62
62
|
- MIT
|
63
63
|
metadata:
|
64
|
-
homepage_uri: https://
|
65
|
-
source_code_uri: https://
|
66
|
-
changelog_uri: https://
|
64
|
+
homepage_uri: https://github.com/ksss/rubocop-yard
|
65
|
+
source_code_uri: https://github.com/ksss/rubocop-yard
|
66
|
+
changelog_uri: https://github.com/ksss/rubocop-yard
|
67
67
|
rubygems_mfa_required: 'true'
|
68
68
|
post_install_message:
|
69
69
|
rdoc_options: []
|