rubocop-yard 1.3.0 → 1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1899df376dd3954bb74cccef087aa23643d16a8c585965cafc732d2463ef408f
4
- data.tar.gz: 6b268c4978625ffd07dbdcfa971f57df5442fcea0dfa1833b7570754f1758042
3
+ metadata.gz: 8272b34188843c9aa79a7ffda45f7ff0b1d989986b16a17dd8e6c8518bd3be44
4
+ data.tar.gz: 1e63dfa63b3176abb82c47a4fefa4774ba6cd2b30f8fc0a860ec48730bbc03d4
5
5
  SHA512:
6
- metadata.gz: 1db8c39281f661263e7c9f3afc99e5155ad5ee566d6c0025519850e5585e6bc22c617e37b3772a41f7ca4d9c574af65ee853d8ed89f09af9537f66381f3d197a
7
- data.tar.gz: 95a2d49c434ea46b6b86dee06347c96f0522cbcedcd5a34699536beec0009f7d8fe877ea352f79dcf57079186a8f6f5ae40c4454dbe40c06d4a1deabedddd254
6
+ metadata.gz: 50f2218aa2ec22871eac830efb774b6c1b135a09c2c4a0b32baebff6387b36873b2afb4e7f57074203e9d4c21907e054604b96113c83a89a686e5924ee2b6866
7
+ data.tar.gz: a4ced5b2e2f17569bc8271e07b17d2029e64ec063273cc4cc8a979aa678a5962a21d9f65f2355936e454f1f00b642a02b5861e5b61bd043e8804f7f8e15ee236
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.4.0] - 2026-11-14
4
+
5
+ * Add new cop `YARD/StructParamTag` (disabled by default) to prefer `@param` over `@!attribute` for `Struct.new`/`Data.define` members by @lekemula in https://github.com/ksss/rubocop-yard/pull/46
6
+
7
+ ## [1.3.0] - 2026-06-27
8
+
9
+ * Guard against YARD parser type/explainer size mismatch by @ksss in https://github.com/ksss/rubocop-yard/pull/45
10
+
11
+ ## [1.2.0] - 2026-06-01
12
+
3
13
  * `YARD/MeaninglessTag`: Allow `@param` on `Struct.new`/`Data.define` constant assignments (https://github.com/ksss/rubocop-yard/issues/36)
4
14
 
5
15
  ## [1.1.0] - 2026-01-29
data/README.md CHANGED
@@ -116,6 +116,16 @@ module Foo
116
116
  CONST = 1
117
117
  ```
118
118
 
119
+ ### `YARD/StructParamTag`
120
+
121
+ Prefer `@param` over `@!attribute` for `Struct.new`/`Data.define` members (disabled by default). YARD reads both, but some tools, such as Solargraph, read only `@param` there.
122
+
123
+ ```rb
124
+ # @!attribute name [String]
125
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `@param` instead of `@!attribute` for Struct/Data members.
126
+ Person = Struct.new(:name)
127
+ ```
128
+
119
129
  ## Installation
120
130
 
121
131
  Install the gem and add to the application's Gemfile by executing:
data/config/default.yml CHANGED
@@ -39,3 +39,8 @@ YARD/TagTypePosition:
39
39
  Description: 'Notice tag type position'
40
40
  Enabled: true
41
41
  VersionAdded: '0.9.0'
42
+
43
+ YARD/StructParamTag:
44
+ Description: 'Prefer `@param` over `@!attribute` for Struct/Data members'
45
+ Enabled: false
46
+ VersionAdded: '1.4.0'
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module YARD
6
+ # Documents `Struct.new` and `Data.define` members with `@param` tags
7
+ # rather than `@!attribute` directives.
8
+ #
9
+ # YARD reads both, but some tools read only `@param` there, e.g.
10
+ # Solargraph, which types the generated members from them.
11
+ #
12
+ # @example
13
+ # # bad
14
+ # # @!attribute name [String]
15
+ # Person = Struct.new(:name)
16
+ #
17
+ # # good
18
+ # # @param name [String]
19
+ # Person = Struct.new(:name)
20
+ class StructParamTag < Base
21
+ extend AutoCorrector
22
+
23
+ MSG = 'Use `@param` instead of `@!attribute` for Struct/Data members.'
24
+ ATTRIBUTE = /\A#\s*@!attribute\b/
25
+ # `@!attribute name [Type] text`, which maps onto `@param` one to one
26
+ CORRECTABLE_ATTRIBUTE = /\A(#\s*)@!attribute(\s+\w+\s+\[)/
27
+
28
+ # @!method struct_or_data_definition?(node)
29
+ # @param node [RuboCop::AST::Node]
30
+ def_node_matcher :struct_or_data_definition?, <<~PATTERN
31
+ (casgn _ _ {
32
+ (block (send (const _ {:Struct :Data}) {:new :define} ...) ...)
33
+ (send (const _ {:Struct :Data}) {:new :define} ...)
34
+ })
35
+ PATTERN
36
+
37
+ def on_casgn(node)
38
+ return unless struct_or_data_definition?(node)
39
+
40
+ preceding_comments(node).each do |comment|
41
+ next unless comment.text.match?(ATTRIBUTE)
42
+
43
+ add_offense(comment) do |corrector|
44
+ next unless comment.text.match?(CORRECTABLE_ATTRIBUTE)
45
+
46
+ corrector.replace(comment, comment.text.sub(CORRECTABLE_ATTRIBUTE, '\1@param\2'))
47
+ end
48
+ end
49
+ end
50
+
51
+ private
52
+
53
+ # The comment block that ends on the line right above the node
54
+ def preceding_comments(node)
55
+ by_line = processed_source.comments.to_h { |comment| [comment.loc.line, comment] }
56
+ line = node.first_line - 1
57
+ comments = []
58
+ while (comment = by_line[line])
59
+ comments.unshift(comment)
60
+ line -= 1
61
+ end
62
+ comments
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -7,5 +7,6 @@ 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/struct_param_tag'
10
11
  require_relative 'yard/tag_type_position'
11
12
  require_relative 'yard/tag_type_syntax'
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module YARD
5
- VERSION = "1.3.0"
5
+ VERSION = "1.4.0"
6
6
  end
7
7
  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: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ksss
@@ -70,6 +70,7 @@ files:
70
70
  - lib/rubocop/cop/yard/meaningless_tag.rb
71
71
  - lib/rubocop/cop/yard/mismatch_name.rb
72
72
  - lib/rubocop/cop/yard/patch.rb
73
+ - lib/rubocop/cop/yard/struct_param_tag.rb
73
74
  - lib/rubocop/cop/yard/tag_type_position.rb
74
75
  - lib/rubocop/cop/yard/tag_type_syntax.rb
75
76
  - lib/rubocop/cop/yard_cops.rb
@@ -100,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
101
  - !ruby/object:Gem::Version
101
102
  version: '0'
102
103
  requirements: []
103
- rubygems_version: 4.0.10
104
+ rubygems_version: 4.0.16
104
105
  specification_version: 4
105
106
  summary: Check yardoc format.
106
107
  test_files: []