yard-lint 1.3.0 → 1.5.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.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -0
  3. data/CHANGELOG.md +73 -3
  4. data/README.md +154 -527
  5. data/Rakefile +11 -8
  6. data/bin/yard-lint +64 -5
  7. data/lib/yard/lint/config.rb +4 -0
  8. data/lib/yard/lint/config_validator.rb +230 -0
  9. data/lib/yard/lint/errors.rb +6 -0
  10. data/lib/yard/lint/executor/in_process_registry.rb +9 -0
  11. data/lib/yard/lint/path_grouper.rb +70 -0
  12. data/lib/yard/lint/result_builder.rb +19 -5
  13. data/lib/yard/lint/results/base.rb +3 -3
  14. data/lib/yard/lint/templates/default_config.yml +31 -0
  15. data/lib/yard/lint/templates/strict_config.yml +31 -0
  16. data/lib/yard/lint/todo_generator.rb +261 -0
  17. data/lib/yard/lint/validators/base.rb +1 -1
  18. data/lib/yard/lint/validators/documentation/missing_return/config.rb +23 -0
  19. data/lib/yard/lint/validators/documentation/missing_return/messages_builder.rb +23 -0
  20. data/lib/yard/lint/validators/documentation/missing_return/parser.rb +128 -0
  21. data/lib/yard/lint/validators/documentation/missing_return/result.rb +25 -0
  22. data/lib/yard/lint/validators/documentation/missing_return/validator.rb +40 -0
  23. data/lib/yard/lint/validators/documentation/missing_return.rb +49 -0
  24. data/lib/yard/lint/validators/documentation/undocumented_boolean_methods/parser.rb +1 -1
  25. data/lib/yard/lint/validators/documentation/undocumented_method_arguments/parser.rb +1 -1
  26. data/lib/yard/lint/validators/documentation/undocumented_method_arguments/validator.rb +3 -0
  27. data/lib/yard/lint/validators/documentation/undocumented_objects/parser.rb +1 -1
  28. data/lib/yard/lint/validators/tags/collection_type/messages_builder.rb +8 -2
  29. data/lib/yard/lint/validators/tags/collection_type/validator.rb +33 -14
  30. data/lib/yard/lint/validators/tags/example_style/config.rb +33 -0
  31. data/lib/yard/lint/validators/tags/example_style/linter_detector.rb +71 -0
  32. data/lib/yard/lint/validators/tags/example_style/messages_builder.rb +29 -0
  33. data/lib/yard/lint/validators/tags/example_style/parser.rb +88 -0
  34. data/lib/yard/lint/validators/tags/example_style/result.rb +42 -0
  35. data/lib/yard/lint/validators/tags/example_style/rubocop_runner.rb +210 -0
  36. data/lib/yard/lint/validators/tags/example_style/validator.rb +87 -0
  37. data/lib/yard/lint/validators/tags/example_style.rb +61 -0
  38. data/lib/yard/lint/validators/tags/forbidden_tags/config.rb +21 -0
  39. data/lib/yard/lint/validators/tags/forbidden_tags/messages_builder.rb +34 -0
  40. data/lib/yard/lint/validators/tags/forbidden_tags/parser.rb +51 -0
  41. data/lib/yard/lint/validators/tags/forbidden_tags/result.rb +28 -0
  42. data/lib/yard/lint/validators/tags/forbidden_tags/validator.rb +66 -0
  43. data/lib/yard/lint/validators/tags/forbidden_tags.rb +68 -0
  44. data/lib/yard/lint/validators/tags/invalid_types/validator.rb +1 -1
  45. data/lib/yard/lint/validators/tags/tag_group_separator/parser.rb +1 -1
  46. data/lib/yard/lint/validators/tags/type_syntax/validator.rb +19 -0
  47. data/lib/yard/lint/validators/warnings/unknown_tag/parser.rb +1 -1
  48. data/lib/yard/lint/version.rb +1 -1
  49. data/mise.toml +2 -0
  50. data/package-lock.json +329 -0
  51. data/package.json +7 -0
  52. data/proxy_types +0 -0
  53. data/renovate.json +18 -1
  54. metadata +30 -3
  55. data/.coditsu/ci.yml +0 -3
data/README.md CHANGED
@@ -15,31 +15,22 @@ Accurate documentation isn't just for human developers anymore. [Research shows]
15
15
 
16
16
  **The solution:** YARD-Lint automatically validates your YARD documentation stays synchronized with your code, ensuring both human developers and AI tools have accurate context.
17
17
 
18
- ## Features
18
+ ## Features Overview
19
19
 
20
20
  YARD-Lint validates your YARD documentation for:
21
21
 
