yard-lint 1.4.0 → 1.5.1

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