rubocop-yard 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +8 -0
- data/lib/rubocop/cop/yard/mismatch_name.rb +57 -5
- data/lib/rubocop/yard/version.rb +1 -1
- 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: 903402913fde5bdf6702b4412bc6f1ab07197f5f993039c440ffd1a736b5277c
|
4
|
+
data.tar.gz: 31eeffd0cbd9fd26fe3cf5035784c990bea7e9296e10cbb22a36218c31064db9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48d2bd70f00ffd7c31e864039b77b9eabaff53e52b25c8825959c25486f024e3f3d63827ba98dc8ea5f09dd6a964e93700eaa1f88ef1ec6746d46804026bd444
|
7
|
+
data.tar.gz: 7f4e6010137fd5f1c55b70c9c6744f4ca194e6a44078aca0643020bd0ba1c9b43b7cec3cea1790eff025f79990cedb443e75b737d292095fba0896f5b0f17b68
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -86,6 +86,14 @@ Check `@param` and `@option` name with method definition.
|
|
86
86
|
def foo(strings, opts = {})
|
87
87
|
```
|
88
88
|
|
89
|
+
Check undocumented argument.
|
90
|
+
|
91
|
+
```
|
92
|
+
# @param [String] strings
|
93
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^ This method has argument `opts`, But not documented
|
94
|
+
def foo(strings, opts = {})
|
95
|
+
```
|
96
|
+
|
89
97
|
### `YARD/MeaninglessTag`
|
90
98
|
|
91
99
|
Check `@param` and `@option` with class/module or casgn
|
@@ -20,6 +20,7 @@ module RuboCop
|
|
20
20
|
include YARD::Helper
|
21
21
|
include RangeHelp
|
22
22
|
include DocumentationComment
|
23
|
+
extend AutoCorrector
|
23
24
|
|
24
25
|
def on_def(node)
|
25
26
|
return unless node.arguments?
|
@@ -28,7 +29,12 @@ module RuboCop
|
|
28
29
|
return false unless preceding_comment?(node, preceding_lines.last)
|
29
30
|
|
30
31
|
yard_docstring = preceding_lines.map { |line| line.text.gsub(/\A#\s*/, '') }.join("\n")
|
31
|
-
docstring =
|
32
|
+
docstring = begin
|
33
|
+
::YARD::DocstringParser.new.parse(yard_docstring)
|
34
|
+
rescue
|
35
|
+
return false
|
36
|
+
end
|
37
|
+
|
32
38
|
return false if include_overload_tag?(docstring)
|
33
39
|
|
34
40
|
each_tags_by_docstring(['param', 'option'], docstring) do |tags|
|
@@ -56,9 +62,35 @@ module RuboCop
|
|
56
62
|
parse_type(types.join(', '))
|
57
63
|
rescue SyntaxError
|
58
64
|
next
|
59
|
-
end
|
65
|
+
end if types
|
60
66
|
|
61
|
-
add_offense_to_tag(comment, tag)
|
67
|
+
add_offense_to_tag(node, comment, tag)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# Documentation only or just `@return` is a common form of documentation.
|
72
|
+
# The subsequent features will be limited to cases where both `@param` and `@option` are present.
|
73
|
+
unless docstring.tags.find { |tag| (tag.tag_name == 'param' && !tag.instance_of?(::YARD::Tags::RefTagList)) || tag.tag_name == 'option' }
|
74
|
+
return false
|
75
|
+
end
|
76
|
+
node.arguments.each do |argument|
|
77
|
+
next if argument.type == :blockarg
|
78
|
+
next if argument.name.nil?
|
79
|
+
|
80
|
+
found = docstring.tags.find do |tag|
|
81
|
+
next unless tag.tag_name == 'param' || tag.tag_name == 'option'
|
82
|
+
tag.name&.to_sym == argument.name
|
83
|
+
end
|
84
|
+
|
85
|
+
unless found
|
86
|
+
comment = preceding_lines.last
|
87
|
+
return if part_of_ignored_node?(comment)
|
88
|
+
add_offense(comment, message: "This method has argument `#{argument.name}`, But not documented") do |corrector|
|
89
|
+
corrector.replace(
|
90
|
+
comment.source_range.end,
|
91
|
+
"#{comment.source_range.end.join(node.source_range.begin).source}# #{tag_prototype(argument)}"
|
92
|
+
)
|
93
|
+
end
|
62
94
|
end
|
63
95
|
end
|
64
96
|
end
|
@@ -66,6 +98,18 @@ module RuboCop
|
|
66
98
|
|
67
99
|
private
|
68
100
|
|
101
|
+
# @param [RuboCop::AST::ArgNode] argument
|
102
|
+
def tag_prototype(argument)
|
103
|
+
case argument.type
|
104
|
+
when :kwrestarg
|
105
|
+
"@param [Hash{Symbol => Object}] #{argument.name}"
|
106
|
+
when :restarg
|
107
|
+
"@param [Array<Object>] #{argument.name}"
|
108
|
+
else
|
109
|
+
"@param [Object] #{argument.name}"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
69
113
|
def each_tags_by_docstring(tag_names, docstring)
|
70
114
|
tag_names.each do |tag_name|
|
71
115
|
yield docstring.tags.select { |tag| tag.tag_name == tag_name }
|
@@ -80,13 +124,21 @@ module RuboCop
|
|
80
124
|
end
|
81
125
|
end
|
82
126
|
|
83
|
-
def add_offense_to_tag(comment, tag)
|
127
|
+
def add_offense_to_tag(node, comment, tag)
|
84
128
|
tag_name_regexp = Regexp.new("\\b#{Regexp.escape(tag.name)}\\b")
|
85
129
|
start_column = comment.source.index(tag_name_regexp)
|
86
130
|
offense_start = comment.location.column + start_column
|
87
131
|
offense_end = offense_start + tag.name.length - 1
|
88
132
|
range = source_range(processed_source.buffer, comment.location.line, offense_start..offense_end)
|
89
|
-
|
133
|
+
argument_names = node.arguments.map(&:name).compact
|
134
|
+
argument_name =
|
135
|
+
if argument_names.empty?
|
136
|
+
''
|
137
|
+
else
|
138
|
+
" of [#{argument_names.join(', ')}]"
|
139
|
+
end
|
140
|
+
add_offense(range, message: "`#{tag.name}` is not found in method arguments#{argument_name}")
|
141
|
+
ignore_node(comment)
|
90
142
|
end
|
91
143
|
|
92
144
|
def include_overload_tag?(docstring)
|
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.7.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-10-
|
11
|
+
date: 2023-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|