22
- - **Undocumented code**: Classes, modules, methods, and constants without documentation
23
- - **Missing parameter documentation**: Methods with undocumented parameters
24
- - **Invalid tag types**: Type definitions that aren't valid Ruby classes or allowed defaults
25
- - **Invalid type syntax**: Malformed YARD type syntax (unclosed brackets, empty generics, etc.)
26
- - **Non-ASCII type characters**: Detects Unicode characters in type specifications (e.g., `…`, `→`, `—`) that are invalid Ruby identifiers
27
- - **Invalid tag ordering**: Tags that don't follow your specified order
28
- - **Meaningless tags**: `@param` or `@option` tags on classes, modules, or constants (only valid on methods)
29
- - **Collection type syntax**: Enforces `Hash{K => V}` over `Hash<K, V>` (YARD standard)
30
- - **Type annotation position**: Validates whether types appear before or after parameter names (configurable)
31
- - **Boolean method documentation**: Question mark methods missing return type documentation
32
- - **API tag validation**: Enforce @api tags on public objects and validate API values
33
- - **Abstract method validation**: Ensure @abstract methods don't have real implementations
34
- - **Option hash documentation**: Validate that methods with options parameters have @option tags
35
- - **Example code syntax validation**: Validates Ruby syntax in `@example` tags to catch broken code examples
36
- - **Redundant parameter descriptions**: Detects meaningless parameter descriptions that add no value (e.g., `@param user [User] The user`)
37
- - **Empty comment lines**: Detects unnecessary empty `#` lines at the start or end of documentation blocks
38
- - **Blank lines before definitions**: Detects blank lines between YARD documentation and method/class/module definitions (single blank line = convention violation, 2+ blank lines = orphaned documentation that YARD ignores)
39
- - **Informal notation patterns**: Detects `Note:`, `TODO:`, `See:` etc. and suggests proper YARD tags (`@note`, `@todo`, `@see`)
40
- - **Tag group separation**: Enforces blank lines between different YARD tag groups (e.g., between `@param` and `@return` tags) for improved readability
41
- - **YARD warnings**: Unknown tags, invalid directives, duplicated parameter names, and more
42
- - **Smart suggestions**: Provides "did you mean" suggestions for typos in parameter names using Ruby's `did_you_mean` gem with Levenshtein distance fallback
22
+ - **Documentation Completeness** - Undocumented classes, modules, methods, parameters, boolean return values, and missing `@return` tags
23
+ - **Type Accuracy** - Invalid type definitions, malformed type syntax, non-ASCII characters in types, tuple types, and literal types (symbols, strings, numbers)
24
+ - **Tag Validation** - Incorrect tag ordering, meaningless tags, invalid tag positions, unknown tags with suggestions, forbidden tag patterns
25
+ - **Code Examples** - Syntax validation in `@example` tags, optional style validation with RuboCop/StandardRB
26
+ - **Semantic Correctness** - Abstract methods with implementations, redundant descriptions
27
+ - **Style & Formatting** - Empty comment lines, blank lines before definitions, informal notation patterns, tag group separators
28
+ - **Smart Suggestions** - "Did you mean" suggestions for typos in parameter names, tags, and configuration settings
29
+ - **Configuration Safety** - Validates `.yard-lint.yml` for typos and invalid settings before processing
30
+ - **Performance** - In-process YARD execution with shared registry (~10x faster than shell-based execution)
31
+ - **Incremental Adoption** - `--auto-gen-config` generates a baseline todo file to adopt on legacy codebases without fixing everything first
32
+
33
+ **See the complete list:** [All Features](https://github.com/mensfeld/yard-lint/wiki/Features) | [30 Validators](https://github.com/mensfeld/yard-lint/wiki/Validators)
43
34
 
44
35
  ## Installation
45
36
 
@@ -61,655 +52,291 @@ Or install it yourself as:
61
52
  gem install yard-lint
62
53
  ```
63
54
 
64
- ## Usage
55
+ **See also:** [Installation Guide](https://github.com/mensfeld/yard-lint/wiki/Installation) - Platform notes, troubleshooting, upgrading
65
56
 
66
- ### Quick Start
57
+ ## Quick Start
67
58
 
68
- Generate a default configuration file:
59
+ ### Generate Configuration
69
60
 
70
61
  ```bash
62
+ # Create .yard-lint.yml with sensible defaults
71
63
  yard-lint --init
72
- ```
73
-
74
- This creates `.yard-lint.yml` with sensible defaults in your current directory.
75
-
76
- For new projects with high documentation standards, use strict mode:
77
64
 
78
- ```bash
65
+ # For new projects with high standards, use strict mode
79
66
  yard-lint --init --strict
80
67
  ```
81
68
 
82
- This creates a strict configuration with:
83
- - All validators set to `error` severity (no warnings or conventions)
84
- - Minimum documentation coverage set to 100%
85
- - Perfect for bootstrapping new repositories with high quality standards
86
-
87
- After upgrading yard-lint, update your config to include any new validators:
88
-
89
- ```bash
90
- yard-lint --update
91
- ```
92
-
93
- This will:
94
- - Add any new validators introduced in the latest version (with their default settings)
95
- - Remove any obsolete validators that no longer exist
96
- - Preserve all your existing configuration
97
-
98
- ### Command Line
99
-
100
- Basic usage:
69
+ ### Run on Your Codebase
101
70
 
102
71
  ```bash
72
+ # Lint all files in lib/
103
73
  yard-lint lib/
104
74
  ```
105
75
 
106
- With options:
76
+ ### Update Configuration After Upgrading
107
77
 
108
78
  ```bash
109
- # Use a specific config file
110
- yard-lint lib/ --config config/yard-lint.yml
111
-
112
- # Output as JSON
113
- yard-lint lib/ --format json > report.json
79
+ # Add new validators, remove obsolete ones
80
+ yard-lint --update
81
+ ```
114
82
 
115
- # Generate config file (use --force to overwrite existing)
116
- yard-lint --init
117
- yard-lint --init --force
83
+ **Learn more:** [Configuration Guide](https://github.com/mensfeld/yard-lint/wiki/Configuration)
118
84
 
119
- # Generate strict config (all errors, 100% coverage)
120
- yard-lint --init --strict
121
- ```
85
+ ## Common Workflows
122
86
 
123
- ### Diff Mode (Incremental Linting)
87
+ ### Lint Only Changed Files (Diff Mode)
124
88
 
125
- Lint only files that changed - perfect for large projects, CI/CD, and pre-commit hooks:
89
+ Perfect for CI/CD, pre-commit hooks, and legacy codebases:
126
90
 
127
91
  ```bash
128
- # Lint only files changed since main branch (auto-detects main/master)
92
+ # Lint files changed since main branch
129
93
  yard-lint lib/ --diff
130
94
 
131
- # Lint only files changed since specific branch/commit
132
- yard-lint lib/ --diff develop
133
- yard-lint lib/ --diff HEAD~3
134
-
135
- # Lint only staged files (perfect for pre-commit hooks)
95
+ # Lint only staged files (pre-commit hook)
136
96
  yard-lint lib/ --staged
137
97
 
138
- # Lint only uncommitted files
98
+ # Lint uncommitted changes
139
99
  yard-lint lib/ --changed
140
100
  ```
141
101
 
142
- **Use Cases:**
102
+ **Learn more:** [Diff Mode Guide](https://github.com/mensfeld/yard-lint/wiki/Diff-Mode)
143
103
 
144
- **Pre-commit Hook:**
145
- ```bash
146
- #!/bin/bash
147
- # .git/hooks/pre-commit
148
- bundle exec yard-lint lib/ --staged --fail-on-severity error
149
- ```
104
+ ### Adopt on Existing Projects (Incremental Adoption)
150
105
 
151
- **GitHub Actions CI/CD:**
152
- ```yaml
153
- name: YARD Lint
154
- on: [pull_request]
155
- jobs:
156
- lint:
157
- runs-on: ubuntu-latest
158
- steps:
159
- - uses: actions/checkout@v4
160
- with:
161
- fetch-depth: 0 # Need full history for --diff
162
- - name: Run YARD-Lint on changed files
163
- run: bundle exec yard-lint lib/ --diff origin/${{ github.base_ref }}
164
- ```
106
+ For projects with many existing violations, generate a baseline that excludes current issues:
165
107
 
166
- **Legacy Codebase Incremental Adoption:**
167
108
  ```bash
168
- # Only enforce rules on NEW code
169
- yard-lint lib/ --diff main
109
+ # Generate .yard-lint-todo.yml with exclusions for all current violations
110
+ yard-lint --auto-gen-config
111
+
112
+ # Now yard-lint shows no offenses
113
+ yard-lint lib/
114
+
115
+ # Fix violations incrementally by removing exclusions from .yard-lint-todo.yml
170
116
  ```
171
117
 
172
- ### Documentation Coverage Statistics
118
+ **Learn more:** [Incremental Adoption Guide](https://github.com/mensfeld/yard-lint/wiki/Incremental-Adoption)
173
119
 
174
- Monitor and enforce minimum documentation coverage thresholds:
120
+ ### Check Documentation Coverage
175
121
 
176
122
  ```bash
177
- # Show coverage statistics with --stats flag
123
+ # Show coverage statistics
178
124
  yard-lint lib/ --stats
179
125
 
180
- # Output:
181
- # Documentation Coverage: 85.5%
182
- # Total objects: 120
183
- # Documented: 102
184
- # Undocumented: 18
185
-
186
- # Enforce minimum coverage threshold (fails if below)
126
+ # Enforce minimum coverage threshold
187
127
  yard-lint lib/ --min-coverage 80
188
128
 
189
- # Use with diff mode to check coverage only for changed files
129
+ # Combine with diff mode for new code only
190
130
  yard-lint lib/ --diff main --min-coverage 90
191
-
192
- # Quiet mode shows only summary with coverage
193
- yard-lint lib/ --quiet --min-coverage 80
194
- ```
195
-
196
- **Configuration File:**
197
- ```yaml
198
- # .yard-lint.yml
199
- AllValidators:
200
- # Fail if documentation coverage is below this percentage
201
- MinCoverage: 80.0
202
- ```
203
-
204
- **CI/CD Pipeline Example:**
205
- ```yaml
206
- name: Documentation Quality
207
- on: [pull_request]
208
- jobs:
209
- coverage:
210
- runs-on: ubuntu-latest
211
- steps:
212
- - uses: actions/checkout@v4
213
- with:
214
- fetch-depth: 0
215
- - name: Check documentation coverage for new code
216
- run: |
217
- bundle exec yard-lint \
218
- lib/ \
219
- --diff origin/${{ github.base_ref }} \
220
- --min-coverage 90 \
221
- --quiet
222
131
  ```
223
132
 
224
- **Key Features:**
225
- - Calculates percentage of documented classes, modules, and methods
226
- - CLI `--min-coverage` flag overrides config file setting
227
- - Exit code 1 if coverage is below threshold
228
- - Works with diff mode to enforce coverage only on changed files
229
- - Performance optimized with auto-cleanup temp directories for large codebases
230
-
231
- ### Running Specific Validators
232
-
233
- Run only specific validators using the `--only` option - useful for debugging, gradual adoption, or focused CI checks:
133
+ ### Run Specific Validators
234
134
 
235
135
  ```bash
236
136
  # Run only one validator
237
- yard-lint --only Tags/TypeSyntax lib/
137
+ yard-lint lib/ --only Tags/TypeSyntax
238
138
 
239
- # Run multiple validators (comma-separated)
240
- yard-lint --only Tags/Order,Tags/TypeSyntax lib/
241
-
242
- # Combine with other options
243
- yard-lint --only Documentation/UndocumentedObjects --diff main lib/
139
+ # Run multiple validators
140
+ yard-lint lib/ --only Tags/Order,Documentation/UndocumentedObjects
244
141
  ```
245
142
 
246
- ## Configuration
247
-
248
- YARD-Lint is configured via a `.yard-lint.yml` configuration file (similar to `.rubocop.yml`).
143
+ **Learn more:** [Advanced Usage Guide](https://github.com/mensfeld/yard-lint/wiki/Advanced-Usage)
249
144
 
250
- ### Configuration File
145
+ ## Configuration Basics
251
146
 
252
147
  Create a `.yard-lint.yml` file in your project root:
253
148
 
254
149
  ```yaml
255
- # .yard-lint.yml
256
150
  # Global settings for all validators
257
151
  AllValidators:
258
- # YARD command-line options (applied to all validators by default)
152
+ # YARD command-line options
259
153
  YardOptions:
260
154
  - --private
261
155
  - --protected
262
156
 
263
- # Global file exclusion patterns
157
+ # Global file exclusions
264
158
  Exclude:
265
- - '\.git'
266
159
  - 'vendor/**/*'
267
- - 'node_modules/**/*'
268
160
  - 'spec/**/*'
269
161
 
270
162
  # Exit code behavior (error, warning, convention, never)
271
163
  FailOnSeverity: warning
272
164
 
273
- # Diff mode settings
274
- DiffMode:
275
- # Default base ref for --diff (auto-detects main/master if not specified)
276
- DefaultBaseRef: ~
277
- # Include untracked files in diff mode (not yet implemented)
278
- IncludeUntracked: false
165
+ # Minimum documentation coverage percentage
166
+ MinCoverage: 80.0
279
167
 
280
168
  # Individual validator configuration
281
169
  Documentation/UndocumentedObjects:
282
170
  Description: 'Checks for classes, modules, and methods without documentation.'
283
171
  Enabled: true
284
172
  Severity: warning
285
- # List of methods to exclude from validation
286
- # Supports three patterns:
287
- # - Exact names: 'method_name' (excludes all methods with this name)
288
- # - Arity notation: 'method_name/N' (excludes only if method has N parameters)
289
- # - Regex patterns: '/pattern/' (excludes methods matching the regex)
290
173
  ExcludedMethods:
291
- - 'initialize/0' # Exclude only parameter-less initialize (default)
292
- - '/^_/' # Exclude private methods (by convention)
174
+ - 'initialize/0'
175
+ - '/^_/'
293
176
 
294
177
  Documentation/UndocumentedMethodArguments:
295
- Description: 'Checks for method parameters without @param tags.'
296
- Enabled: true
297
- Severity: warning
298
-
299
- Documentation/UndocumentedBooleanMethods:
300
- Description: 'Checks that question mark methods document their boolean return.'
301
178
  Enabled: true
302
179
  Severity: warning
303
180
 
304
181
  Tags/Order:
305
- Description: 'Enforces consistent ordering of YARD tags.'
306
182
  Enabled: true
307
183
  Severity: convention
308
184
  EnforcedOrder:
309
185
  - param
310
186
  - option
187
+ - yield
188
+ - yieldparam
189
+ - yieldreturn
311
190
  - return
312
191
  - raise
192
+ - see
313
193
  - example
194
+ - note
195
+ - todo
314
196
 
315
197
  Tags/InvalidTypes:
316
- Description: 'Validates type definitions in @param, @return, @option tags.'
317
198
  Enabled: true
318
199
  Severity: warning
319
- ValidatedTags:
320
- - param
321
- - option
322
- - return
323
200
  ExtraTypes:
324
201
  - CustomType
325
- - MyType
326
-
327
- Tags/TypeSyntax:
328
- Description: 'Validates YARD type syntax using YARD parser.'
329
- Enabled: true
330
- Severity: warning
331
- ValidatedTags:
332
- - param
333
- - option
334
- - return
335
- - yieldreturn
202
+ - MyNamespace::CustomType
336
203
 
337
- Tags/MeaninglessTag:
338
- Description: 'Detects @param/@option tags on classes, modules, or constants.'
204
+ # Opt-in: Require @return tags on all methods
205
+ Documentation/MissingReturn:
339
206
  Enabled: true
340
207
  Severity: warning
341
- CheckedTags:
342
- - param
343
- - option
344
- InvalidObjectTypes:
345
- - class
346
- - module
347
- - constant
348
-
349
- Tags/CollectionType:
350
- Description: 'Validates Hash collection syntax (enforces Hash{K => V} over Hash<K, V>).'
351
- Enabled: true
352
- Severity: convention
353
- ValidatedTags:
354
- - param
355
- - option
356
- - return
357
- - yieldreturn
208
+ ExcludedMethods:
209
+ - 'initialize'
358
210
 
359
- Tags/TagTypePosition:
360
- Description: 'Validates type annotation position in tags.'
211
+ # Opt-in: Lint @example code style with RuboCop/StandardRB
212
+ Tags/ExampleStyle:
361
213
  Enabled: true
362
214
  Severity: convention
363
- CheckedTags:
364
- - param
365
- - option
366
- # EnforcedStyle: 'type_after_name' (YARD standard: @param name [Type])
367
- # or 'type_first' (@param [Type] name)
368
- EnforcedStyle: type_after_name
369
-
370
- Tags/ApiTags:
371
- Description: 'Enforces @api tags on public objects.'
372
- Enabled: false # Opt-in validator
373
- Severity: warning
374
- AllowedApis:
375
- - public
376
- - private
377
- - internal
378
-
379
- Tags/OptionTags:
380
- Description: 'Requires @option tags for methods with options parameters.'
381
- Enabled: true
382
- Severity: warning
383
-
384
- # Warnings validators - catches YARD parser errors
385
- Warnings/UnknownTag:
386
- Description: 'Detects unknown YARD tags.'
387
- Enabled: true
388
- Severity: error
389
-
390
- Warnings/UnknownDirective:
391
- Description: 'Detects unknown YARD directives.'
392
- Enabled: true
393
- Severity: error
394
-
395
- Warnings/InvalidTagFormat:
396
- Description: 'Detects malformed tag syntax.'
397
- Enabled: true
398
- Severity: error
399
-
400
- Warnings/InvalidDirectiveFormat:
401
- Description: 'Detects malformed directive syntax.'
402
- Enabled: true
403
- Severity: error
404
-
405
- Warnings/DuplicatedParameterName:
406
- Description: 'Detects duplicate @param tags.'
407
- Enabled: true
408
- Severity: error
409
-
410
- Warnings/UnknownParameterName:
411
- Description: 'Detects @param tags for non-existent parameters.'
412
- Enabled: true
413
- Severity: error
414
-
415
- Semantic/AbstractMethods:
416
- Description: 'Ensures @abstract methods do not have real implementations.'
417
- Enabled: true
418
- Severity: warning
419
215
  ```
420
216
 
421
- #### Key Features
422
-
423
- - **Per-validator control**: Enable/disable and configure each validator independently
424
- - **Custom severity**: Override severity levels per validator
425
- - **Per-validator exclusions**: Add validator-specific file exclusions (in addition to global ones)
426
- - **Per-validator YardOptions**: Override YARD options for specific validators if needed
427
- - **Inheritance support**: Use `inherit_from` and `inherit_gem` to share configurations
428
- - **Self-documenting**: Each validator can include a `Description` field
429
-
430
- #### Configuration Discovery
217
+ **Key features:**
218
+ - Per-validator control (enable/disable, severity, exclusions)
219
+ - Configuration inheritance with `inherit_from` and `inherit_gem`
220
+ - Automatic configuration validation with helpful error messages
221
+ - Per-validator YARD options and file exclusions
431
222
 
432
- YARD-Lint will automatically search for `.yard-lint.yml` in the current directory and parent directories.
223
+ **Learn more:** [Complete Configuration Guide](https://github.com/mensfeld/yard-lint/wiki/Configuration)
433
224
 
434
- You can specify a different config file:
435
-
436
- ```bash
437
- yard-lint lib/ --config path/to/config.yml
438
- ```
225
+ ## CI Integration
439
226
 
440
- #### Configuration Inheritance
441
-
442
- Share configurations across projects using inheritance (like RuboCop):
443
-
444
- ```yaml
445
- # Inherit from local files
446
- inherit_from:
447
- - .yard-lint_todo.yml
448
- - ../.yard-lint.yml
449
-
450
- # Inherit from gems
451
- inherit_gem:
452
- my-company-style: .yard-lint.yml
453
-
454
- # Your project-specific overrides
455
- Documentation/UndocumentedObjects:
456
- Exclude:
457
- - 'lib/legacy/**/*'
458
- ```
459
-
460
- #### Per-Validator Exclusions
461
-
462
- 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.
463
-
464
- **Example: Skip type checking in legacy code**
465
-
466
- ```yaml
467
- # .yard-lint.yml
468
- AllValidators:
469
- Exclude:
470
- - 'vendor/**/*'
471
-
472
- # Exclude legacy files from type validation only
473
- Tags/InvalidTypes:
474
- Exclude:
475
- - 'lib/legacy/**/*'
476
- - 'lib/deprecated/*.rb'
477
-
478
- # But still check for undocumented methods in those files
479
- Documentation/UndocumentedObjects:
480
- Enabled: true
481
- ```
482
-
483
- **Example: Different rules for different directories**
227
+ ### GitHub Actions
484
228
 
485
229
  ```yaml
486
- # Strict documentation for public API
487
- Documentation/UndocumentedMethodArguments:
488
- Enabled: true
489
- Exclude:
490
- - 'lib/internal/**/*'
491
- - 'spec/**/*'
492
-
493
- # But enforce @api tags everywhere
494
- Tags/ApiTags:
495
- Enabled: true
496
- Exclude:
497
- - 'spec/**/*' # Only exclude specs
498
- ```
499
-
500
- **Example: Override YARD options per validator**
230
+ name: YARD Lint
231
+ on: [pull_request]
501
232
 
502
- ```yaml
503
- AllValidators:
504
- # Default: only parse public methods
505
- YardOptions: []
233
+ jobs:
234
+ lint:
235
+ runs-on: ubuntu-latest
236
+ steps:
237
+ - uses: actions/checkout@v4
238
+ with:
239
+ fetch-depth: 0 # Needed for --diff
506
240
 
507
- # Check all methods (including private) for tag order
508
- Tags/Order:
509
- YardOptions:
510
- - --private
511
- - --protected
241
+ - name: Set up Ruby
242
+ uses: ruby/setup-ruby@v1
243
+ with:
244
+ ruby-version: '3.2'
245
+ bundler-cache: true
512
246
 
513
- # But only require documentation for public methods
514
- Documentation/UndocumentedObjects:
515
- YardOptions: [] # Only public methods
247
+ - name: Run YARD-Lint on changed files
248
+ run: bundle exec yard-lint lib/ --diff origin/${{ github.base_ref }}
516
249
  ```
517
250
 
518
- This allows you to enforce correct tag formatting on all methods while only requiring documentation on public methods.
519
-
520
- **How it works:**
521
-
522
- 1. **Global exclusions** (defined in `AllValidators/Exclude`) apply to ALL validators
523
- 2. **Per-validator exclusions** (defined in each validator's `Exclude`) apply ONLY to that validator
524
- 3. Both types of exclusions work together - a file must pass both filters to be checked
525
-
526
- Supported glob patterns:
527
- - `**/*` - Recursive match (all files in subdirectories)
528
- - `*.rb` - Simple wildcard
529
- - `lib/foo/*.rb` - Directory with wildcard
530
- - `**/test_*.rb` - Recursive with prefix match
531
-
532
- ### Available Validators
533
-
534
- | Validator | Description | Default | Configuration Options |
535
- |-----------|-------------|---------|----------------------|
536
- | **Documentation Validators** |
537
- | `Documentation/UndocumentedObjects` | Checks for classes, modules, and methods without documentation | Enabled (warning) | `Enabled`, `Severity`, `Exclude`, `ExcludedMethods` |
538
- | `Documentation/UndocumentedMethodArguments` | Checks for method parameters without `@param` tags | Enabled (warning) | `Enabled`, `Severity`, `Exclude` |
539
- | `Documentation/UndocumentedBooleanMethods` | Checks that question mark methods document their boolean return | Enabled (warning) | `Enabled`, `Severity`, `Exclude` |
540
- | `Documentation/UndocumentedOptions` | Detects methods with options hash/kwargs parameters but no `@option` tags | Enabled (warning) | `Enabled`, `Severity`, `Exclude` |
541
- | `Documentation/MarkdownSyntax` | Detects common markdown syntax errors in documentation (unclosed backticks, invalid list markers, etc.) | Enabled (warning) | `Enabled`, `Severity`, `Exclude` |
542
- | `Documentation/EmptyCommentLine` | Detects empty `#` lines at the start or end of documentation blocks | Enabled (convention) | `Enabled`, `Severity`, `Exclude`, `EnabledPatterns` |
543
- | `Documentation/BlankLineBeforeDefinition` | Detects blank lines between documentation and definitions (single blank = convention violation, 2+ blank = orphaned docs) | Enabled (convention) | `Enabled`, `Severity`, `OrphanedSeverity`, `Exclude`, `EnabledPatterns` |
544
- | **Tags Validators** |
545
- | `Tags/Order` | Enforces consistent ordering of YARD tags | Enabled (convention) | `Enabled`, `Severity`, `Exclude`, `EnforcedOrder` |
546
- | `Tags/InvalidTypes` | Validates type definitions in `@param`, `@return`, `@option` tags | Enabled (warning) | `Enabled`, `Severity`, `Exclude`, `ValidatedTags`, `ExtraTypes` |
547
- | `Tags/TypeSyntax` | Validates YARD type syntax (detects unclosed brackets, empty generics, etc.) | Enabled (warning) | `Enabled`, `Severity`, `Exclude`, `ValidatedTags` |
548
- | `Tags/NonAsciiType` | Detects non-ASCII characters in type specifications (e.g., `…`, `→`, `—`) | Enabled (warning) | `Enabled`, `Severity`, `Exclude`, `ValidatedTags` |
549
- | `Tags/MeaninglessTag` | Detects `@param`/`@option` tags on classes, modules, or constants (only valid on methods) | Enabled (warning) | `Enabled`, `Severity`, `Exclude`, `CheckedTags`, `InvalidObjectTypes` |
550
- | `Tags/CollectionType` | Enforces `Hash{K => V}` over `Hash<K, V>` (YARD standard collection syntax) | Enabled (convention) | `Enabled`, `Severity`, `Exclude`, `ValidatedTags` |
551
- | `Tags/TagTypePosition` | Validates type annotation position (`@param name [Type]` vs `@param [Type] name`) | Enabled (convention) | `Enabled`, `Severity`, `Exclude`, `CheckedTags`, `EnforcedStyle` |
552
- | `Tags/ApiTags` | Enforces `@api` tags on public objects | Disabled (opt-in) | `Enabled`, `Severity`, `Exclude`, `AllowedApis` |
553
- | `Tags/OptionTags` | Requires `@option` tags for methods with options parameters | Enabled (warning) | `Enabled`, `Severity`, `Exclude` |
554
- | `Tags/ExampleSyntax` | Validates Ruby syntax in `@example` tags to catch broken code examples | Enabled (warning) | `Enabled`, `Severity`, `Exclude` |
555
- | `Tags/RedundantParamDescription` | Detects meaningless parameter descriptions that add no value beyond the parameter name | Enabled (convention) | `Enabled`, `Severity`, `Exclude`, `CheckedTags`, `Articles`, `MaxRedundantWords`, `MinMeaningfulLength`, `GenericTerms`, `EnabledPatterns` |
556
- | `Tags/InformalNotation` | Detects informal notation patterns (`Note:`, `TODO:`, etc.) and suggests proper YARD tags | Enabled (warning) | `Enabled`, `Severity`, `Exclude`, `CaseSensitive`, `RequireStartOfLine`, `Patterns` |
557
- | `Tags/TagGroupSeparator` | Enforces blank line separators between different YARD tag groups (e.g., between `@param` and `@return` tags) | Disabled (opt-in) | `Enabled`, `Severity`, `Exclude`, `TagGroups`, `RequireAfterDescription` |
558
- | **Warnings Validators** |
559
- | `Warnings/UnknownTag` | Detects unknown YARD tags with "did you mean" suggestions | Enabled (error) | `Enabled`, `Severity`, `Exclude` |
560
- | `Warnings/UnknownDirective` | Detects unknown YARD directives | Enabled (error) | `Enabled`, `Severity`, `Exclude` |
561
- | `Warnings/InvalidTagFormat` | Detects malformed tag syntax | Enabled (error) | `Enabled`, `Severity`, `Exclude` |
562
- | `Warnings/InvalidDirectiveFormat` | Detects malformed directive syntax | Enabled (error) | `Enabled`, `Severity`, `Exclude` |
563
- | `Warnings/DuplicatedParameterName` | Detects duplicate `@param` tags | Enabled (error) | `Enabled`, `Severity`, `Exclude` |
564
- | `Warnings/UnknownParameterName` | Detects `@param` tags for non-existent parameters with "did you mean" suggestions | Enabled (error) | `Enabled`, `Severity`, `Exclude` |
565
- | **Semantic Validators** |
566
- | `Semantic/AbstractMethods` | Ensures `@abstract` methods don't have real implementations | Enabled (warning) | `Enabled`, `Severity`, `Exclude` |
567
-
568
- ### Detailed Validator Documentation
569
-
570
- For detailed documentation on each validator including configuration examples, pattern types, and troubleshooting guides, see the validator module documentation:
571
-
572
- - Each validator module file in `lib/yard/lint/validators/` contains comprehensive YARD documentation
573
- - You can browse the source files directly, or generate YARD documentation to view in HTML format:
251
+ ### Pre-Commit Hook
574
252
 
575
253
  ```bash
576
- yard doc lib/yard/lint/validators/**/*.rb
577
- yard server
578
- ```
579
-
580
- Then open http://localhost:8808 in your browser to browse the full validator documentation with examples.
581
-
582
- ### Smart Suggestions with "Did You Mean"
583
-
584
- YARD-Lint provides intelligent suggestions for common typos in both tag names and parameter names.
585
-
586
- #### Unknown Tag Suggestions
587
-
588
- The `Warnings/UnknownTag` validator suggests correct YARD tags for typos:
589
-
590
- **Example:**
591
-
592
- ```ruby
593
- # @params value [String] should be @param
594
- # @returns [String] should be @return
595
- # @raises [Error] should be @raise
596
- def process(value)
597
- # ...
598
- end
599
- ```
600
-
601
- **Output:**
602
-
603
- ```
604
- lib/processor.rb:10: [error] Unknown tag @params (did you mean '@param'?)
605
- lib/processor.rb:11: [error] Unknown tag @returns (did you mean '@return'?)
606
- lib/processor.rb:12: [error] Unknown tag @raises (did you mean '@raise'?)
607
- ```
608
-
609
- #### Unknown Parameter Suggestions
610
-
611
- The `Warnings/UnknownParameterName` validator suggests correct parameter names:
612
-
613
- **Example:**
614
-
615
- ```ruby
616
- # @param usr_name [String] the username
617
- # @param usr_email [String] the email
618
- def create_user(user_name, user_email)
619
- # ...
620
- end
621
- ```
622
-
623
- **Output:**
624
-
625
- ```
626
- lib/user.rb:123: [error] @param tag has unknown parameter name: usr_name (did you mean 'user_name'?)
627
- lib/user.rb:124: [error] @param tag has unknown parameter name: usr_email (did you mean 'user_email'?)
254
+ #!/bin/bash
255
+ # .git/hooks/pre-commit
256
+ bundle exec yard-lint lib/ --staged --fail-on-severity error
628
257
  ```
629
258
 
630
- **How it works:**
631
- - Uses Ruby's `did_you_mean` gem for intelligent suggestions
632
- - Falls back to Levenshtein distance algorithm when needed
633
- - For parameters: Parses method signatures directly from source files for accurate parameter detection
634
- - Supports all parameter types: regular, keyword, splat, block, and default values
635
- - For tags: Checks against all standard YARD tags and directives
636
-
637
- ### Quick Configuration Examples
259
+ ### GitLab CI
638
260
 
639
261
  ```yaml
640
- # Exclude specific methods from documentation requirements
641
- Documentation/UndocumentedObjects:
642
- ExcludedMethods:
643
- - 'initialize/0' # Parameter-less constructors
644
- - '/^_/' # Private methods (by convention)
645
- - 'to_s' # String conversion
646
-
647
- # Enable @api tag validation (disabled by default)
648
- Tags/ApiTags:
649
- Enabled: true
650
- AllowedApis:
651
- - public
652
- - private
653
-
654
- # Disable a validator
655
- Tags/RedundantParamDescription:
656
- Enabled: false
262
+ yard-lint:
263
+ stage: test
264
+ script:
265
+ - git fetch origin $CI_MERGE_REQUEST_TARGET_BRANCH_NAME
266
+ - bundle exec yard-lint lib/ --diff origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME
267
+ only:
268
+ - merge_requests
657
269
  ```
658
270
 
659
- ### Global Configuration
660
-
661
- | Option | Description | Default | Type |
662
- |--------|-------------|---------|------|
663
- | `AllValidators/YardOptions` | YARD command-line options applied to all validators (e.g., `--private`, `--protected`). Can be overridden per-validator. | `[]` | Array of strings |
664
- | `AllValidators/Exclude` | File patterns to exclude from all validators. Per-validator exclusions are additive. | `['\.git', 'vendor/**/*', 'node_modules/**/*']` | Array of glob patterns |
665
- | `AllValidators/FailOnSeverity` | Exit with error code for this severity level and above | `warning` | `error`, `warning`, `convention`, or `never` |
666
- | `<Validator>/YardOptions` | Override YARD options for a specific validator | Inherits from `AllValidators/YardOptions` | Array of strings |
667
- | `<Validator>/Exclude` | Additional file patterns to exclude for this validator only | `[]` | Array of glob patterns |
668
-
669
- ## Severity Levels
670
-
671
- | Severity | Description | Examples |
672
- |----------|-------------|----------|
673
- | **error** | Critical issues that prevent proper documentation parsing | Unknown tags, invalid formats, malformed syntax, duplicate parameters |
674
- | **warning** | Missing or incorrect documentation | Undocumented methods, missing `@param` tags, invalid type definitions, semantic issues |
675
- | **convention** | Style and consistency issues | Tag ordering, formatting preferences |
676
-
677
- ## Integration with CI
678
-
679
- ### GitHub Actions
680
-
681
- ```yaml
682
- - name: Run YARD Lint
683
- run: bundle exec yard-lint lib/
684
- ```
271
+ **Learn more:** [CI/CD Integration Guide](https://github.com/mensfeld/yard-lint/wiki/CI-CD-Integration) - GitHub Actions, GitLab, CircleCI, Jenkins, hooks, badges
685
272
 
686
273
  ## CLI Options
687
274
 
688
- YARD-Lint supports the following command-line options:
689
-
690
275
  ```bash
691
276
  yard-lint [options] PATH
692
277
 
693
- Options:
278
+ Configuration:
694
279
  -c, --config FILE Path to config file (default: .yard-lint.yml)
280
+
281
+ Output:
695
282
  -f, --format FORMAT Output format (text, json)
696
283
  -q, --quiet Quiet mode (only show summary)
697
- --stats Show statistics summary
698
- --min-coverage N Minimum documentation coverage required (0-100)
284
+ --stats Show documentation coverage statistics
699
285
  --[no-]progress Show progress indicator (default: auto-detect TTY)
286
+
287
+ Coverage:
288
+ --min-coverage N Minimum documentation coverage required (0-100)
289
+
290
+ Diff Mode:
700
291
  --diff [REF] Lint only files changed since REF
701
292
  --staged Lint only staged files
702
293
  --changed Lint only uncommitted files
294
+
295
+ Validators:
703
296
  --only VALIDATORS Run only specified validators (comma-separated)
297
+
298
+ Configuration Generation:
704
299
  --init Generate .yard-lint.yml config file
705
300
  --update Update .yard-lint.yml with new validators
706
301
  --strict Generate strict config (use with --init or --update)
707
302
  --force Force overwrite when using --init
303
+ --auto-gen-config Generate .yard-lint-todo.yml to silence existing violations
304
+ --regenerate-todo Regenerate .yard-lint-todo.yml (overwrites existing)
305
+ --exclude-limit N Min files before grouping into pattern (default: 15)
306
+
307
+ Information:
708
308
  -v, --version Show version
709
309
  -h, --help Show this help
710
310
  ```
711
311
 
712
- All configuration (tag order, exclude patterns, severity levels, validator settings) should be defined in `.yard-lint.yml`.
312
+ **Learn more:** [Advanced Usage](https://github.com/mensfeld/yard-lint/wiki/Advanced-Usage) - CLI reference, JSON output, coverage
313
+
314
+ ## Documentation
315
+
316
+ ### Quick Links
317
+
318
+ - **[Wiki Home](https://github.com/mensfeld/yard-lint/wiki)** - Full documentation
319
+ - **[Installation](https://github.com/mensfeld/yard-lint/wiki/Installation)** - Installation guide
320
+ - **[Configuration](https://github.com/mensfeld/yard-lint/wiki/Configuration)** - Complete configuration reference
321
+ - **[Validators](https://github.com/mensfeld/yard-lint/wiki/Validators)** - All 30 validators documented
322
+ - **[Features](https://github.com/mensfeld/yard-lint/wiki/Features)** - All features explained
323
+
324
+ ### Workflows
325
+
326
+ - **[Incremental Adoption](https://github.com/mensfeld/yard-lint/wiki/Incremental-Adoption)** - Adopt on existing projects
327
+ - **[Diff Mode](https://github.com/mensfeld/yard-lint/wiki/Diff-Mode)** - Lint only changed files
328
+ - **[Advanced Usage](https://github.com/mensfeld/yard-lint/wiki/Advanced-Usage)** - CLI options, coverage, JSON output
329
+
330
+ ### Integration
331
+
332
+ - **[CI/CD Integration](https://github.com/mensfeld/yard-lint/wiki/CI-CD-Integration)** - GitHub Actions, GitLab CI, hooks
333
+ - **[Troubleshooting](https://github.com/mensfeld/yard-lint/wiki/Troubleshooting)** - Common issues and solutions
334
+
335
+ ## Getting Help
336
+
337
+ - **Questions or issues?** Open an issue on [GitHub Issues](https://github.com/mensfeld/yard-lint/issues)
338
+ - **Need configuration help?** See [Configuration Guide](https://github.com/mensfeld/yard-lint/wiki/Configuration)
339
+ - **Common problems?** Check [Troubleshooting](https://github.com/mensfeld/yard-lint/wiki/Troubleshooting)
713
340
 
714
341
  ## License
715
342