rubocop-yard 0.8.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 64ff6712be966753c2ddc2510a4a51c1d36488ed302b8fc848f50e8beb6561b5
4
- data.tar.gz: a34143c5775f3705adb8bd4aac2837b4c4b2334f7191ccc2c7629b015cd3fe89
3
+ metadata.gz: 06747e91e4d94f896cb88e9fb16826b8863afb224451a97a55aedbe0e0c36517
4
+ data.tar.gz: 8f8eb7d93d78b2f23b356850e346e82f1cdf187b40fc2e17e584751a5929774a
5
5
  SHA512:
6
- metadata.gz: 1bdf6a2b0740459083c5e1b0e93ecab91172b372821168972879f94bb3b59c21706a0eb84895d03cf6ce915ab25b510100c8c84edd7cecd8469d8b6950647cc0
7
- data.tar.gz: 89d4dd145df3813f14e4f3fb790e892c1948858843a8ab1b834450c6eac52164f5d222ebc8c8dcd3db3589d23e0b82ae599a9247e60f41d3697b82c8e0157c44
6
+ metadata.gz: 7a299956fd71c933d0d4aa59d68c273cd49e481b61be404f1a071b6051d8c874e18f7de1a27b1b3d59b72c6e3ee098ec554d1bb5c06e94971cc4bb04e4890555
7
+ data.tar.gz: e940c21c3172cc9ba385f16d227418006406af7c44f34a7c1da32ee53dabfa3062d7e83b2a2351671a7a68d9c4457f4672df574e5d71a1e68fcf406fa5da98e2
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.9.0] - 2023-11-28
4
+
5
+ - Add `YARD/TagTypePosition`
6
+
7
+ ## [0.8.0] - 2023-11-6
8
+
9
+ - Support EnforcedStylePrototypeName
10
+
3
11
  ## [0.7.0] - 2023-10-14
4
12
 
5
13
  - New feature
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
@@ -35,3 +35,7 @@ YARD/MismatchName:
35
35
  - before
36
36
  - after
37
37
 
38
+ YARD/TagTypePosition:
39
+ Description: 'Notice tag type position'
40
+ Enabled: true
41
+ VersionAdded: '0.9.0'
@@ -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
@@ -19,7 +21,7 @@ module RuboCop
19
21
 
20
22
  def each_types_explainer(docstring, &block)
21
23
  docstring.tags.each do |tag|
22
- types = extract_tag_types(tag)
24
+ types = extract_tag_types(tag) or next
23
25
 
24
26
  begin
25
27
  types_explainers = parse_type(types.join(', '))
@@ -69,6 +71,10 @@ 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
72
78
  end
73
79
  end
74
80
  end
@@ -57,6 +57,7 @@ module RuboCop
57
57
  end
58
58
 
59
59
  next unless node.arguments.none? { |arg_node| tag.name.to_sym == arg_node.name }
60
+ next unless types
60
61
 
61
62
  begin
62
63
  parse_type(types.join(', '))
@@ -148,8 +149,8 @@ module RuboCop
148
149
  end
149
150
 
150
151
  def add_offense_to_tag(node, comment, tag)
151
- tag_name_regexp = Regexp.new("\\b#{Regexp.escape(tag.name)}\\b")
152
- start_column = comment.source.index(tag_name_regexp)
152
+ tag_name_regexp = Regexp.new("\\s#{Regexp.escape(tag.name)}\\s")
153
+ start_column = comment.source.index(tag_name_regexp) or return
153
154
  offense_start = comment.location.column + start_column
154
155
  offense_end = offense_start + tag.name.length - 1
155
156
  range = source_range(processed_source.buffer, comment.location.line, offense_start..offense_end)
@@ -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
@@ -27,7 +27,7 @@ module RuboCop
27
27
  def check(comment)
28
28
  docstring = comment.text.gsub(/\A#\s*/, '')
29
29
  ::YARD::DocstringParser.new.parse(docstring).tags.each do |tag|
30
- types = extract_tag_types(tag)
30
+ types = extract_tag_types(tag) or next
31
31
 
32
32
  check_syntax_error(comment) do
33
33
  parse_type(types.join(', '))
@@ -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
@@ -7,4 +7,5 @@ require_relative 'yard/collection_style'
7
7
  require_relative 'yard/collection_type'
8
8
  require_relative 'yard/meaningless_tag'
9
9
  require_relative 'yard/mismatch_name'
10
+ require_relative 'yard/tag_type_position'
10
11
  require_relative 'yard/tag_type_syntax'
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module YARD
5
- VERSION = "0.8.1"
5
+ VERSION = "0.9.0"
6
6
  end
7
7
  end
data/sig/rubocop/yard.rbs CHANGED
@@ -5,12 +5,44 @@ module RuboCop
5
5
  end
6
6
  module Cop
7
7
  module YARD
8
+ type tag = ::YARD::Tags::Tag | ::YARD::Tags::OverloadTag | ::YARD::Tags::OptionTag
9
+ type tag_types = YARD::Tags::TypesExplainer::Type
10
+ | ::YARD::Tags::TypesExplainer::CollectionType
11
+ | ::YARD::Tags::TypesExplainer::FixedCollectionType
12
+ | ::YARD::Tags::TypesExplainer::HashCollectionType
8
13
  class CollectionType
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
+ private def check_mismatch_collection_type: (untyped comment, tag_types types_explainer) -> void
15
+ end
16
+
17
+ module Helper
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
28
+ end
29
+
30
+ class TagTypeSyntax < ::RuboCop::Cop::Base
31
+ include YARD::Helper
32
+
33
+ private
34
+
35
+ def check: (::Parser::Source::Comment comment) -> void
36
+ def check_syntax_error: (::Parser::Source::Comment comment) { () -> void } -> void
37
+ def include_yard_tag?: (::Parser::Source::Comment comment) -> bool
38
+ def tag_range_for_comment: (::Parser::Source::Comment comment) -> untyped
39
+ end
40
+
41
+ class MismatchName < ::RuboCop::Cop::Base
42
+ include YARD::Helper
43
+
44
+ def add_offense_to_tag: (untyped node, ::Parser::Source::Comment comment, ::YARD::Tags::Tag tag) -> void
45
+ def cop_config_prototype_name: () -> ("before" | "after")
14
46
  end
15
47
  end
16
48
  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.8.1
4
+ version: 0.9.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-11-22 00:00:00.000000000 Z
11
+ date: 2023-12-06 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