yard-lint 0.2.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 +7 -0
- data/.coditsu/ci.yml +3 -0
- data/CHANGELOG.md +28 -0
- data/LICENSE.txt +21 -0
- data/README.md +454 -0
- data/bin/console +11 -0
- data/bin/setup +8 -0
- data/bin/yard-lint +109 -0
- data/lib/yard/lint/command_cache.rb +77 -0
- data/lib/yard/lint/config.rb +255 -0
- data/lib/yard/lint/config_loader.rb +198 -0
- data/lib/yard/lint/errors.rb +17 -0
- data/lib/yard/lint/formatters/progress.rb +50 -0
- data/lib/yard/lint/parsers/base.rb +23 -0
- data/lib/yard/lint/parsers/one_line_base.rb +35 -0
- data/lib/yard/lint/parsers/two_line_base.rb +45 -0
- data/lib/yard/lint/result_builder.rb +130 -0
- data/lib/yard/lint/results/aggregate.rb +86 -0
- data/lib/yard/lint/results/base.rb +156 -0
- data/lib/yard/lint/runner.rb +125 -0
- data/lib/yard/lint/validators/base.rb +120 -0
- data/lib/yard/lint/validators/config.rb +30 -0
- data/lib/yard/lint/validators/documentation/undocumented_boolean_methods/config.rb +20 -0
- data/lib/yard/lint/validators/documentation/undocumented_boolean_methods/parser.rb +43 -0
- data/lib/yard/lint/validators/documentation/undocumented_boolean_methods/result.rb +26 -0
- data/lib/yard/lint/validators/documentation/undocumented_boolean_methods/validator.rb +48 -0
- data/lib/yard/lint/validators/documentation/undocumented_boolean_methods.rb +13 -0
- data/lib/yard/lint/validators/documentation/undocumented_method_arguments/config.rb +20 -0
- data/lib/yard/lint/validators/documentation/undocumented_method_arguments/messages_builder.rb +24 -0
- data/lib/yard/lint/validators/documentation/undocumented_method_arguments/parser.rb +45 -0
- data/lib/yard/lint/validators/documentation/undocumented_method_arguments/result.rb +25 -0
- data/lib/yard/lint/validators/documentation/undocumented_method_arguments/validator.rb +55 -0
- data/lib/yard/lint/validators/documentation/undocumented_method_arguments.rb +13 -0
- data/lib/yard/lint/validators/documentation/undocumented_objects/config.rb +21 -0
- data/lib/yard/lint/validators/documentation/undocumented_objects/messages_builder.rb +23 -0
- data/lib/yard/lint/validators/documentation/undocumented_objects/parser.rb +39 -0
- data/lib/yard/lint/validators/documentation/undocumented_objects/result.rb +25 -0
- data/lib/yard/lint/validators/documentation/undocumented_objects/validator.rb +39 -0
- data/lib/yard/lint/validators/documentation/undocumented_objects.rb +14 -0
- data/lib/yard/lint/validators/semantic/abstract_methods/config.rb +24 -0
- data/lib/yard/lint/validators/semantic/abstract_methods/messages_builder.rb +25 -0
- data/lib/yard/lint/validators/semantic/abstract_methods/parser.rb +45 -0
- data/lib/yard/lint/validators/semantic/abstract_methods/result.rb +42 -0
- data/lib/yard/lint/validators/semantic/abstract_methods/validator.rb +65 -0
- data/lib/yard/lint/validators/semantic/abstract_methods.rb +13 -0
- data/lib/yard/lint/validators/tags/api_tags/config.rb +21 -0
- data/lib/yard/lint/validators/tags/api_tags/messages_builder.rb +29 -0
- data/lib/yard/lint/validators/tags/api_tags/parser.rb +50 -0
- data/lib/yard/lint/validators/tags/api_tags/result.rb +42 -0
- data/lib/yard/lint/validators/tags/api_tags/validator.rb +69 -0
- data/lib/yard/lint/validators/tags/api_tags.rb +13 -0
- data/lib/yard/lint/validators/tags/invalid_types/config.rb +22 -0
- data/lib/yard/lint/validators/tags/invalid_types/messages_builder.rb +24 -0
- data/lib/yard/lint/validators/tags/invalid_types/parser.rb +16 -0
- data/lib/yard/lint/validators/tags/invalid_types/result.rb +25 -0
- data/lib/yard/lint/validators/tags/invalid_types/validator.rb +106 -0
- data/lib/yard/lint/validators/tags/invalid_types.rb +13 -0
- data/lib/yard/lint/validators/tags/option_tags/config.rb +21 -0
- data/lib/yard/lint/validators/tags/option_tags/messages_builder.rb +24 -0
- data/lib/yard/lint/validators/tags/option_tags/parser.rb +45 -0
- data/lib/yard/lint/validators/tags/option_tags/result.rb +42 -0
- data/lib/yard/lint/validators/tags/option_tags/validator.rb +61 -0
- data/lib/yard/lint/validators/tags/option_tags.rb +13 -0
- data/lib/yard/lint/validators/tags/order/config.rb +33 -0
- data/lib/yard/lint/validators/tags/order/messages_builder.rb +30 -0
- data/lib/yard/lint/validators/tags/order/parser.rb +66 -0
- data/lib/yard/lint/validators/tags/order/result.rb +26 -0
- data/lib/yard/lint/validators/tags/order/validator.rb +89 -0
- data/lib/yard/lint/validators/tags/order.rb +13 -0
- data/lib/yard/lint/validators/warnings/duplicated_parameter_name/config.rb +22 -0
- data/lib/yard/lint/validators/warnings/duplicated_parameter_name/parser.rb +22 -0
- data/lib/yard/lint/validators/warnings/duplicated_parameter_name/result.rb +25 -0
- data/lib/yard/lint/validators/warnings/duplicated_parameter_name/validator.rb +33 -0
- data/lib/yard/lint/validators/warnings/duplicated_parameter_name.rb +14 -0
- data/lib/yard/lint/validators/warnings/invalid_directive_format/config.rb +22 -0
- data/lib/yard/lint/validators/warnings/invalid_directive_format/parser.rb +22 -0
- data/lib/yard/lint/validators/warnings/invalid_directive_format/result.rb +25 -0
- data/lib/yard/lint/validators/warnings/invalid_directive_format/validator.rb +33 -0
- data/lib/yard/lint/validators/warnings/invalid_directive_format.rb +14 -0
- data/lib/yard/lint/validators/warnings/invalid_tag_format/config.rb +22 -0
- data/lib/yard/lint/validators/warnings/invalid_tag_format/parser.rb +22 -0
- data/lib/yard/lint/validators/warnings/invalid_tag_format/result.rb +25 -0
- data/lib/yard/lint/validators/warnings/invalid_tag_format/validator.rb +33 -0
- data/lib/yard/lint/validators/warnings/invalid_tag_format.rb +14 -0
- data/lib/yard/lint/validators/warnings/unknown_directive/config.rb +22 -0
- data/lib/yard/lint/validators/warnings/unknown_directive/parser.rb +22 -0
- data/lib/yard/lint/validators/warnings/unknown_directive/result.rb +25 -0
- data/lib/yard/lint/validators/warnings/unknown_directive/validator.rb +33 -0
- data/lib/yard/lint/validators/warnings/unknown_directive.rb +14 -0
- data/lib/yard/lint/validators/warnings/unknown_parameter_name/config.rb +22 -0
- data/lib/yard/lint/validators/warnings/unknown_parameter_name/parser.rb +22 -0
- data/lib/yard/lint/validators/warnings/unknown_parameter_name/result.rb +25 -0
- data/lib/yard/lint/validators/warnings/unknown_parameter_name/validator.rb +33 -0
- data/lib/yard/lint/validators/warnings/unknown_parameter_name.rb +14 -0
- data/lib/yard/lint/validators/warnings/unknown_tag/config.rb +22 -0
- data/lib/yard/lint/validators/warnings/unknown_tag/parser.rb +24 -0
- data/lib/yard/lint/validators/warnings/unknown_tag/result.rb +25 -0
- data/lib/yard/lint/validators/warnings/unknown_tag/validator.rb +33 -0
- data/lib/yard/lint/validators/warnings/unknown_tag.rb +14 -0
- data/lib/yard/lint/version.rb +8 -0
- data/lib/yard/lint.rb +76 -0
- data/lib/yard-lint.rb +11 -0
- data/renovate.json +22 -0
- metadata +178 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 43a01c4ffe524ad45bfac735365768a8afaacf812a894c511b7e8d42c475e646
|
|
4
|
+
data.tar.gz: a10ebddfaacdeb54db032121df28c73efc82fae79898fce5b080491e4087c26d
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 00b26fb9a801b71dc13c0e1050f1ecd6db7ce7e777ecfdf1e4916bedbfb63af273186c7a1327a24f371b6e02c18bcd5c51ae8b6fa24e4f0c63f64370021a7418
|
|
7
|
+
data.tar.gz: d7665d29d69631b17d4bfc82e77a08494131490167d9e2124e3b2b625f82ce8c263111448e8a66e0f95d1e87ef976e643480adfbaf915c962251161db0d99f71
|
data/.coditsu/ci.yml
ADDED
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.2.0 (2025-11-07)
|
|
4
|
+
|
|
5
|
+
- Initial release of YARD-Lint gem
|
|
6
|
+
- Comprehensive YARD documentation validation
|
|
7
|
+
- CLI tool (`yard-lint`) for running linter
|
|
8
|
+
- Detects undocumented classes, modules, and methods
|
|
9
|
+
- Validates parameter documentation
|
|
10
|
+
- Validates tag type definitions
|
|
11
|
+
- Enforces tag ordering conventions
|
|
12
|
+
- Validates boolean method documentation
|
|
13
|
+
- Detects YARD warnings (unknown tags, invalid directives, etc.)
|
|
14
|
+
- JSON and text output formats
|
|
15
|
+
- Configurable tag ordering and extra type definitions
|
|
16
|
+
- Ruby API for programmatic usage
|
|
17
|
+
- Result object with offense categorization
|
|
18
|
+
- Three severity levels: error, warning, convention
|
|
19
|
+
- YAML configuration file support (`.yard-lint.yml`)
|
|
20
|
+
- Automatic configuration file discovery
|
|
21
|
+
- File exclusion patterns with glob support
|
|
22
|
+
- Configurable exit code based on severity level
|
|
23
|
+
- Quiet mode (`--quiet`) for minimal output
|
|
24
|
+
- Statistics summary (`--stats`)
|
|
25
|
+
- @api tag validation with configurable allowed APIs
|
|
26
|
+
- @abstract method validation
|
|
27
|
+
- @option hash documentation validation
|
|
28
|
+
- Zeitwerk for automatic code loading
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Maciej Mensfeld
|
|
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
|
|
13
|
+
all 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
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
# YARD-Lint
|
|
2
|
+
|
|
3
|
+
A comprehensive linter for YARD documentation that helps you maintain clean, consistent, and complete documentation in your Ruby and Ruby on Rails projects.
|
|
4
|
+
|
|
5
|
+
## Why Documentation Quality Matters More Than Ever
|
|
6
|
+
|
|
7
|
+
Accurate documentation isn't just for human developers anymore. [Research shows](https://arxiv.org/html/2404.03114) that incorrect documentation reduces AI assistant success rates up to 50% (from 44.7% to 22.1%). [Enterprise studies](https://arxiv.org/html/2501.13282v1) with 400+ developers found well-documented code achieves 30%+ AI acceptance rates versus 14-20% for poorly documented code.
|
|
8
|
+
|
|
9
|
+
**The problem:** Documentation drifts as code changes-parameters get renamed, return types change, but docs stay stale. This doesn't just confuse developers; it trains AI coding assistants to generate confidently wrong code.
|
|
10
|
+
|
|
11
|
+
**The solution:** YARD-Lint automatically validates your YARD documentation stays synchronized with your code, ensuring both human developers and AI tools have accurate context.
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
YARD-Lint validates your YARD documentation for:
|
|
16
|
+
|
|
17
|
+
- **Undocumented code**: Classes, modules, methods, and constants without documentation
|
|
18
|
+
- **Missing parameter documentation**: Methods with undocumented parameters
|
|
19
|
+
- **Invalid tag types**: Type definitions that aren't valid Ruby classes or allowed defaults
|
|
20
|
+
- **Invalid tag ordering**: Tags that don't follow your specified order
|
|
21
|
+
- **Boolean method documentation**: Question mark methods missing return type documentation
|
|
22
|
+
- **API tag validation**: Enforce @api tags on public objects and validate API values
|
|
23
|
+
- **Abstract method validation**: Ensure @abstract methods don't have real implementations
|
|
24
|
+
- **Option hash documentation**: Validate that methods with options parameters have @option tags
|
|
25
|
+
- **YARD warnings**: Unknown tags, invalid directives, duplicated parameter names, and more
|
|
26
|
+
|
|
27
|
+
## Installation
|
|
28
|
+
|
|
29
|
+
Add this line to your application's Gemfile:
|
|
30
|
+
|
|
31
|
+
```ruby
|
|
32
|
+
gem 'yard-lint'
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
And then execute:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
bundle install
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Or install it yourself as:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
gem install yard-lint
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Usage
|
|
48
|
+
|
|
49
|
+
### Command Line
|
|
50
|
+
|
|
51
|
+
Basic usage:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
yard-lint lib/
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
With options:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
# Use a specific config file
|
|
61
|
+
yard-lint --config config/yard-lint.yml lib/
|
|
62
|
+
|
|
63
|
+
# Output as JSON
|
|
64
|
+
yard-lint --format json lib/ > report.json
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Configuration
|
|
68
|
+
|
|
69
|
+
YARD-Lint is configured via a `.yard-lint.yml` configuration file (similar to `.rubocop.yml`).
|
|
70
|
+
|
|
71
|
+
### Configuration File
|
|
72
|
+
|
|
73
|
+
Create a `.yard-lint.yml` file in your project root:
|
|
74
|
+
|
|
75
|
+
```yaml
|
|
76
|
+
# .yard-lint.yml
|
|
77
|
+
# Global settings for all validators
|
|
78
|
+
AllValidators:
|
|
79
|
+
# YARD command-line options (applied to all validators by default)
|
|
80
|
+
YardOptions:
|
|
81
|
+
- --private
|
|
82
|
+
- --protected
|
|
83
|
+
|
|
84
|
+
# Global file exclusion patterns
|
|
85
|
+
Exclude:
|
|
86
|
+
- '\.git'
|
|
87
|
+
- 'vendor/**/*'
|
|
88
|
+
- 'node_modules/**/*'
|
|
89
|
+
- 'spec/**/*'
|
|
90
|
+
|
|
91
|
+
# Exit code behavior (error, warning, convention, never)
|
|
92
|
+
FailOnSeverity: warning
|
|
93
|
+
|
|
94
|
+
# Individual validator configuration
|
|
95
|
+
Documentation/UndocumentedObjects:
|
|
96
|
+
Description: 'Checks for classes, modules, and methods without documentation.'
|
|
97
|
+
Enabled: true
|
|
98
|
+
Severity: warning
|
|
99
|
+
|
|
100
|
+
Documentation/UndocumentedMethodArguments:
|
|
101
|
+
Description: 'Checks for method parameters without @param tags.'
|
|
102
|
+
Enabled: true
|
|
103
|
+
Severity: warning
|
|
104
|
+
|
|
105
|
+
Documentation/UndocumentedBooleanMethods:
|
|
106
|
+
Description: 'Checks that question mark methods document their boolean return.'
|
|
107
|
+
Enabled: true
|
|
108
|
+
Severity: warning
|
|
109
|
+
|
|
110
|
+
Tags/Order:
|
|
111
|
+
Description: 'Enforces consistent ordering of YARD tags.'
|
|
112
|
+
Enabled: true
|
|
113
|
+
Severity: convention
|
|
114
|
+
EnforcedOrder:
|
|
115
|
+
- param
|
|
116
|
+
- option
|
|
117
|
+
- return
|
|
118
|
+
- raise
|
|
119
|
+
- example
|
|
120
|
+
|
|
121
|
+
Tags/InvalidTypes:
|
|
122
|
+
Description: 'Validates type definitions in @param, @return, @option tags.'
|
|
123
|
+
Enabled: true
|
|
124
|
+
Severity: warning
|
|
125
|
+
ValidatedTags:
|
|
126
|
+
- param
|
|
127
|
+
- option
|
|
128
|
+
- return
|
|
129
|
+
ExtraTypes:
|
|
130
|
+
- CustomType
|
|
131
|
+
- MyType
|
|
132
|
+
|
|
133
|
+
Tags/ApiTags:
|
|
134
|
+
Description: 'Enforces @api tags on public objects.'
|
|
135
|
+
Enabled: false # Opt-in validator
|
|
136
|
+
Severity: warning
|
|
137
|
+
AllowedApis:
|
|
138
|
+
- public
|
|
139
|
+
- private
|
|
140
|
+
- internal
|
|
141
|
+
|
|
142
|
+
Tags/OptionTags:
|
|
143
|
+
Description: 'Requires @option tags for methods with options parameters.'
|
|
144
|
+
Enabled: true
|
|
145
|
+
Severity: warning
|
|
146
|
+
|
|
147
|
+
# Warnings validators - catches YARD parser errors
|
|
148
|
+
Warnings/UnknownTag:
|
|
149
|
+
Description: 'Detects unknown YARD tags.'
|
|
150
|
+
Enabled: true
|
|
151
|
+
Severity: error
|
|
152
|
+
|
|
153
|
+
Warnings/UnknownDirective:
|
|
154
|
+
Description: 'Detects unknown YARD directives.'
|
|
155
|
+
Enabled: true
|
|
156
|
+
Severity: error
|
|
157
|
+
|
|
158
|
+
Warnings/InvalidTagFormat:
|
|
159
|
+
Description: 'Detects malformed tag syntax.'
|
|
160
|
+
Enabled: true
|
|
161
|
+
Severity: error
|
|
162
|
+
|
|
163
|
+
Warnings/InvalidDirectiveFormat:
|
|
164
|
+
Description: 'Detects malformed directive syntax.'
|
|
165
|
+
Enabled: true
|
|
166
|
+
Severity: error
|
|
167
|
+
|
|
168
|
+
Warnings/DuplicatedParameterName:
|
|
169
|
+
Description: 'Detects duplicate @param tags.'
|
|
170
|
+
Enabled: true
|
|
171
|
+
Severity: error
|
|
172
|
+
|
|
173
|
+
Warnings/UnknownParameterName:
|
|
174
|
+
Description: 'Detects @param tags for non-existent parameters.'
|
|
175
|
+
Enabled: true
|
|
176
|
+
Severity: error
|
|
177
|
+
|
|
178
|
+
Semantic/AbstractMethods:
|
|
179
|
+
Description: 'Ensures @abstract methods do not have real implementations.'
|
|
180
|
+
Enabled: true
|
|
181
|
+
Severity: warning
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
#### Key Features
|
|
185
|
+
|
|
186
|
+
- **Per-validator control**: Enable/disable and configure each validator independently
|
|
187
|
+
- **Custom severity**: Override severity levels per validator
|
|
188
|
+
- **Per-validator exclusions**: Add validator-specific file exclusions (in addition to global ones)
|
|
189
|
+
- **Per-validator YardOptions**: Override YARD options for specific validators if needed
|
|
190
|
+
- **Inheritance support**: Use `inherit_from` and `inherit_gem` to share configurations
|
|
191
|
+
- **Self-documenting**: Each validator can include a `Description` field
|
|
192
|
+
|
|
193
|
+
#### Configuration Discovery
|
|
194
|
+
|
|
195
|
+
YARD-Lint will automatically search for `.yard-lint.yml` in the current directory and parent directories.
|
|
196
|
+
|
|
197
|
+
You can specify a different config file:
|
|
198
|
+
|
|
199
|
+
```bash
|
|
200
|
+
yard-lint --config path/to/config.yml lib/
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
#### Configuration Inheritance
|
|
204
|
+
|
|
205
|
+
Share configurations across projects using inheritance (like RuboCop):
|
|
206
|
+
|
|
207
|
+
```yaml
|
|
208
|
+
# Inherit from local files
|
|
209
|
+
inherit_from:
|
|
210
|
+
- .yard-lint_todo.yml
|
|
211
|
+
- ../.yard-lint.yml
|
|
212
|
+
|
|
213
|
+
# Inherit from gems
|
|
214
|
+
inherit_gem:
|
|
215
|
+
my-company-style: .yard-lint.yml
|
|
216
|
+
|
|
217
|
+
# Your project-specific overrides
|
|
218
|
+
Documentation/UndocumentedObjects:
|
|
219
|
+
Exclude:
|
|
220
|
+
- 'lib/legacy/**/*'
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
#### Per-Validator Exclusions
|
|
224
|
+
|
|
225
|
+
You can exclude specific files from individual validators while still checking them with other validators. This is useful when you want different validators to apply to different parts of your codebase.
|
|
226
|
+
|
|
227
|
+
**Example: Skip type checking in legacy code**
|
|
228
|
+
|
|
229
|
+
```yaml
|
|
230
|
+
# .yard-lint.yml
|
|
231
|
+
AllValidators:
|
|
232
|
+
Exclude:
|
|
233
|
+
- 'vendor/**/*'
|
|
234
|
+
|
|
235
|
+
# Exclude legacy files from type validation only
|
|
236
|
+
Tags/InvalidTypes:
|
|
237
|
+
Exclude:
|
|
238
|
+
- 'lib/legacy/**/*'
|
|
239
|
+
- 'lib/deprecated/*.rb'
|
|
240
|
+
|
|
241
|
+
# But still check for undocumented methods in those files
|
|
242
|
+
Documentation/UndocumentedObjects:
|
|
243
|
+
Enabled: true
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
**Example: Different rules for different directories**
|
|
247
|
+
|
|
248
|
+
```yaml
|
|
249
|
+
# Strict documentation for public API
|
|
250
|
+
Documentation/UndocumentedMethodArguments:
|
|
251
|
+
Enabled: true
|
|
252
|
+
Exclude:
|
|
253
|
+
- 'lib/internal/**/*'
|
|
254
|
+
- 'spec/**/*'
|
|
255
|
+
|
|
256
|
+
# But enforce @api tags everywhere
|
|
257
|
+
Tags/ApiTags:
|
|
258
|
+
Enabled: true
|
|
259
|
+
Exclude:
|
|
260
|
+
- 'spec/**/*' # Only exclude specs
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
**Example: Override YARD options per validator**
|
|
264
|
+
|
|
265
|
+
```yaml
|
|
266
|
+
AllValidators:
|
|
267
|
+
# Default: only parse public methods
|
|
268
|
+
YardOptions: []
|
|
269
|
+
|
|
270
|
+
# Check all methods (including private) for tag order
|
|
271
|
+
Tags/Order:
|
|
272
|
+
YardOptions:
|
|
273
|
+
- --private
|
|
274
|
+
- --protected
|
|
275
|
+
|
|
276
|
+
# But only require documentation for public methods
|
|
277
|
+
Documentation/UndocumentedObjects:
|
|
278
|
+
YardOptions: [] # Only public methods
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
This allows you to enforce correct tag formatting on all methods while only requiring documentation on public methods.
|
|
282
|
+
|
|
283
|
+
**How it works:**
|
|
284
|
+
|
|
285
|
+
1. **Global exclusions** (defined in `AllValidators/Exclude`) apply to ALL validators
|
|
286
|
+
2. **Per-validator exclusions** (defined in each validator's `Exclude`) apply ONLY to that validator
|
|
287
|
+
3. Both types of exclusions work together - a file must pass both filters to be checked
|
|
288
|
+
|
|
289
|
+
Supported glob patterns:
|
|
290
|
+
- `**/*` - Recursive match (all files in subdirectories)
|
|
291
|
+
- `*.rb` - Simple wildcard
|
|
292
|
+
- `lib/foo/*.rb` - Directory with wildcard
|
|
293
|
+
- `**/test_*.rb` - Recursive with prefix match
|
|
294
|
+
|
|
295
|
+
### Available Validators
|
|
296
|
+
|
|
297
|
+
| Validator | Description | Default | Configuration Options |
|
|
298
|
+
|-----------|-------------|---------|----------------------|
|
|
299
|
+
| **Documentation Validators** |
|
|
300
|
+
| `Documentation/UndocumentedObjects` | Checks for classes, modules, and methods without documentation | Enabled (warning) | `Enabled`, `Severity`, `Exclude` |
|
|
301
|
+
| `Documentation/UndocumentedMethodArguments` | Checks for method parameters without `@param` tags | Enabled (warning) | `Enabled`, `Severity`, `Exclude` |
|
|
302
|
+
| `Documentation/UndocumentedBooleanMethods` | Checks that question mark methods document their boolean return | Enabled (warning) | `Enabled`, `Severity`, `Exclude` |
|
|
303
|
+
| **Tags Validators** |
|
|
304
|
+
| `Tags/Order` | Enforces consistent ordering of YARD tags | Enabled (convention) | `Enabled`, `Severity`, `Exclude`, `EnforcedOrder` |
|
|
305
|
+
| `Tags/InvalidTypes` | Validates type definitions in `@param`, `@return`, `@option` tags | Enabled (warning) | `Enabled`, `Severity`, `Exclude`, `ValidatedTags`, `ExtraTypes` |
|
|
306
|
+
| `Tags/ApiTags` | Enforces `@api` tags on public objects | Disabled (opt-in) | `Enabled`, `Severity`, `Exclude`, `AllowedApis` |
|
|
307
|
+
| `Tags/OptionTags` | Requires `@option` tags for methods with options parameters | Enabled (warning) | `Enabled`, `Severity`, `Exclude` |
|
|
308
|
+
| **Warnings Validators** |
|
|
309
|
+
| `Warnings/UnknownTag` | Detects unknown YARD tags | Enabled (error) | `Enabled`, `Severity`, `Exclude` |
|
|
310
|
+
| `Warnings/UnknownDirective` | Detects unknown YARD directives | Enabled (error) | `Enabled`, `Severity`, `Exclude` |
|
|
311
|
+
| `Warnings/InvalidTagFormat` | Detects malformed tag syntax | Enabled (error) | `Enabled`, `Severity`, `Exclude` |
|
|
312
|
+
| `Warnings/InvalidDirectiveFormat` | Detects malformed directive syntax | Enabled (error) | `Enabled`, `Severity`, `Exclude` |
|
|
313
|
+
| `Warnings/DuplicatedParameterName` | Detects duplicate `@param` tags | Enabled (error) | `Enabled`, `Severity`, `Exclude` |
|
|
314
|
+
| `Warnings/UnknownParameterName` | Detects `@param` tags for non-existent parameters | Enabled (error) | `Enabled`, `Severity`, `Exclude` |
|
|
315
|
+
| **Semantic Validators** |
|
|
316
|
+
| `Semantic/AbstractMethods` | Ensures `@abstract` methods don't have real implementations | Enabled (warning) | `Enabled`, `Severity`, `Exclude` |
|
|
317
|
+
|
|
318
|
+
### Global Configuration
|
|
319
|
+
|
|
320
|
+
| Option | Description | Default | Type |
|
|
321
|
+
|--------|-------------|---------|------|
|
|
322
|
+
| `AllValidators/YardOptions` | YARD command-line options applied to all validators (e.g., `--private`, `--protected`). Can be overridden per-validator. | `[]` | Array of strings |
|
|
323
|
+
| `AllValidators/Exclude` | File patterns to exclude from all validators. Per-validator exclusions are additive. | `['\.git', 'vendor/**/*', 'node_modules/**/*']` | Array of glob patterns |
|
|
324
|
+
| `AllValidators/FailOnSeverity` | Exit with error code for this severity level and above | `warning` | `error`, `warning`, `convention`, or `never` |
|
|
325
|
+
| `<Validator>/YardOptions` | Override YARD options for a specific validator | Inherits from `AllValidators/YardOptions` | Array of strings |
|
|
326
|
+
| `<Validator>/Exclude` | Additional file patterns to exclude for this validator only | `[]` | Array of glob patterns |
|
|
327
|
+
|
|
328
|
+
## Severity Levels
|
|
329
|
+
|
|
330
|
+
| Severity | Description | Examples |
|
|
331
|
+
|----------|-------------|----------|
|
|
332
|
+
| **error** | Critical issues that prevent proper documentation parsing | Unknown tags, invalid formats, malformed syntax, duplicate parameters |
|
|
333
|
+
| **warning** | Missing or incorrect documentation | Undocumented methods, missing `@param` tags, invalid type definitions, semantic issues |
|
|
334
|
+
| **convention** | Style and consistency issues | Tag ordering, formatting preferences |
|
|
335
|
+
|
|
336
|
+
## Integration with CI
|
|
337
|
+
|
|
338
|
+
### GitHub Actions
|
|
339
|
+
|
|
340
|
+
```yaml
|
|
341
|
+
- name: Run YARD Lint
|
|
342
|
+
run: bundle exec yard-lint lib/
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
## CLI Options
|
|
346
|
+
|
|
347
|
+
YARD-Lint supports the following command-line options:
|
|
348
|
+
|
|
349
|
+
```bash
|
|
350
|
+
yard-lint [options] PATH
|
|
351
|
+
|
|
352
|
+
Options:
|
|
353
|
+
-c, --config FILE Path to config file (default: .yard-lint.yml)
|
|
354
|
+
-f, --format FORMAT Output format (text, json)
|
|
355
|
+
-q, --quiet Quiet mode (only show summary)
|
|
356
|
+
--stats Show statistics summary
|
|
357
|
+
--[no-]progress Show progress indicator (default: auto-detect TTY)
|
|
358
|
+
-v, --version Show version
|
|
359
|
+
-h, --help Show this help
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
All configuration (tag order, exclude patterns, severity levels, validator settings) should be defined in `.yard-lint.yml`.
|
|
363
|
+
|
|
364
|
+
## Examples
|
|
365
|
+
|
|
366
|
+
### Check a directory
|
|
367
|
+
|
|
368
|
+
```bash
|
|
369
|
+
yard-lint lib/
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
### Check a single file
|
|
373
|
+
|
|
374
|
+
```bash
|
|
375
|
+
yard-lint lib/my_class.rb
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
### Use custom config file
|
|
379
|
+
|
|
380
|
+
```bash
|
|
381
|
+
yard-lint --config config/yard-lint.yml lib/
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
### Configure fail-on-severity
|
|
385
|
+
|
|
386
|
+
Add to `.yard-lint.yml`:
|
|
387
|
+
```yaml
|
|
388
|
+
AllValidators:
|
|
389
|
+
FailOnSeverity: error # Only fail on errors, not warnings
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
### Enable @api tag validation
|
|
393
|
+
|
|
394
|
+
Add to `.yard-lint.yml`:
|
|
395
|
+
```yaml
|
|
396
|
+
Tags/ApiTags:
|
|
397
|
+
Enabled: true
|
|
398
|
+
AllowedApis:
|
|
399
|
+
- public
|
|
400
|
+
- private
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
This will enforce that all public classes, modules, and methods have an `@api` tag:
|
|
404
|
+
|
|
405
|
+
```ruby
|
|
406
|
+
# Good
|
|
407
|
+
# @api public
|
|
408
|
+
class MyClass
|
|
409
|
+
# @api public
|
|
410
|
+
def public_method
|
|
411
|
+
end
|
|
412
|
+
|
|
413
|
+
# @api private
|
|
414
|
+
def internal_helper
|
|
415
|
+
end
|
|
416
|
+
end
|
|
417
|
+
|
|
418
|
+
# Bad - missing @api tags
|
|
419
|
+
class AnotherClass
|
|
420
|
+
def some_method
|
|
421
|
+
end
|
|
422
|
+
end
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
### @option tag validation (enabled by default)
|
|
426
|
+
|
|
427
|
+
This validator ensures that methods with options parameters document them. It's **enabled by default**. To disable it, add to `.yard-lint.yml`:
|
|
428
|
+
|
|
429
|
+
```yaml
|
|
430
|
+
Tags/OptionTags:
|
|
431
|
+
Enabled: false
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
Examples:
|
|
435
|
+
|
|
436
|
+
```ruby
|
|
437
|
+
# Good
|
|
438
|
+
# @param name [String] the name
|
|
439
|
+
# @param options [Hash] configuration options
|
|
440
|
+
# @option options [Boolean] :enabled Whether to enable the feature
|
|
441
|
+
# @option options [Integer] :timeout Timeout in seconds
|
|
442
|
+
def configure(name, options = {})
|
|
443
|
+
end
|
|
444
|
+
|
|
445
|
+
# Bad - missing @option tags
|
|
446
|
+
# @param name [String] the name
|
|
447
|
+
# @param options [Hash] configuration options
|
|
448
|
+
def configure(name, options = {})
|
|
449
|
+
end
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
## License
|
|
453
|
+
|
|
454
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/bin/console
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "bundler/setup"
|
|
5
|
+
require "yard/lint"
|
|
6
|
+
|
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
9
|
+
|
|
10
|
+
require "irb"
|
|
11
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/bin/yard-lint
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
$LOAD_PATH.unshift File.expand_path('../lib', __dir__)
|
|
5
|
+
|
|
6
|
+
require 'optparse'
|
|
7
|
+
require 'yard-lint'
|
|
8
|
+
|
|
9
|
+
options = {}
|
|
10
|
+
config_file = nil
|
|
11
|
+
|
|
12
|
+
OptionParser.new do |opts|
|
|
13
|
+
opts.banner = 'Usage: yard-lint [options] PATH'
|
|
14
|
+
|
|
15
|
+
opts.on('-c', '--config FILE', 'Path to config file (default: .yard-lint.yml)') do |file|
|
|
16
|
+
config_file = file
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
opts.on('-f', '--format FORMAT', 'Output format (text, json)') do |format|
|
|
20
|
+
options[:format] = format
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
opts.on('-q', '--quiet', 'Quiet mode (only show summary)') do
|
|
24
|
+
options[:quiet] = true
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
opts.on('--stats', 'Show statistics summary') do
|
|
28
|
+
options[:stats] = true
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
opts.on('--[no-]progress', 'Show progress indicator (default: auto)') do |value|
|
|
32
|
+
options[:progress] = value
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
opts.on('-v', '--version', 'Show version') do
|
|
36
|
+
puts "yard-lint #{Yard::Lint::VERSION}"
|
|
37
|
+
exit
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
opts.on('-h', '--help', 'Show this help') do
|
|
41
|
+
puts opts
|
|
42
|
+
exit
|
|
43
|
+
end
|
|
44
|
+
end.parse!
|
|
45
|
+
|
|
46
|
+
# Get path argument
|
|
47
|
+
path = ARGV[0]
|
|
48
|
+
|
|
49
|
+
unless path
|
|
50
|
+
puts 'Error: PATH argument is required'
|
|
51
|
+
puts 'Usage: yard-lint [options] PATH'
|
|
52
|
+
exit 1
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Run the linter with config_file (it will be loaded internally)
|
|
56
|
+
result = Yard::Lint.run(
|
|
57
|
+
path: path,
|
|
58
|
+
config_file: config_file,
|
|
59
|
+
progress: options[:progress]
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
# Format and display results
|
|
63
|
+
case options[:format]
|
|
64
|
+
when 'json'
|
|
65
|
+
require 'json'
|
|
66
|
+
puts JSON.pretty_generate({
|
|
67
|
+
offense_count: result.count,
|
|
68
|
+
offenses: result.offenses
|
|
69
|
+
})
|
|
70
|
+
exit result.exit_code
|
|
71
|
+
when 'text', nil
|
|
72
|
+
if result.clean?
|
|
73
|
+
puts 'No offenses found'
|
|
74
|
+
exit 0
|
|
75
|
+
else
|
|
76
|
+
# Show statistics if requested or in quiet mode
|
|
77
|
+
if options[:stats] || options[:quiet]
|
|
78
|
+
stats = result.statistics
|
|
79
|
+
puts "\n#{result.count} offense(s) detected"
|
|
80
|
+
puts " Errors: #{stats[:error]}"
|
|
81
|
+
puts " Warnings: #{stats[:warning]}"
|
|
82
|
+
puts " Conventions: #{stats[:convention]}"
|
|
83
|
+
puts
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# Show individual offenses unless in quiet mode
|
|
87
|
+
unless options[:quiet]
|
|
88
|
+
puts "Found #{result.count} offense(s):\n\n"
|
|
89
|
+
|
|
90
|
+
result.offenses.each do |offense|
|
|
91
|
+
severity_symbol = case offense[:severity]
|
|
92
|
+
when 'error' then 'E'
|
|
93
|
+
when 'warning' then 'W'
|
|
94
|
+
when 'convention' then 'C'
|
|
95
|
+
else '?'
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
puts "[#{severity_symbol}] #{offense[:location]}:#{offense[:location_line]}"
|
|
99
|
+
puts " #{offense[:name]}: #{offense[:message]}"
|
|
100
|
+
puts
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
exit result.exit_code
|
|
105
|
+
end
|
|
106
|
+
else
|
|
107
|
+
puts "Error: Unknown format '#{options[:format]}'"
|
|
108
|
+
exit 1
|
|
109
|
+
end
|