yard-lint 1.0.0 → 1.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.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +77 -0
  3. data/README.md +160 -268
  4. data/bin/yard-lint +100 -8
  5. data/lib/yard/lint/command_cache.rb +17 -1
  6. data/lib/yard/lint/config.rb +20 -2
  7. data/lib/yard/lint/config_generator.rb +200 -0
  8. data/lib/yard/lint/ext/irb_notifier_shim.rb +95 -0
  9. data/lib/yard/lint/git.rb +125 -0
  10. data/lib/yard/lint/results/aggregate.rb +22 -2
  11. data/lib/yard/lint/runner.rb +4 -3
  12. data/lib/yard/lint/stats_calculator.rb +157 -0
  13. data/lib/yard/lint/validators/base.rb +36 -0
  14. data/lib/yard/lint/validators/documentation/markdown_syntax/config.rb +20 -0
  15. data/lib/yard/lint/validators/documentation/markdown_syntax/messages_builder.rb +44 -0
  16. data/lib/yard/lint/validators/documentation/markdown_syntax/parser.rb +53 -0
  17. data/lib/yard/lint/validators/documentation/markdown_syntax/result.rb +25 -0
  18. data/lib/yard/lint/validators/documentation/markdown_syntax/validator.rb +38 -0
  19. data/lib/yard/lint/validators/documentation/markdown_syntax.rb +37 -0
  20. data/lib/yard/lint/validators/documentation/undocumented_boolean_methods.rb +26 -1
  21. data/lib/yard/lint/validators/documentation/undocumented_method_arguments.rb +26 -1
  22. data/lib/yard/lint/validators/documentation/undocumented_objects.rb +131 -2
  23. data/lib/yard/lint/validators/documentation/undocumented_options/config.rb +20 -0
  24. data/lib/yard/lint/validators/documentation/undocumented_options/parser.rb +53 -0
  25. data/lib/yard/lint/validators/documentation/undocumented_options/result.rb +29 -0
  26. data/lib/yard/lint/validators/documentation/undocumented_options/validator.rb +38 -0
  27. data/lib/yard/lint/validators/documentation/undocumented_options.rb +40 -0
  28. data/lib/yard/lint/validators/semantic/abstract_methods.rb +31 -1
  29. data/lib/yard/lint/validators/tags/api_tags.rb +34 -1
  30. data/lib/yard/lint/validators/tags/collection_type/config.rb +2 -1
  31. data/lib/yard/lint/validators/tags/collection_type/messages_builder.rb +40 -11
  32. data/lib/yard/lint/validators/tags/collection_type/parser.rb +6 -5
  33. data/lib/yard/lint/validators/tags/collection_type/validator.rb +26 -7
  34. data/lib/yard/lint/validators/tags/collection_type.rb +38 -2
  35. data/lib/yard/lint/validators/tags/example_syntax/config.rb +20 -0
  36. data/lib/yard/lint/validators/tags/example_syntax/messages_builder.rb +28 -0
  37. data/lib/yard/lint/validators/tags/example_syntax/parser.rb +79 -0
  38. data/lib/yard/lint/validators/tags/example_syntax/result.rb +42 -0
  39. data/lib/yard/lint/validators/tags/example_syntax/validator.rb +88 -0
  40. data/lib/yard/lint/validators/tags/example_syntax.rb +42 -0
  41. data/lib/yard/lint/validators/tags/invalid_types/validator.rb +2 -2
  42. data/lib/yard/lint/validators/tags/invalid_types.rb +25 -1
  43. data/lib/yard/lint/validators/tags/meaningless_tag/validator.rb +2 -4
  44. data/lib/yard/lint/validators/tags/meaningless_tag.rb +31 -3
  45. data/lib/yard/lint/validators/tags/option_tags/validator.rb +7 -1
  46. data/lib/yard/lint/validators/tags/option_tags.rb +26 -1
  47. data/lib/yard/lint/validators/tags/order.rb +25 -1
  48. data/lib/yard/lint/validators/tags/redundant_param_description/config.rb +33 -0
  49. data/lib/yard/lint/validators/tags/redundant_param_description/messages_builder.rb +61 -0
  50. data/lib/yard/lint/validators/tags/redundant_param_description/parser.rb +67 -0
  51. data/lib/yard/lint/validators/tags/redundant_param_description/result.rb +25 -0
  52. data/lib/yard/lint/validators/tags/redundant_param_description/validator.rb +148 -0
  53. data/lib/yard/lint/validators/tags/redundant_param_description.rb +168 -0
  54. data/lib/yard/lint/validators/tags/tag_type_position/validator.rb +2 -4
  55. data/lib/yard/lint/validators/tags/tag_type_position.rb +39 -2
  56. data/lib/yard/lint/validators/tags/type_syntax.rb +26 -2
  57. data/lib/yard/lint/validators/warnings/duplicated_parameter_name.rb +26 -1
  58. data/lib/yard/lint/validators/warnings/invalid_directive_format.rb +26 -1
  59. data/lib/yard/lint/validators/warnings/invalid_tag_format.rb +25 -1
  60. data/lib/yard/lint/validators/warnings/unknown_directive.rb +26 -1
  61. data/lib/yard/lint/validators/warnings/unknown_parameter_name.rb +23 -1
  62. data/lib/yard/lint/validators/warnings/unknown_tag.rb +26 -1
  63. data/lib/yard/lint/version.rb +1 -1
  64. data/lib/yard/lint.rb +38 -2
  65. data/lib/yard-lint.rb +5 -0
  66. metadata +28 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 312a8649c021c9df03d03240a80da73a5985b692f784bbe1143cf6f7138dbb78
