rubocop-yard 0.3.1 → 0.4.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 +4 -0
- data/README.md +17 -4
- data/config/default.yml +5 -0
- data/lib/rubocop/cop/yard/meaningless_tag.rb +50 -0
- data/lib/rubocop/cop/yard/mismatch_name.rb +2 -2
- data/lib/rubocop/cop/yard/tag_type.rb +38 -21
- data/lib/rubocop/cop/yard_cops.rb +1 -0
- data/lib/rubocop/yard/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35f55b03315d73095819182351a19278528a8d91f5fb71f9644e39734ef0aa89
|
4
|
+
data.tar.gz: 731f21ea908307e87b59e36dae70fc9da5ced99157cdc53d0084c077673fd496
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 378e7d10ff7f50c807a1fe0fe6266e7163ebcece3bc6a4cf340cf98baade320a4785d2520c42aa9319bc20e20642dc46b39311088b58e521f57ee0ce15fab48b
|
7
|
+
data.tar.gz: a33bc93f4cb7712b0c73c259d3ecb7f94409973ec73c897494e723c33f5879b7686deba726e7a1f871da20aae3abd46554641c8d1ea29d5c58124cc66646213e
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -12,12 +12,12 @@ Check tag type syntax error.
|
|
12
12
|
|
13
13
|
```
|
14
14
|
# @param [Symbol|String]
|
15
|
-
|
15
|
+
^^^^^^^^^^^^^ SyntaxError as YARD tag type
|
16
16
|
```
|
17
17
|
|
18
18
|
```
|
19
19
|
# @param [Hash<Symbol, String>]
|
20
|
-
|
20
|
+
^^^^^^^^^^^^^^^^^^^^ `<Type>` is the collection type syntax. Did you mean `{KeyType => ValueType}` or `Hash{KeyType => ValueType}`
|
21
21
|
```
|
22
22
|
|
23
23
|
### `YARD/MismatchName`
|
@@ -26,12 +26,25 @@ Check `@param` and `@option` name with method definition.
|
|
26
26
|
|
27
27
|
```rb
|
28
28
|
# @param [String] string
|
29
|
-
|
29
|
+
^^^^^^ `string` is not found in method arguments
|
30
30
|
# @option opt bar [String]
|
31
|
-
|
31
|
+
^^^ `opt` is not found in method arguments
|
32
32
|
def foo(strings, opts = {})
|
33
33
|
```
|
34
34
|
|
35
|
+
### `YARD/MeaninglessTag`
|
36
|
+
|
37
|
+
Check `@param` and `@option` with class/module or casgn
|
38
|
+
|
39
|
+
```rb
|
40
|
+
# @param [String] foo
|
41
|
+
^^^^^^^^^^^^^^^^^^^^^ `@param` is meaningless tag on module
|
42
|
+
module Foo
|
43
|
+
# @option foo bar [String]
|
44
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^ `@option` is meaningless tag on casgn
|
45
|
+
CONST = 1
|
46
|
+
```
|
47
|
+
|
35
48
|
## Installation
|
36
49
|
|
37
50
|
Install the gem and add to the application's Gemfile by executing:
|
data/config/default.yml
CHANGED
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module YARD
|
6
|
+
# @example meaningless tag
|
7
|
+
# # bad
|
8
|
+
# # @param [String] foo
|
9
|
+
# # @option bar baz [String]
|
10
|
+
# class Foo
|
11
|
+
#
|
12
|
+
# # bad
|
13
|
+
# # @param [String] foo
|
14
|
+
# # @option bar baz [String]
|
15
|
+
# CONST = 1
|
16
|
+
#
|
17
|
+
# # good
|
18
|
+
# class Foo
|
19
|
+
#
|
20
|
+
# # good
|
21
|
+
# CONST = 1
|
22
|
+
class MeaninglessTag < Base
|
23
|
+
include RangeHelp
|
24
|
+
include DocumentationComment
|
25
|
+
|
26
|
+
def on_class(node)
|
27
|
+
check(node)
|
28
|
+
end
|
29
|
+
alias on_module on_class
|
30
|
+
alias on_casgn on_class
|
31
|
+
|
32
|
+
def check(node)
|
33
|
+
preceding_lines = preceding_lines(node)
|
34
|
+
return false unless preceding_comment?(node, preceding_lines.last)
|
35
|
+
|
36
|
+
yard_docstring = preceding_lines.map { |line| line.text.gsub(/\A#\s*/, '') }.join("\n")
|
37
|
+
docstring = ::YARD::DocstringParser.new.parse(yard_docstring)
|
38
|
+
docstring.tags.each do |tag|
|
39
|
+
next unless tag.tag_name == 'param' || tag.tag_name == 'option'
|
40
|
+
|
41
|
+
comment = preceding_lines.find { |line| line.text.include?("@#{tag.tag_name}") }
|
42
|
+
next unless comment
|
43
|
+
|
44
|
+
add_offense(comment, message: "`@#{tag.tag_name}` is meaningless tag on #{node.type}")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module YARD
|
6
|
-
# @example
|
6
|
+
# @example mismatch name
|
7
7
|
# # bad
|
8
8
|
# # @param [void] baz
|
9
9
|
# # @option opt aaa [void]
|
@@ -12,7 +12,7 @@ module RuboCop
|
|
12
12
|
#
|
13
13
|
# # good
|
14
14
|
# # @param [void] bar
|
15
|
-
# # @param [Array]
|
15
|
+
# # @param [Array] arg
|
16
16
|
# # @option opts aaa [void]
|
17
17
|
# def foo(bar, opts = {}, *arg)
|
18
18
|
# end
|
@@ -3,37 +3,36 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module YARD
|
6
|
-
# @example
|
6
|
+
# @example tag type
|
7
7
|
# # bad
|
8
|
-
# @param [Integer String]
|
8
|
+
# # @param [Integer String]
|
9
9
|
#
|
10
10
|
# # bad
|
11
|
-
# @param [Hash<Symbol, String>]
|
11
|
+
# # @param [Hash<Symbol, String>]
|
12
12
|
#
|
13
13
|
# # bad
|
14
|
-
# @param [Hash(String)]
|
14
|
+
# # @param [Hash(String)]
|
15
15
|
#
|
16
16
|
# # bad
|
17
|
-
# @param [Array{Symbol => String}]
|
17
|
+
# # @param [Array{Symbol => String}]
|
18
18
|
#
|
19
19
|
# # good
|
20
|
-
# @param [Integer, String]
|
20
|
+
# # @param [Integer, String]
|
21
21
|
#
|
22
22
|
# # good
|
23
|
-
# @param [<String>]
|
24
|
-
# @param [Array<String>]
|
25
|
-
# @param [List<String>]
|
26
|
-
# @param [Array<(String, Fixnum, Hash)>]
|
23
|
+
# # @param [<String>]
|
24
|
+
# # @param [Array<String>]
|
25
|
+
# # @param [List<String>]
|
26
|
+
# # @param [Array<(String, Fixnum, Hash)>]
|
27
27
|
#
|
28
28
|
# # good
|
29
|
-
# @param [(String)]
|
30
|
-
# @param [Array(String)]
|
29
|
+
# # @param [(String)]
|
30
|
+
# # @param [Array(String)]
|
31
31
|
#
|
32
32
|
# # good
|
33
|
-
# @param [{KeyType => ValueType}]
|
34
|
-
# @param [Hash{KeyType => ValueType}]
|
33
|
+
# # @param [{KeyType => ValueType}]
|
34
|
+
# # @param [Hash{KeyType => ValueType}]
|
35
35
|
class TagType < Base
|
36
|
-
MSG = ''
|
37
36
|
include RangeHelp # @return [void,]
|
38
37
|
|
39
38
|
def on_new_investigation
|
@@ -50,13 +49,22 @@ module RuboCop
|
|
50
49
|
def check(comment)
|
51
50
|
docstring = comment.text.gsub(/\A#\s*/, '')
|
52
51
|
::YARD::DocstringParser.new.parse(docstring).tags.each do |tag|
|
53
|
-
|
52
|
+
types = extract_tag_type(tag)
|
54
53
|
|
55
|
-
|
56
|
-
|
54
|
+
check_syntax_error(comment) do
|
55
|
+
types_explainers = ::YARD::Tags::TypesExplainer::Parser.parse(types.join(', '))
|
56
|
+
types_explainers.each do |types_explainer|
|
57
|
+
check_mismatch_collection_type(comment, types_explainer)
|
58
|
+
end
|
57
59
|
end
|
58
|
-
|
59
|
-
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def check_syntax_error(comment)
|
64
|
+
begin
|
65
|
+
yield
|
66
|
+
rescue SyntaxError => e
|
67
|
+
add_offense(tag_range_for_comment(comment), message: "(#{e.class}) #{e.message}")
|
60
68
|
end
|
61
69
|
end
|
62
70
|
|
@@ -88,12 +96,21 @@ module RuboCop
|
|
88
96
|
end
|
89
97
|
end
|
90
98
|
|
99
|
+
def extract_tag_type(tag)
|
100
|
+
case tag
|
101
|
+
when ::YARD::Tags::OptionTag
|
102
|
+
tag.pair.types
|
103
|
+
else
|
104
|
+
tag.types
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
91
108
|
def inline_comment?(comment)
|
92
109
|
!comment_line?(comment.source_range.source_line)
|
93
110
|
end
|
94
111
|
|
95
112
|
def include_yard_tag?(comment)
|
96
|
-
comment.source.match?(/@(?:param|return|option|raise|yieldparam|yieldreturn)\s
|
113
|
+
comment.source.match?(/@(?:param|return|option|raise|yieldparam|yieldreturn)\s+.*\[.*\]/)
|
97
114
|
end
|
98
115
|
|
99
116
|
def tag_range_for_comment(comment)
|
data/lib/rubocop/yard/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-yard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ksss
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-09-
|
11
|
+
date: 2023-09-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -51,6 +51,7 @@ files:
|
|
51
51
|
- README.md
|
52
52
|
- config/default.yml
|
53
53
|
- lib/rubocop-yard.rb
|
54
|
+
- lib/rubocop/cop/yard/meaningless_tag.rb
|
54
55
|
- lib/rubocop/cop/yard/mismatch_name.rb
|
55
56
|
- lib/rubocop/cop/yard/tag_type.rb
|
56
57
|
- lib/rubocop/cop/yard_cops.rb
|