rubocop-yard 0.8.2 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +9 -0
- data/config/default.yml +4 -0
- data/lib/rubocop/cop/yard/collection_style.rb +0 -4
- data/lib/rubocop/cop/yard/collection_type.rb +0 -4
- data/lib/rubocop/cop/yard/helper.rb +17 -0
- data/lib/rubocop/cop/yard/meaningless_tag.rb +4 -2
- data/lib/rubocop/cop/yard/mismatch_name.rb +2 -6
- data/lib/rubocop/cop/yard/tag_type_position.rb +43 -0
- data/lib/rubocop/cop/yard/tag_type_syntax.rb +0 -4
- data/lib/rubocop/cop/yard_cops.rb +1 -0
- data/lib/rubocop/yard/version.rb +1 -1
- data/sig/rubocop/yard.rbs +9 -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: 2b240277d34c92f69d7a7b3bf0cc2de5e6db342a668dd2b3426faad8f693b36d
|
4
|
+
data.tar.gz: d682c69f314766eb8e6ba49ac5ebb6d1c4dbe2cd3bed4c8e9d675ba49e347533
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c02ef119ea3d56b064ffc1770ae0abc28d8e519eef44516b1ae5e14bb34347b494782d0e0d7a32d9db996d271513ae234e06234e85d61e8175efd0a7a7397162
|
7
|
+
data.tar.gz: 162842c1675a778c33063ead865a10515c4665821751e3d05f222b5437369d06a62837ddcf1950bdc18775be4a46b8864e94489287464835d9db221d01557350
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -15,6 +15,15 @@ Check tag type syntax error.
|
|
15
15
|
^^^^^^^^^^^^^ (SyntaxError) invalid character at |
|
16
16
|
```
|
17
17
|
|
18
|
+
### `YARD/TagTypePosition`
|
19
|
+
|
20
|
+
Notice tag type position.
|
21
|
+
|
22
|
+
```
|
23
|
+
# @option [Integer] opts foo
|
24
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This docs found `[Integer]`, but parser of YARD can't found types. Please check syntax of YARD.
|
25
|
+
```
|
26
|
+
|
18
27
|
### `YARD/CollectionStyle`
|
19
28
|
|
20
29
|
`EnforcedStyle long (default)`
|
data/config/default.yml
CHANGED
@@ -82,10 +82,6 @@ module RuboCop
|
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
|
-
def inline_comment?(comment)
|
86
|
-
!comment_line?(comment.source_range.source_line)
|
87
|
-
end
|
88
|
-
|
89
85
|
def include_yard_tag?(comment)
|
90
86
|
comment.source.match?(/@(?:param|return|option|raise|yieldparam|yieldreturn)\s+.*\[.*\]/)
|
91
87
|
end
|
@@ -112,10 +112,6 @@ module RuboCop
|
|
112
112
|
corrector.replace(comment, comment.source.sub(/\[(.*)\]/) { "[#{styled_string(types_explainer)}]" })
|
113
113
|
end
|
114
114
|
|
115
|
-
def inline_comment?(comment)
|
116
|
-
!comment_line?(comment.source_range.source_line)
|
117
|
-
end
|
118
|
-
|
119
115
|
def include_yard_tag?(comment)
|
120
116
|
comment.source.match?(/@(?:param|return|option|raise|yieldparam|yieldreturn)\s+.*\[.*\]/)
|
121
117
|
end
|
@@ -8,6 +8,8 @@ module RuboCop
|
|
8
8
|
case tag
|
9
9
|
when ::YARD::Tags::OptionTag
|
10
10
|
tag.pair.types
|
11
|
+
when ::YARD::Tags::OverloadTag
|
12
|
+
tag.types
|
11
13
|
else
|
12
14
|
tag.types
|
13
15
|
end
|
@@ -69,6 +71,21 @@ module RuboCop
|
|
69
71
|
raise "#{types_explainer.class} is not supported"
|
70
72
|
end
|
71
73
|
end
|
74
|
+
|
75
|
+
def inline_comment?(comment)
|
76
|
+
!comment_line?(comment.source_range.source_line)
|
77
|
+
end
|
78
|
+
|
79
|
+
def build_docstring(preceding_lines)
|
80
|
+
comment_texts = preceding_lines.map { |l| l.text.gsub(/\A#/, '') }
|
81
|
+
minimum_space = comment_texts.map { |t| t.index(/[^\s]/) }.min
|
82
|
+
yard_docstring = comment_texts.map { |t| t[minimum_space..-1] }.join("\n")
|
83
|
+
begin
|
84
|
+
::YARD::DocstringParser.new.parse(yard_docstring)
|
85
|
+
rescue
|
86
|
+
nil
|
87
|
+
end
|
88
|
+
end
|
72
89
|
end
|
73
90
|
end
|
74
91
|
end
|
@@ -20,6 +20,7 @@ module RuboCop
|
|
20
20
|
# # good
|
21
21
|
# CONST = 1
|
22
22
|
class MeaninglessTag < Base
|
23
|
+
include YARD::Helper
|
23
24
|
include RangeHelp
|
24
25
|
include DocumentationComment
|
25
26
|
extend AutoCorrector
|
@@ -34,8 +35,9 @@ module RuboCop
|
|
34
35
|
preceding_lines = preceding_lines(node)
|
35
36
|
return false unless preceding_comment?(node, preceding_lines.last)
|
36
37
|
|
37
|
-
|
38
|
-
|
38
|
+
docstring = build_docstring(preceding_lines)
|
39
|
+
return false unless docstring
|
40
|
+
|
39
41
|
docstring.tags.each do |tag|
|
40
42
|
next unless tag.tag_name == 'param' || tag.tag_name == 'option'
|
41
43
|
|
@@ -28,12 +28,8 @@ module RuboCop
|
|
28
28
|
preceding_lines = preceding_lines(node)
|
29
29
|
return false unless preceding_comment?(node, preceding_lines.last)
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
::YARD::DocstringParser.new.parse(yard_docstring)
|
34
|
-
rescue
|
35
|
-
return false
|
36
|
-
end
|
31
|
+
docstring = build_docstring(preceding_lines)
|
32
|
+
return false unless docstring
|
37
33
|
|
38
34
|
return false if include_overload_tag?(docstring)
|
39
35
|
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module YARD
|
6
|
+
class TagTypePosition < Base
|
7
|
+
include YARD::Helper
|
8
|
+
include RangeHelp
|
9
|
+
|
10
|
+
def on_new_investigation
|
11
|
+
processed_source.comments.each do |comment|
|
12
|
+
next if inline_comment?(comment)
|
13
|
+
next unless include_yard_tag?(comment)
|
14
|
+
next unless include_yard_tag_type?(comment)
|
15
|
+
|
16
|
+
check(comment)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def check(comment)
|
23
|
+
docstring = comment.text.gsub(/\A#\s*/, '')
|
24
|
+
::YARD::DocstringParser.new.parse(docstring).tags.each do |tag|
|
25
|
+
types = extract_tag_types(tag)
|
26
|
+
if types.nil?
|
27
|
+
match = comment.source.match(/(?<type>\[.+\])/)
|
28
|
+
add_offense(comment, message: "This docs found `#{match[:type]}`, but parser of YARD can't found types. Please check syntax of YARD.")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def include_yard_tag?(comment)
|
34
|
+
comment.source.match?(/@(?:param|return|option|raise|yieldparam|yieldreturn)\s+.*\[.*\]/)
|
35
|
+
end
|
36
|
+
|
37
|
+
def include_yard_tag_type?(comment)
|
38
|
+
comment.source.match?(/\[.+\]/)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -43,10 +43,6 @@ module RuboCop
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
def inline_comment?(comment)
|
47
|
-
!comment_line?(comment.source_range.source_line)
|
48
|
-
end
|
49
|
-
|
50
46
|
def include_yard_tag?(comment)
|
51
47
|
comment.source.match?(/@(?:param|return|option|raise|yieldparam|yieldreturn)\s+.*\[.*\]/)
|
52
48
|
end
|
data/lib/rubocop/yard/version.rb
CHANGED
data/sig/rubocop/yard.rbs
CHANGED
@@ -16,6 +16,15 @@ module RuboCop
|
|
16
16
|
|
17
17
|
module Helper
|
18
18
|
def extract_tag_types: (tag tag) -> Array[String]?
|
19
|
+
def inline_comment?: (::Parser::Source::Comment comment) -> bool
|
20
|
+
end
|
21
|
+
|
22
|
+
class TagTypePosition < ::RuboCop::Cop::Base
|
23
|
+
include YARD::Helper
|
24
|
+
|
25
|
+
def check: (::Parser::Source::Comment comment) -> void
|
26
|
+
def include_yard_tag?: (::Parser::Source::Comment comment) -> bool
|
27
|
+
def include_yard_tag_type?: (::Parser::Source::Comment comment) -> bool
|
19
28
|
end
|
20
29
|
|
21
30
|
class TagTypeSyntax < ::RuboCop::Cop::Base
|
@@ -25,7 +34,6 @@ module RuboCop
|
|
25
34
|
|
26
35
|
def check: (::Parser::Source::Comment comment) -> void
|
27
36
|
def check_syntax_error: (::Parser::Source::Comment comment) { () -> void } -> void
|
28
|
-
def inline_comment?: (::Parser::Source::Comment comment) -> bool
|
29
37
|
def include_yard_tag?: (::Parser::Source::Comment comment) -> bool
|
30
38
|
def tag_range_for_comment: (::Parser::Source::Comment comment) -> untyped
|
31
39
|
end
|
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.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ksss
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -57,6 +57,7 @@ files:
|
|
57
57
|
- lib/rubocop/cop/yard/meaningless_tag.rb
|
58
58
|
- lib/rubocop/cop/yard/mismatch_name.rb
|
59
59
|
- lib/rubocop/cop/yard/patch.rb
|
60
|
+
- lib/rubocop/cop/yard/tag_type_position.rb
|
60
61
|
- lib/rubocop/cop/yard/tag_type_syntax.rb
|
61
62
|
- lib/rubocop/cop/yard_cops.rb
|
62
63
|
- lib/rubocop/yard.rb
|