4
- data.tar.gz: ba230c3af103171163396ccc31ac2b4b8fb400b98faba25705072558ee9b71bb
3
+ metadata.gz: 72ea0cf00858078029ca28144f64d7722abcf1a646e1365560542a064a37de24
4
+ data.tar.gz: 2d68009b8610f26b2bfaeb053692f36a714e96ff145cc60c71ed5b2c01c2a43c
5
5
  SHA512:
6
- metadata.gz: d14c94827a3b20f08c283aff9e60f82473dd91522e35f434012cf7b90bd23f7aeaaa3e4f95788d3e7fd32870ac96ee75c953b2bf176c4f38cc44ef9d0cb2e874
7
- data.tar.gz: b8d9bdf4583ea0553b8badd02266d03b402a50926f26492ba1d5c956ee275d2e9fab97bcc773e9d7d160acae76e10746a8103937fa5ea01aeb46e0480fd0a0e2
6
+ metadata.gz: 48313464b85f0d161d39cf151fbbc681fcb5b8271efcc87a371f72199f692c6a75bf24f478dd169ad53babe987c43f88987cc89d51835085db7180eb0906a2f1
7
+ data.tar.gz: c2fa9aa46f81613ee4aacdee0dd6aba4492d61bb9776daf11c7754b94aec7011a5337ccfbe937b136004d240974b0fa336c406d91bb0982dc322235c02b1fdc8
data/CHANGELOG.md CHANGED
@@ -1,5 +1,82 @@
1
1
  # YARD-Lint Changelog
2
2
 
