rubocop-yardoc 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c426a883ef24b7fbb8e51fd209e6052c093d154c5ea17266eaae980d9f31299a
4
+ data.tar.gz: b516cccfb30b937874169ca12a344bbb6fd12b878427ddb0bad5c05cda799903
5
+ SHA512:
6
+ metadata.gz: c74648386bcf3bd50f07f884e3530e0ef7e565fdb434a5d809883937738828c77a09ac0947c9adabb6aeb3858541793870e80a9f2eeb0ee5394d353a3fbee41d
7
+ data.tar.gz: 6bb39ddbef6f814afd4d863838f54fb3980e8087e0754a97734e27ac90a1f94036ff93922276a01b2ee2a313bf79cbcc2cd421a5618b5aeee4da8b47999b34f1
data/CHANGELOG.md ADDED
@@ -0,0 +1,21 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2026-08-04
4
+
5
+ - Initial release with following cops:
6
+ - `Yardoc/ClassDescription`: Ensure that classes are documented, with an ignore list of names
7
+ - `Yardoc/ColumnParams`: Ensure that parameters elements are aligned
8
+ - `Yardoc/ConstantDescription`: Ensure that constants are documented, with an ignore list of names
9
+ - `Yardoc/MethodDescription`: Ensure that methods have a description, with an ignore list of names
10
+ - `Yardoc/ModuleDescription`: Ensure that modules are documented, with an ignore list of names
11
+ - `Yardoc/ParamDescriptionCasing`: Ensure that the first letter of a parameter is an uppercase letter
12
+ - `Yardoc/ParamDocumentation`: Ensure that parameters are fully documented (type and description), with an option to
13
+ ignore description
14
+ - `Yardoc/SeparateTagsBlocks`: Ensure consecutive blocks of the same tag are separated with empty spaces from other
15
+ tags
16
+ - `Yardoc/SupportedTags`: Ensure that tags used in documentation are supported by Yardoc (base + custom registered ones),
17
+ with an ignore list
18
+ - `Yardoc/TagOrder`: Ensure that tags follows a defined order in the documentation block, with option to re-define the
19
+ list
20
+ - `Yardoc/YieldDocumentation`: Ensure that blocks and block arguments are documented, with an option to disable
21
+ arguments check.
@@ -0,0 +1,71 @@
1
+ # Code of Conduct - RuboCop Yardoc
2
+
3
+ ## Our pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to make participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, sex characteristics, gender identity and expression,
9
+ level of experience, education, socio-economic status, nationality, personal
10
+ appearance, race, religion, or sexual identity and orientation.
11
+
12
+ ## Our standards
13
+
14
+ Examples of behavior that contributes to a positive environment for our
15
+ community include:
16
+
17
+ * Demonstrating empathy and kindness toward other people
18
+ * Being respectful of differing opinions, viewpoints, and experiences
19
+ * Giving and gracefully accepting constructive feedback
20
+ * Accepting responsibility and apologizing to those affected by our mistakes,
21
+ and learning from the experience
22
+ * Focusing on what is best not just for us as individuals, but for the
23
+ overall community
24
+
25
+ Examples of unacceptable behavior include:
26
+
27
+ * The use of sexualized language or imagery, and sexual attention or
28
+ advances
29
+ * Trolling, insulting or derogatory comments, and personal or political attacks
30
+ * Public or private harassment
31
+ * Publishing others' private information, such as a physical or email
32
+ address, without their explicit permission
33
+ * Other conduct which could reasonably be considered inappropriate in a
34
+ professional setting
35
+
36
+ ## Our responsibilities
37
+
38
+ Project maintainers are responsible for clarifying and enforcing our standards of
39
+ acceptable behavior and will take appropriate and fair corrective action in
40
+ response to any instances of unacceptable behavior.
41
+
42
+ Project maintainers have the right and responsibility to remove, edit, or reject
43
+ comments, commits, code, wiki edits, issues, and other contributions that are
44
+ not aligned to this Code of Conduct, or to ban
45
+ temporarily or permanently any contributor for other behaviors that they deem
46
+ inappropriate, threatening, offensive, or harmful.
47
+
48
+ ## Scope
49
+
50
+ This Code of Conduct applies within all community spaces, and also applies when
51
+ an individual is officially representing the community in public spaces.
52
+ Examples of representing our community include using an official e-mail address,
53
+ posting via an official social media account, or acting as an appointed
54
+ representative at an online or offline event.
55
+
56
+ ## Enforcement
57
+
58
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
59
+ reported to the community leaders responsible for enforcement at
60
+ `contact-project+experimentslabs-rubocop-yardoc-85063958-issue-@incoming.gitlab.com`.
61
+ All complaints will be reviewed and investigated promptly and fairly.
62
+
63
+ All community leaders are obligated to respect the privacy and security of the
64
+ reporter of any incident.
65
+
66
+ ## Attribution
67
+
68
+ This Code of Conduct is adapted from the [Contributor Covenant](https://contributor-covenant.org/), version
69
+ [1.4](https://www.contributor-covenant.org/version/1/4/code-of-conduct/code_of_conduct.md) and
70
+ [2.0](https://www.contributor-covenant.org/version/2/0/code_of_conduct/code_of_conduct.md),
71
+ and was generated by [contributing-gen](https://github.com/bttger/contributing-gen).
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,213 @@
1
+ <!-- omit in toc -->
2
+ # Contributing to RuboCop Yardoc
3
+ <!-- Keep the toc for the documentation app -->
4
+ [[TOC]]
5
+
6
+ First off, thanks for taking the time to contribute! ❤️
7
+
8
+ All types of contributions are encouraged and valued. See the [Table of Contents](#table-of-contents) for different ways
9
+ to help and details about how this project handles them. Please make sure to read the relevant section before making
10
+ your contribution. It will make it a lot easier for us maintainers and smooth out the experience for all involved. The
11
+ community looks forward to your contributions.
12
+
13
+ And if you like the project, but just don't have time to contribute, that's fine. Speaking about it to people that might
14
+ be interested is already a contribution :)
15
+
16
+ <!-- omit in toc -->
17
+ ## Table of contents
18
+
19
+ - [Code of Conduct](#code-of-conduct)
20
+ - [I Have a Question](#i-have-a-question)
21
+ - [I Want To Contribute](#i-want-to-contribute)
22
+ - [Reporting Bugs](#reporting-bugs)
23
+ - [Suggesting Enhancements](#suggesting-enhancements)
24
+ - [Your First Code Contribution](#your-first-code-contribution)
25
+ - [Improving The Documentation](#improving-the-documentation)
26
+ - [Styleguides](#styleguides)
27
+ - [Commit Messages](#commit-messages)
28
+ - [Join The Project Team](#join-the-project-team)
29
+
30
+
31
+ ## Code of conduct
32
+
33
+ This project and everyone participating in it is governed by the
34
+ [Code of Conduct](CODE_OF_CONDUCT.md).
35
+ By participating, you are expected to uphold this code. Please report unacceptable behavior to
36
+ `contact-project+experimentslabs-rubocop-yardoc-85063958-issue-@incoming.gitlab.com`. Received emails are not
37
+ public.
38
+
39
+
40
+ ## I Have a question
41
+
42
+ Before you ask a question, it is best to search for
43
+ existing [Issues](https://gitlab.com/experimentslabs/rubocop-yardoc/-/issues) that might help you. In case
44
+ you have found a suitable issue and still need clarification, you can write your question in this issue. It is also
45
+ advisable to search the internet for answers first.
46
+
47
+ If you then still feel the need to ask a question and need clarification, we recommend the following:
48
+
49
+ - Open an [Issue](https://gitlab.com/experimentslabs/rubocop-yardoc/-/issues/new).
50
+ - Provide as much context as you can about what you're running into (try to fill the provided template).
51
+ - Provide project and platform versions (nodejs, npm, etc), depending on what seems relevant.
52
+
53
+ We will then take care of the issue as soon as possible.
54
+
55
+ You also can reach us on our Matrix chatrooms (listed in the [README](README.md))
56
+
57
+ ## I want to contribute
58
+
59
+ > ### Legal notice <!-- omit in toc -->
60
+ > When contributing to this project, you must agree that you have authored 100% of the content, that you have the
61
+ > necessary rights to the content and that the content you contribute may be provided under the project license.
62
+
63
+ ### Reporting bugs
64
+
65
+ #### Before submitting a bug report
66
+
67
+ A good bug report shouldn't leave others needing to chase you up for more information. Therefore, we ask you to
68
+ investigate carefully, collect information and describe the issue in detail in your report. Please complete the
69
+ following steps in advance to help us fix any potential bug as fast as possible.
70
+
71
+ - Make sure that you are using the latest version.
72
+ - Determine if your bug is really a bug and not an error on your side e.g. using incompatible environment
73
+ components/versions (Make sure that you have read the documentation (check the [README](README.md) for a full list).
74
+ If you are looking for support, you might want to check [this section](#i-have-a-question)).
75
+ - To see if other users have experienced (and potentially already solved) the same issue you are having, check if there
76
+ is not already a bug report existing for your bug or error in
77
+ the [bug tracker](https://gitlab.com/experimentslabs/rubocop-yardoc/-/issues/-/issues?label_name[]=Type%3A%3ABug).
78
+ - Also make sure to search the internet (including Stack Overflow) to see if users outside of the GitLab community have
79
+ discussed the issue.
80
+ - Collect information about the bug:
81
+ - Stack trace (Traceback)
82
+ - OS, Platform and Version (Windows, Linux, macOS, x86, ARM)
83
+ - Version of the interpreter, compiler, SDK, runtime environment, package manager, depending on what seems relevant.
84
+ - Possibly your input and the output
85
+ - Can you reliably reproduce the issue? And can you also reproduce it with older versions?
86
+
87
+ <!-- omit in toc -->
88
+ #### How do I submit a good bug report?
89
+
90
+ > You must never report security related issues, vulnerabilities or bugs including sensitive information to the issue
91
+ > tracker, or elsewhere in public.
92
+ > Instead sensitive bugs must be sent by email to
93
+ > contact-project+experimentslabs-rubocop-yardoc-85063958-issue-@incoming.gitlab.com.
94
+
95
+ We use GitLab issues to track bugs and errors. If you run into an issue with the project:
96
+
97
+ - Open an [Issue](https://gitlab.com/experimentslabs/rubocop-yardoc/-/issues/issues/new). (Since we can't be
98
+ sure at this point whether it is a bug or not, we ask you not to talk about a bug yet and not to label the issue.)
99
+ - Explain the behavior you would expect and the actual behavior.
100
+ - Please provide as much context as possible and describe the *reproduction steps* that someone else can follow to
101
+ recreate the issue on their own. This usually includes your code. For good bug reports you should isolate the problem
102
+ and create a reduced test case.
103
+ - Provide the information you collected in the previous section, in the issue template.
104
+
105
+ Once it's filed:
106
+
107
+ - The project team will label the issue accordingly.
108
+ - A team member will try to reproduce the issue with your provided steps. If there are no reproduction steps or no
109
+ obvious way to reproduce the issue, the team will ask you for those steps and mark the issue
110
+ as `Status::Needs reproduction`. Bugs with the `Status::Needs reproduction` tag will not be addressed until they are
111
+ reproduced.
112
+ - If the team is able to reproduce the issue, it will be marked `Status::Available`, as well as possibly other tags, and
113
+ the issue will be left to be [implemented by someone](#your-first-code-contribution).
114
+
115
+ ### Suggesting enhancements
116
+
117
+ This section guides you through submitting an enhancement suggestion for _RuboCop Yardoc_, **including completely new
118
+ features and minor improvements to existing functionality**.
119
+ Following these guidelines will help maintainers and the community to understand your suggestion and find related
120
+ suggestions.
121
+
122
+ <!-- omit in toc -->
123
+ #### Before submitting an enhancement
124
+
125
+ - Make sure that you are using the latest version.
126
+ - Read the documentation (check the [README](README.md) for a full list) carefully and find out if the functionality is
127
+ already covered, maybe by an individual configuration.
128
+ - Perform a [search](https://gitlab.com/experimentslabs/rubocop-yardoc/-/issues/issues) to see if the
129
+ enhancement has already been suggested. If it has, add a comment to the existing issue instead of opening a new one.
130
+ - Find out whether your idea fits with the scope and aims of the project. It's up to you to make a strong case to
131
+ convince the project's developers of the merits of this feature. Keep in mind that we want features that will be
132
+ useful to the majority of our users and not just a small subset. If you're just targeting a minority of users,
133
+ consider writing an add-on/plugin library.
134
+
135
+ <!-- omit in toc -->
136
+ #### How do I submit a good enhancement suggestion?
137
+
138
+ Enhancement suggestions are tracked as [GitLab issues](https://gitlab.com/experimentslabs/rubocop-yardoc/-/issues).
139
+
140
+ - Use a **clear and descriptive title** for the issue to identify the suggestion. It still may be changed by maintainers
141
+ if they think it's unclear.
142
+ - Provide a **step-by-step description of the suggested enhancement** in as many details as possible.
143
+ - **Describe the current behavior** and **explain which behavior you expected to see instead** and why. At this point
144
+ you can also tell which alternatives do not work for you.
145
+ - You may want to **include screenshots and animated GIFs** which help you demonstrate the steps or point out the part
146
+ which the suggestion is related to. You can use [this tool](https://www.cockos.com/licecap/) to record GIFs on macOS
147
+ and Windows, and [this tool](https://github.com/colinkeenan/silentcast)
148
+ or [this tool](https://github.com/GNOME/byzanz) on Linux.
149
+ - **Explain why this enhancement would be useful** to most RuboCop Yardoc users. You may also want to point out the other
150
+ projects that solved it better and which could serve as inspiration.
151
+
152
+ Maintainers will review the suggestion add the appropriate tags to the ticket as soon as possible.
153
+
154
+ ### Your first code contribution
155
+
156
+ To make a code contribution, you should follow these steps:
157
+
158
+ 1. Fork the repository and clone it on your computer (or synchronize your local fork with the main repository).
159
+ 1. Check the [README](README.md) to get started with the project on your machine
160
+ 1. Create a branch from (`develop`) and make your fixes. Don't forget to add or update tests related to your work. We
161
+ use the [conventional commits](https://www.conventionalcommits.org) specification here for our commit messages.
162
+ 1. Make sure the tests suites and linters pass (RuboCop, RSpec).
163
+ 1. You updated the changelog for non-documentational changes (`CHANGELOG.md`).
164
+ 1. Push your work and open a merge request on the RuboCop Yardoc repository, explaining your changes. The merge request form
165
+ contains templates with a few things to do/keep in mind.
166
+ 1. Check for comments and/or changes requests until a maintainer merges the request.
167
+
168
+ Note that if you're not so comfortable with git, you can state it in the MR, and a maintainer _may_ rebase/cleanup the
169
+ commits.
170
+
171
+ ## Styleguides
172
+
173
+ ### Commit Messages
174
+
175
+ This project follow the [conventional commits](https://www.conventionalcommits.org) specification for commit messages.
176
+
177
+ As a reminder, these _types_ are already used:
178
+
179
+ - `feat` - This commit introduces a new feature or enhancement.
180
+ - `fix` - This commit fixes something.
181
+ - `rework` - This commit does not add anything but makes the code better.
182
+ - `chore` - This commit is a bit boring: code linting, generating files, adding dependencies, splitting files,
183
+ updating, ...
184
+ - `release` - This commit marks a release preparation: changes in the migration guide, changelogs, version bump, ...
185
+
186
+ We are less strict on the _scope_, except for a few of them:
187
+
188
+ - `ruby` - Related to ruby dependencies
189
+
190
+ Beside these two, look at the commit log if you need inspiration
191
+
192
+ ### Markdown
193
+
194
+ There is no tool to enforce Markdown files format, but we try to follow these conventions:
195
+
196
+ - Lines are at most 120 characters long
197
+ - use one dash for emphasis `_text_`
198
+ - use double asterisk for bigger emphasis `**text**`
199
+
200
+ Everything else is pretty free for now.
201
+
202
+ ## Join the project team
203
+
204
+ You want to be part of the maintainers? Great!
205
+
206
+ You will need to have a good general understanding of the project and code, or at least on a part of it.
207
+
208
+ Be a living part of the community by joining the chatrooms (see the [README](README.md) for links), participating on
209
+ issues, and ideally have some merge requests... merged.
210
+
211
+
212
+ ## Attribution
213
+ This guide is based on the **contributing-gen**. [Make your own](https://github.com/bttger/contributing-gen)!
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Experiments Labs / Rubocop Yardoc
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # RuboCop Yardoc
2
+
3
+ A RuboCop plugin to lint documentation comments in Ruby files.
4
+
5
+ ## Community
6
+
7
+ - [Matrix chatroom](https://matrix.to/#/#experimentslabs-general:matrix.org)
8
+
9
+ ## Documentation
10
+
11
+ - Community-related:
12
+ - [Code of conduct](CODE_OF_CONDUCT.md)
13
+ - Development-related:
14
+ - [Contribution guide](CONTRIBUTING.md)
15
+ - _This file_
16
+ - Provided cops: **For now, refer to examples in `lib/rubocop/cop/yardoc/*`.**
17
+
18
+ _Todo_ : Gitlab pages with cop documentation, Markdown cop documentation from sources.
19
+
20
+ ## Installation
21
+
22
+ Install the gem and add to the application's Gemfile by executing:
23
+
24
+ ```bash
25
+ bundle add rubocop-yardoc
26
+ ```
27
+
28
+ If bundler is not being used to manage dependencies, install the gem by executing:
29
+
30
+ ```bash
31
+ gem install rubocop-yardoc
32
+ ```
33
+
34
+ ## Usage
35
+
36
+ Add `rubocop-yardoc` to the plugins list in the RuboCop configuration:
37
+
38
+ ```yml
39
+ # .rubocop.yml
40
+ plugins:
41
+ - rubocop-yardoc
42
+ ```
43
+
44
+ Then, run RuboCop as usual.
45
+
46
+ ## Cops
47
+
48
+ _TODO_
49
+
50
+ ## Development
51
+
52
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can
53
+ also run `bin/console` for an interactive prompt that will allow you to experiment.
54
+
55
+ To install this gem onto your local machine, run `bundle exec rake install`.
56
+
57
+ To release a new version, update the version number in `lib/rubocop/yardoc/version.rb`, and then run
58
+ `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push
59
+ the `.gem` file to [rubygems.org](https://rubygems.org).
60
+
61
+ ## Contributing
62
+
63
+ Bug reports and pull requests are welcome on Gitlab at https://gitlab.com/experimentslabs/rubocop-yardoc.
64
+
65
+ This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to
66
+ the [code of conduct](https://gitlab.com/experimentslabs/rubocop-yardoc/-/blob/main/CODE_OF_CONDUCT.md).
67
+
68
+ ## Code of Conduct
69
+
70
+ Everyone interacting in the RuboCop Yardoc project's codebases, issue trackers, chat rooms and mailing lists is expected
71
+ to follow the [code of conduct](https://gitlab.com/experimentslabs/rubocop-yardoc/-/blob/main/CODE_OF_CONDUCT.md).
@@ -0,0 +1,62 @@
1
+ # This is the default configuration file.
2
+
3
+ Yardoc:
4
+ Enabled: true
5
+ DocumentationBaseURL: __FIXME__
6
+
7
+ Yardoc/ClassDescription:
8
+ Enabled: true
9
+ # Use plain strings or regular expressions to match names and fully qualified names
10
+ Ignore: []
11
+
12
+ Yardoc/ColumnParams:
13
+ Enabled: true
14
+
15
+ Yardoc/ConstantDescription:
16
+ Enabled: true
17
+ # Use plain strings or regular expressions to match names and fully qualified names
18
+ Ignore: []
19
+
20
+ Yardoc/MethodDescription:
21
+ Enabled: true
22
+ DocumentPrivate: true
23
+ # Use plain strings or regular expressions to match names and fully qualified names
24
+ Ignore: []
25
+
26
+ Yardoc/ModuleDescription:
27
+ Enabled: true
28
+ # Use plain strings or regular expressions to match names and fully qualified names
29
+ Ignore: []
30
+
31
+ Yardoc/ParamDescriptionCasing:
32
+ Enabled: true
33
+
34
+ Yardoc/ParamDocumentation:
35
+ Enabled: true
36
+ RequireDescription: true
37
+
38
+ Yardoc/SeparateTagsBlocks:
39
+ Enabled: true
40
+
41
+ Yardoc/SupportedTags:
42
+ Enabled: true
43
+ AdditionalTags: []
44
+
45
+ Yardoc/TagOrder:
46
+ Enabled: true
47
+ Order:
48
+ - deprecated
49
+ - param
50
+ - return
51
+ - yieldparam
52
+ - yieldreturn
53
+ - option
54
+ - raise
55
+ - see
56
+ - since
57
+ - note
58
+ - example
59
+
60
+ Yardoc/YieldDocumentation:
61
+ Enabled: true
62
+ RequireParamDocumentation: true
@@ -0,0 +1,3 @@
1
+ # Configuration for obsoletion.
2
+ #
3
+ # See: https://docs.rubocop.org/rubocop/latest/plugin_configuration.html#config-obsoletions
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ # Helper methods to work with Rubocop node names
6
+ module NodeNameHelp
7
+ # Resolves the fully-qualified name of a module or class node
8
+ # by walking up the ancestor chain.
9
+ #
10
+ # @param node [RuboCop::AST::Node] Module or class node
11
+ #
12
+ # @return [String] Fully-qualified name
13
+ def fully_qualified_name(node)
14
+ parts = []
15
+ current = node
16
+
17
+ while current
18
+ parts.unshift(current.children.first.const_name) if current.module_type? || current.class_type?
19
+ current = current.parent
20
+ end
21
+
22
+ parts.join('::')
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ # Helper methods to work with node parameters
6
+ module ParamHelp
7
+ # Returns the location of "@<tag_name>" of the `comment_line` in the
8
+ # source buffer
9
+ #
10
+ # @param comment_line [Parser::Source::Comment] Comment line
11
+ # @param tag_name [String] Name of the tag
12
+ def start_tag_position(comment_line, tag_name)
13
+ comment_range = comment_line.loc.expression
14
+ at_pos = comment_line.text.index('@')
15
+
16
+ Parser::Source::Range.new processed_source.buffer,
17
+ comment_range.begin_pos + at_pos,
18
+ comment_range.begin_pos + at_pos + tag_name.length + 1
19
+ end
20
+
21
+ # Extracts "@param" tags and their position in comment block
22
+ #
23
+ # @param node [RuboCop::AST::Node] The AST node
24
+ #
25
+ # @return [Array<Hash>]
26
+ def param_tags_and_positions(node) # rubocop:disable Metrics/MethodLength
27
+ node_comments = processed_source.ast_with_comments.fetch(node, [])
28
+ param_tags = yard_tags(node).select { |t| t.tag_name == 'param' }
29
+
30
+ # Try to match extracted yard tags and source comments
31
+ param_tags.map do |param|
32
+ source_comment = node_comments.find { |comment| comment.text.match?(/@param\s+#{param.name}/) }
33
+
34
+ {
35
+ name: param.name,
36
+ source: source_comment.source,
37
+ comment: source_comment,
38
+ yard_tag: param,
39
+ range: start_tag_position(source_comment, 'param'),
40
+ }
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ # Helper methods to work with Yard parsed strings
6
+ module YardHelp
7
+ private
8
+
9
+ # Extracts the YARD docstring immediately preceding a node.
10
+ #
11
+ # @param node [RuboCop::AST::Node] The AST node to find docs for
12
+ #
13
+ # @return [YARD::DocstringParser, nil] Parsed docstring or nil if none found
14
+ def yard_docstring(node)
15
+ comments = processed_source.ast_with_comments[node]
16
+ return nil if comments.nil? || comments.empty?
17
+
18
+ comment_text = comments.map { |c| c.text.sub(/^#\s?/, '') }.join("\n")
19
+ YARD::DocstringParser.new.parse(comment_text)
20
+ end
21
+
22
+ # Returns all YARD tags from the docstring preceding a node.
23
+ #
24
+ # @param node [RuboCop::AST::Node] The AST node
25
+ #
26
+ # @return [Array<YARD::Tags::Tag>] List of tags
27
+ def yard_tags(node)
28
+ docstring = yard_docstring(node)
29
+ return [] if docstring.nil?
30
+
31
+ docstring.tags
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Yardoc
6
+ # Base class that provides shared YARD parsing utilities for all YARD cops.
7
+ class Base < RuboCop::Cop::Base
8
+ private
9
+
10
+ # Checks whether a node has any preceding documentation comments.
11
+ #
12
+ # @param node [RuboCop::AST::Node] The AST node
13
+ #
14
+ # @return [Boolean]
15
+ def documented?(node)
16
+ comments = processed_source.ast_with_comments[node]
17
+ comments && !comments.empty?
18
+ end
19
+
20
+ # Checks whether a name matches any entry in an ignore list from cop configuration.
21
+ # Entries may be plain strings or /regexp/ strings.
22
+ #
23
+ # @param name [String] The fully-qualified name to check
24
+ # @param list [Array<String>] List of names or /pattern/ strings
25
+ #
26
+ # @return [Boolean]
27
+ def ignored?(name, list)
28
+ list.any? do |pattern|
29
+ if pattern.start_with?('/') && pattern.end_with?('/')
30
+ Regexp.new(pattern[1..-2]).match?(name)
31
+ else
32
+ name == pattern
33
+ end
34
+ end
35
+ end
36
+
37
+ # List of symbols ignored for the cop
38
+ def ignore_list
39
+ Array(cop_config['Ignore'])
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end