3
+ ## 1.2.0 (2025-11-12)
4
+ - **[Fix]** Add Ruby 3.5+ compatibility without requiring IRB gem dependency
5
+ - Ruby 3.5 moved IRB out of default gems, requiring explicit installation
6
+ - YARD's legacy parser depends on `IRB::Notifier` for debug output
7
+ - Created lightweight `IRB::Notifier` shim to satisfy YARD without full IRB gem
8
+ - Shim tries to load real IRB first, only provides fallback if LoadError occurs
9
+ - Does not override or interfere with real IRB gem when present
10
+ - Safe to use in applications that depend on yard-lint and also use IRB
11
+ - Shim automatically loaded in subprocesses via RUBYOPT environment variable
12
+ - Avoids adding IRB and its transitive dependencies to supply chain
13
+ - All 977 tests pass on Ruby 3.5.0-preview1 without IRB gem
14
+ - **[Feature]** Add Documentation Coverage Statistics with minimum threshold enforcement
15
+ - `--min-coverage PERCENT` - Fail if documentation coverage is below threshold (0-100)
16
+ - `--stats` flag now displays coverage metrics (total objects, documented, undocumented, percentage)
17
+ - `MinCoverage` configuration option in `.yard-lint.yml` under `AllValidators` section
18
+ - CLI flag overrides config file setting for flexibility in CI/CD pipelines
19
+ - Coverage calculation uses YARD queries to count documented vs undocumented objects
20
+ - Works seamlessly with diff mode (--diff, --staged, --changed) to calculate coverage for changed files only
21
+ - Exit code 1 when coverage is below minimum threshold, even if no linting offenses found
22
+ - Summary-only output in --quiet mode shows coverage with pass/fail status
23
+ - Comprehensive unit and integration test coverage for all scenarios
24
+ - Performance optimized with auto-cleanup temp directories for large codebases
25
+ - **[Feature]** Add Diff Mode for incremental linting - only analyze files that changed
26
+ - `--diff [REF]` - Lint only files changed since REF (auto-detects main/master if not specified)
27
+ - `--staged` - Lint only staged files (git index)
28
+ - `--changed` - Lint only uncommitted files
29
+ - Enables practical usage in large legacy codebases
30
+ - Perfect for CI/CD pipelines (only check what changed in PR)
31
+ - Ideal for pre-commit hooks (only check staged files)
32
+ - Auto-detects main/master branch with fallback to master
33
+ - Applies global exclusion patterns to git diff results
34
+ - Silently skips deleted files
35
+ - Returns clean result when no files are changed
36
+ - Uses shell-based git commands via Open3 (no new dependencies)
37
+ - Configuration support via `AllValidators.DiffMode` section
38
+ - Mutually exclusive diff flags (--diff, --staged, --changed)
39
+
40
+ ## 1.1.0 (2025-11-11)
41
+ - **[Feature]** Add `Tags/ExampleSyntax` validator to validate Ruby syntax in `@example` tags
42
+ - Uses Ruby 3.2's `RubyVM::InstructionSequence.compile()` to parse example code
43
+ - Automatically strips output indicators (`#=>`) before validation
44
+ - Intelligently skips incomplete single-line snippets (e.g., `multiply(3, 4)`)
45
+ - Reports multi-line syntax errors with full context from Ruby's parser
46
+ - Enabled by default with 'warning' severity
47
+ - Helps prevent broken code examples in documentation
48
+ - **[Feature]** Add `Tags/RedundantParamDescription` validator to detect meaningless parameter descriptions
49
+ - Detects 7 types of redundant patterns: article+param, possessive, type restatement, param-to-verb, ID pattern, directional date, type+generic
50
+ - Configurable pattern toggles to enable/disable individual pattern types
51
+ - Word count threshold (`MaxRedundantWords`: 6) prevents false positives on longer descriptions
52
+ - Character length threshold (`MinMeaningfulLength`: 15) for additional context
53
+ - Configurable articles list (`Articles`: The, the, A, a, An, an)
54
+ - Configurable generic terms list (`GenericTerms`: object, instance, value, data, item, element)
55
+ - Pattern-specific error messages with actionable suggestions
56
+ - EXACT pattern matching (not prefix) to avoid false positives
57
+ - Enabled by default with 'convention' severity
58
+ - Helps maintain high-quality, meaningful documentation
59
+ - **[Feature]** Add `--init` command to generate `.yard-lint.yml` configuration file with sensible defaults
60
+ - **[Feature]** Add `--force` flag to overwrite existing config file when using `--init`
61
+ - **[Feature]** Add `EnforcedStyle` configuration option to `Tags/CollectionType` validator for bidirectional style enforcement
62
+ - Supports 'long' style: `Hash{K => V}` (default, standard YARD syntax)
63
+ - Supports 'short' style: `{K => V}` (Ruby-like syntax without Hash prefix)
64
+ - Automatically detects violations in either direction and suggests correct style
65
+ - Updated messages to show correct suggestion based on enforced style
66
+ - **[Feature]** Add `Documentation/UndocumentedOptions` validator to detect methods with options hash parameters but no @option tags
67
+ - Detects `options = {}`, `opts = {}`, `**kwargs`, and similar patterns
68
+ - Helps catch missing documentation for option hash parameters
69
+ - Configurable via `Documentation/UndocumentedOptions` in config
70
+ - **[Feature]** Add `Documentation/MarkdownSyntax` validator to detect common markdown syntax errors in documentation
71
+ - Detects unclosed backticks in inline code
72
+ - Detects unclosed code blocks (```)
73
+ - Detects unclosed bold formatting (**)
74
+ - Detects invalid list markers (• instead of - or *)
75
+ - Configurable via `Documentation/MarkdownSyntax` in config
76
+ - [Enhancement] Simplify README by condensing alternative style examples
77
+ - [Documentation] Add Quick Start section to README with `--init` command
78
+ - [Documentation] Update CLI help to show new `--init` and `--force` options
79
+
3
80
  ## 1.0.0 (2025-11-09)
4
81
  - [Fix] Fix "Argument list too long" error on large codebases by using xargs pattern with temporary file lists
5
82
  - [Enhancement] Expand default exclusion patterns to include typical Ruby/Rails directories (test/, log/, coverage/, db/migrate/, etc.)
data/README.md CHANGED
@@ -31,6 +31,8 @@ YARD-Lint validates your YARD documentation for:
31
31
  - **API tag validation**: Enforce @api tags on public objects and validate API values
32
32
  - **Abstract method validation**: Ensure @abstract methods don't have real implementations
33
33
  - **Option hash documentation**: Validate that methods with options parameters have @option tags
34
+ - **Example code syntax validation**: Validates Ruby syntax in `@example` tags to catch broken code examples
35
+ - **Redundant parameter descriptions**: Detects meaningless parameter descriptions that add no value (e.g., `@param user [User] The user`)
34
36
  - **YARD warnings**: Unknown tags, invalid directives, duplicated parameter names, and more
35
37
 
36
38
  ## Installation
@@ -55,6 +57,16 @@ gem install yard-lint
55
57
 
56
58
  ## Usage
57
59
 
60
+ ### Quick Start
61
+
62
+ Generate a default configuration file:
63
+
64
+ ```bash
65
+ yard-lint --init
66
+ ```
67
+
68
+ This creates `.yard-lint.yml` with sensible defaults in your current directory.
69
+
58
70
  ### Command Line
59
71
 
60
72
  Basic usage:
@@ -67,12 +79,124 @@ With options:
67
79
 
68
80
  ```bash
69
81
  # Use a specific config file
70
- yard-lint --config config/yard-lint.yml lib/
82
+ yard-lint lib/ --config config/yard-lint.yml
71
83
 
72
84
  # Output as JSON
73
- yard-lint --format json lib/ > report.json
85
+ yard-lint lib/ --format json > report.json
86
+
87
+ # Generate config file (use --force to overwrite existing)
88
+ yard-lint --init
89
+ yard-lint --init --force
90
+ ```
91
+
92
+ ### Diff Mode (Incremental Linting)
93
+
94
+ Lint only files that changed - perfect for large projects, CI/CD, and pre-commit hooks:
95
+
96
+ ```bash
97
+ # Lint only files changed since main branch (auto-detects main/master)
98
+ yard-lint lib/ --diff
99
+
100
+ # Lint only files changed since specific branch/commit
101
+ yard-lint lib/ --diff develop
102
+ yard-lint lib/ --diff HEAD~3
103
+
104
+ # Lint only staged files (perfect for pre-commit hooks)
105
+ yard-lint lib/ --staged
106
+
107
+ # Lint only uncommitted files
108
+ yard-lint lib/ --changed
109
+ ```
110
+
111
+ **Use Cases:**
112
+
113
+ **Pre-commit Hook:**
114
+ ```bash
115
+ #!/bin/bash
116
+ # .git/hooks/pre-commit
117
+ bundle exec yard-lint lib/ --staged --fail-on-severity error
118
+ ```
119
+
120
+ **GitHub Actions CI/CD:**
121
+ ```yaml
122
+ name: YARD Lint
123
+ on: [pull_request]
124
+ jobs:
125
+ lint:
126
+ runs-on: ubuntu-latest
127
+ steps:
128
+ - uses: actions/checkout@v4
129
+ with:
130
+ fetch-depth: 0 # Need full history for --diff
131
+ - name: Run YARD-Lint on changed files
132
+ run: bundle exec yard-lint lib/ --diff origin/${{ github.base_ref }}
133
+ ```
134
+
135
+ **Legacy Codebase Incremental Adoption:**
136
+ ```bash
137
+ # Only enforce rules on NEW code
138
+ yard-lint lib/ --diff main
139
+ ```
140
+
141
+ ### Documentation Coverage Statistics
142
+
143
+ Monitor and enforce minimum documentation coverage thresholds:
144
+
145
+ ```bash
146
+ # Show coverage statistics with --stats flag
147
+ yard-lint lib/ --stats
148
+
149
+ # Output:
150
+ # Documentation Coverage: 85.5%
151
+ # Total objects: 120
152
+ # Documented: 102
153
+ # Undocumented: 18
154
+
155
+ # Enforce minimum coverage threshold (fails if below)
156
+ yard-lint lib/ --min-coverage 80
157
+
158
+ # Use with diff mode to check coverage only for changed files
159
+ yard-lint lib/ --diff main --min-coverage 90
160
+
161
+ # Quiet mode shows only summary with coverage
162
+ yard-lint lib/ --quiet --min-coverage 80
163
+ ```
164
+
165
+ **Configuration File:**
166
+ ```yaml
167
+ # .yard-lint.yml
168
+ AllValidators:
169
+ # Fail if documentation coverage is below this percentage
170
+ MinCoverage: 80.0
171
+ ```
172
+
173
+ **CI/CD Pipeline Example:**
174
+ ```yaml
175
+ name: Documentation Quality
176
+ on: [pull_request]
177
+ jobs:
178
+ coverage:
179
+ runs-on: ubuntu-latest
180
+ steps:
181
+ - uses: actions/checkout@v4
182
+ with:
183
+ fetch-depth: 0
184
+ - name: Check documentation coverage for new code
185
+ run: |
186
+ bundle exec yard-lint \
187
+ lib/ \
188
+ --diff origin/${{ github.base_ref }} \
189
+ --min-coverage 90 \
190
+ --quiet
74
191
  ```
75
192
 
193
+ **Key Features:**
194
+ - Calculates percentage of documented classes, modules, and methods
195
+ - CLI `--min-coverage` flag overrides config file setting
196
+ - Exit code 1 if coverage is below threshold
197
+ - Works with diff mode to enforce coverage only on changed files
198
+ - Performance optimized with auto-cleanup temp directories for large codebases
199
+
76
200
  ## Configuration
77
201
 
78
202
  YARD-Lint is configured via a `.yard-lint.yml` configuration file (similar to `.rubocop.yml`).
@@ -100,6 +224,13 @@ AllValidators:
100
224
  # Exit code behavior (error, warning, convention, never)
101
225
  FailOnSeverity: warning
102
226
 
227
+ # Diff mode settings
228
+ DiffMode:
229
+ # Default base ref for --diff (auto-detects main/master if not specified)
230
+ DefaultBaseRef: ~
231
+ # Include untracked files in diff mode (not yet implemented)
232
+ IncludeUntracked: false
233
+
103
234
  # Individual validator configuration
104
235
  Documentation/UndocumentedObjects:
105
236
  Description: 'Checks for classes, modules, and methods without documentation.'
@@ -257,7 +388,7 @@ YARD-Lint will automatically search for `.yard-lint.yml` in the current director
257
388
  You can specify a different config file:
258
389
 
259
390
  ```bash
260
- yard-lint --config path/to/config.yml lib/
391
+ yard-lint lib/ --config path/to/config.yml
261
392
  ```
262
393
 
263
394
  #### Configuration Inheritance
@@ -360,6 +491,8 @@ Supported glob patterns:
360
491
  | `Documentation/UndocumentedObjects` | Checks for classes, modules, and methods without documentation | Enabled (warning) | `Enabled`, `Severity`, `Exclude`, `ExcludedMethods` |
361
492
  | `Documentation/UndocumentedMethodArguments` | Checks for method parameters without `@param` tags | Enabled (warning) | `Enabled`, `Severity`, `Exclude` |
362
493
  | `Documentation/UndocumentedBooleanMethods` | Checks that question mark methods document their boolean return | Enabled (warning) | `Enabled`, `Severity`, `Exclude` |
494
+ | `Documentation/UndocumentedOptions` | Detects methods with options hash/kwargs parameters but no `@option` tags | Enabled (warning) | `Enabled`, `Severity`, `Exclude` |
495
+ | `Documentation/MarkdownSyntax` | Detects common markdown syntax errors in documentation (unclosed backticks, invalid list markers, etc.) | Enabled (warning) | `Enabled`, `Severity`, `Exclude` |
363
496
  | **Tags Validators** |
364
497
  | `Tags/Order` | Enforces consistent ordering of YARD tags | Enabled (convention) | `Enabled`, `Severity`, `Exclude`, `EnforcedOrder` |
365
498
  | `Tags/InvalidTypes` | Validates type definitions in `@param`, `@return`, `@option` tags | Enabled (warning) | `Enabled`, `Severity`, `Exclude`, `ValidatedTags`, `ExtraTypes` |
@@ -369,6 +502,8 @@ Supported glob patterns:
369
502
  | `Tags/TagTypePosition` | Validates type annotation position (`@param name [Type]` vs `@param [Type] name`) | Enabled (convention) | `Enabled`, `Severity`, `Exclude`, `CheckedTags`, `EnforcedStyle` |
370
503
  | `Tags/ApiTags` | Enforces `@api` tags on public objects | Disabled (opt-in) | `Enabled`, `Severity`, `Exclude`, `AllowedApis` |
371
504
  | `Tags/OptionTags` | Requires `@option` tags for methods with options parameters | Enabled (warning) | `Enabled`, `Severity`, `Exclude` |
505
+ | `Tags/ExampleSyntax` | Validates Ruby syntax in `@example` tags to catch broken code examples | Enabled (warning) | `Enabled`, `Severity`, `Exclude` |
506
+ | `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` |
372
507
  | **Warnings Validators** |
373
508
  | `Warnings/UnknownTag` | Detects unknown YARD tags | Enabled (error) | `Enabled`, `Severity`, `Exclude` |
374
509
  | `Warnings/UnknownDirective` | Detects unknown YARD directives | Enabled (error) | `Enabled`, `Severity`, `Exclude` |
@@ -379,117 +514,41 @@ Supported glob patterns:
379
514
  | **Semantic Validators** |
380
515
  | `Semantic/AbstractMethods` | Ensures `@abstract` methods don't have real implementations | Enabled (warning) | `Enabled`, `Severity`, `Exclude` |
381
516
 
382
- ### Excluding Methods from Documentation Validation
517
+ ### Detailed Validator Documentation
383
518
 
384
- The `Documentation/UndocumentedObjects` validator supports a flexible `ExcludedMethods` configuration option that allows you to exclude specific methods from documentation requirements. This supports three pattern types:
519
+ For detailed documentation on each validator including configuration examples, pattern types, and troubleshooting guides, see the validator module documentation:
385
520
 
386
- #### Pattern Types
521
+ - Each validator module file in `lib/yard/lint/validators/` contains comprehensive YARD documentation
522
+ - You can browse the source files directly, or generate YARD documentation to view in HTML format:
387
523
 
388
- 1. **Exact Name Matching**
389
- ```yaml
390
- ExcludedMethods:
391
- - 'to_s' # Excludes ALL to_s methods regardless of parameters
392
- - 'inspect' # Excludes ALL inspect methods
393
- ```
394
- Note: Exact name matching excludes the method with **any arity**. If you need arity-specific exclusions, use arity notation instead.
395
-
396
- 2. **Arity Notation** (method_name/N)
397
- ```yaml
398
- ExcludedMethods:
399
- - 'initialize/0' # Only excludes initialize with NO parameters (default)
400
- - 'call/1' # Only excludes call methods with exactly 1 parameter
401
- - 'initialize/2' # Only excludes initialize with exactly 2 parameters
402
- ```
403
- Note: Arity counts total parameters (required + optional) excluding splat (*) and block (&) parameters.
524
+ ```bash
525
+ yard doc lib/yard/lint/validators/**/*.rb
526
+ yard server
527
+ ```
404
528
 
405
- 3. **Regex Patterns**
406
- ```yaml
407
- ExcludedMethods:
408
- - '/^_/' # Excludes all methods starting with underscore (private convention)
409
- - '/^test_/' # Excludes all test methods
410
- - '/_(helper|util)$/' # Excludes methods ending with _helper or _util
411
- ```
529
+ Then open http://localhost:8808 in your browser to browse the full validator documentation with examples.
412
530
 
413
- #### Examples
531
+ ### Quick Configuration Examples
414
532
 
415
533
  ```yaml
416
- # Minimal setup: only exclude parameter-less initialize
417
- Documentation/UndocumentedObjects:
418
- ExcludedMethods:
419
- - 'initialize/0'
420
-
421
- # Common Rails/Ruby patterns
534
+ # Exclude specific methods from documentation requirements
422
535
  Documentation/UndocumentedObjects:
423
536
  ExcludedMethods:
424
537
  - 'initialize/0' # Parameter-less constructors
425
538
  - '/^_/' # Private methods (by convention)
426
539
  - 'to_s' # String conversion
427
- - 'inspect' # Object inspection
428
- - 'hash' # Hash code generation
429
- - 'eql?' # Equality comparison
430
- - '==' # Binary equality operator
431
- - '<=>' # Spaceship operator (comparison)
432
- - '+' # Addition operator
433
- - '-' # Subtraction operator
434
- - '+@' # Unary plus operator
435
- - '-@' # Unary minus operator
436
-
437
- # Test framework exclusions
438
- Documentation/UndocumentedObjects:
439
- ExcludedMethods:
440
- - '/^test_/' # Minitest methods
441
- - '/^should_/' # Shoulda methods
442
- - 'setup/0' # Setup with no params
443
- - 'teardown/0' # Teardown with no params
444
- ```
445
540
 
446
- #### Pattern Validation & Edge Cases
447
-
448
- The `ExcludedMethods` feature includes robust validation and error handling:
449
-
450
- **Automatic Pattern Sanitization:**
451
- - **Nil values** are automatically removed
452
- - **Empty strings** and whitespace-only patterns are filtered out
453
- - **Whitespace trimming** is applied to all patterns
454
- - **Empty regex patterns** (`//`) are rejected (would match everything)
455
- - **Non-array values** are automatically converted to arrays
456
-
457
- **Invalid Pattern Handling:**
458
- - **Invalid regex patterns** (e.g., `/[/`, `/(unclosed`) are silently skipped without crashing
459
- - **Invalid arity notation** (e.g., `method/abc`, `method/`) is silently skipped
460
- - **Pattern matching is case-sensitive** for both exact names and regex
461
-
462
- **Operator Method Support:**
463
- YARD-Lint fully supports Ruby operator methods including:
464
- - Binary operators: `+`, `-`, `*`, `/`, `%`, `**`, `==`, `!=`, `===`, `<`, `>`, `<=`, `>=`, `<=>`, `&`, `|`, `^`, `<<`, `>>`
465
- - Unary operators: `+@`, `-@`, `!`, `~`
466
- - Other special methods: `[]`, `[]=`, `=~`
467
-
468
- **Pattern Matching Behavior:**
469
- - **Any match excludes**: If a method matches any pattern, it is excluded from validation
470
- - **Patterns are evaluated in order** as defined in the configuration
471
- - **Exact names have no arity restriction**: `'initialize'` excludes all initialize methods, regardless of parameters
472
- - **Arity notation is strict**: `'initialize/0'` only excludes initialize with exactly 0 parameters
473
-
474
- #### Troubleshooting ExcludedMethods
475
-
476
- **Methods still showing as undocumented:**
477
- 1. Verify the method name matches exactly (case-sensitive)
478
- 2. Check if you're using arity notation - ensure the arity count is correct
479
- 3. For regex patterns, test your regex independently to ensure it matches
480
- 4. Remember: Arity counts `required + optional` parameters, **excluding** splat (`*args`) and block (`&block`)
481
-
482
- **Regex patterns not working:**
483
- 1. Ensure you're using `/pattern/` format with forward slashes
484
- 2. Test the regex in Ruby: `Regexp.new('your_pattern').match?('method_name')`
485
- 3. Escape special regex characters: `\.`, `\(`, `\)`, `\[`, `\]`, etc.
486
- 4. Invalid regex patterns are silently skipped - check for syntax errors
487
-
488
- **Arity not matching:**
489
- 1. Count parameters correctly: `def method(a, b = 1)` has arity 2 (required + optional)
490
- 2. Splat parameters don't count: `def method(a, *rest)` has arity 1
491
- 3. Block parameters don't count: `def method(a, &block)` has arity 1
492
- 4. Keyword arguments count as individual parameters: `def method(a:, b:)` has arity 2
541
+ # Enable @api tag validation (disabled by default)
542
+ Tags/ApiTags:
543
+ Enabled: true
544
+ AllowedApis:
545
+ - public
546
+ - private
547
+
548
+ # Disable a validator
549
+ Tags/RedundantParamDescription:
550
+ Enabled: false
551
+ ```
493
552
 
494
553
  ### Global Configuration
495
554
 
@@ -537,173 +596,6 @@ Options:
537
596
 
538
597
  All configuration (tag order, exclude patterns, severity levels, validator settings) should be defined in `.yard-lint.yml`.
539
598
 
540
- ## Examples
541
-
542
- ### Check a directory
543
-
544
- ```bash
545
- yard-lint lib/
546
- ```
547
-
548
- ### Check a single file
549
-
550
- ```bash
551
- yard-lint lib/my_class.rb
552
- ```
553
-
554
- ### Use custom config file
555
-
556
- ```bash
557
- yard-lint --config config/yard-lint.yml lib/
558
- ```
559
-
560
- ### Configure fail-on-severity
561
-
562
- Add to `.yard-lint.yml`:
563
- ```yaml
564
- AllValidators:
565
- FailOnSeverity: error # Only fail on errors, not warnings
566
- ```
567
-
568
- ### Enable @api tag validation
569
-
570
- Add to `.yard-lint.yml`:
571
- ```yaml
572
- Tags/ApiTags:
573
- Enabled: true
574
- AllowedApis:
575
- - public
576
- - private
577
- ```
578
-
579
- This will enforce that all public classes, modules, and methods have an `@api` tag:
580
-
581
- ```ruby
582
- # Good
583
- # @api public
584
- class MyClass
585
- # @api public
586
- def public_method
587
- end
588
-
589
- # @api private
590
- def internal_helper
591
- end
592
- end
593
-
594
- # Bad - missing @api tags
595
- class AnotherClass
596
- def some_method
597
- end
598
- end
599
- ```
600
-
601
- ### @option tag validation (enabled by default)
602
-
603
- This validator ensures that methods with options parameters document them. It's **enabled by default**. To disable it, add to `.yard-lint.yml`:
604
-
605
- ```yaml
606
- Tags/OptionTags:
607
- Enabled: false
608
- ```
609
-
610
- Examples:
611
-
612
- ```ruby
613
- # Good
614
- # @param name [String] the name
615
- # @param options [Hash] configuration options
616
- # @option options [Boolean] :enabled Whether to enable the feature
617
- # @option options [Integer] :timeout Timeout in seconds
618
- def configure(name, options = {})
619
- end
620
-
621
- # Bad - missing @option tags
622
- # @param name [String] the name
623
- # @param options [Hash] configuration options
624
- def configure(name, options = {})
625
- end
626
- ```
627
-
628
- ### Meaningless tag validation (enabled by default)
629
-
630
- This validator prevents `@param` and `@option` tags from being used on classes, modules, or constants, where they make no sense (these tags are only valid on methods).
631
-
632
- ```ruby
633
- # Bad - @param on a class
634
- # @param name [String] this makes no sense on a class
635
- class User
636
- end
637
-
638
- # Bad - @option on a module
639
- # @option config [Boolean] :enabled modules don't have parameters
640
- module Authentication
641
- end
642
-
643
- # Good - @param on a method
644
- class User
645
- # @param name [String] the user's name
646
- def initialize(name)
647
- @name = name
648
- end
649
- end
650
- ```
651
-
652
- To disable this validator:
653
-
654
- ```yaml
655
- Tags/MeaninglessTag:
656
- Enabled: false
657
- ```
658
-
659
- ### Collection type syntax validation (enabled by default)
660
-
661
- YARD uses `Hash{K => V}` syntax for hashes, not `Hash<K, V>` (which is generic syntax from other languages). This validator enforces the correct YARD syntax.
662
-
663
- ```ruby
664
- # Bad - using generic syntax
665
- # @param options [Hash<Symbol, String>] configuration
666
- def configure(options)
667
- end
668
-
669
- # Good - using YARD syntax
670
- # @param options [Hash{Symbol => String}] configuration
671
- def configure(options)
672
- end
673
-
674
- # Also good - Array uses angle brackets
675
- # @param items [Array<String>] list of items
676
- def process(items)
677
- end
678
- ```
679
-
680
- To disable this validator:
681
-
682
- ```yaml
683
- Tags/CollectionType:
684
- Enabled: false
685
- ```
686
-
687
- ### Type annotation position validation (enabled by default)
688
-
689
- This validator ensures consistent type annotation positioning. By default, it enforces YARD standard (`@param name [Type]`), but you can configure it to enforce `type_first` style if your team prefers it.
690
-
691
- ```ruby
692
- # Good - type after parameter name (YARD standard)
693
- # @param name [String] the user's name
694
- # @param age [Integer] the user's age
695
- def create_user(name, age)
696
- end
697
-
698
- # Bad - type before parameter name
699
- # @param [String] name the user's name
700
- # @param [Integer] age the user's age
701
- def create_user(name, age)
702
- end
703
- ```
704
-
705
- To use `type_first` style instead, set `EnforcedStyle: type_first` in your `.yard-lint.yml`.
706
-
707
599
  ## License
708
600
 
709
601
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).