yard-lint 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +40 -0
  3. data/README.md +42 -265
  4. data/bin/yard-lint +20 -0
  5. data/lib/yard/lint/config.rb +0 -2
  6. data/lib/yard/lint/config_generator.rb +191 -0
  7. data/lib/yard/lint/validators/base.rb +36 -0
  8. data/lib/yard/lint/validators/documentation/markdown_syntax/config.rb +20 -0
  9. data/lib/yard/lint/validators/documentation/markdown_syntax/messages_builder.rb +44 -0
  10. data/lib/yard/lint/validators/documentation/markdown_syntax/parser.rb +53 -0
  11. data/lib/yard/lint/validators/documentation/markdown_syntax/result.rb +25 -0
  12. data/lib/yard/lint/validators/documentation/markdown_syntax/validator.rb +38 -0
  13. data/lib/yard/lint/validators/documentation/markdown_syntax.rb +37 -0
  14. data/lib/yard/lint/validators/documentation/undocumented_boolean_methods.rb +26 -1
  15. data/lib/yard/lint/validators/documentation/undocumented_method_arguments.rb +26 -1
  16. data/lib/yard/lint/validators/documentation/undocumented_objects.rb +131 -2
  17. data/lib/yard/lint/validators/documentation/undocumented_options/config.rb +20 -0
  18. data/lib/yard/lint/validators/documentation/undocumented_options/parser.rb +53 -0
  19. data/lib/yard/lint/validators/documentation/undocumented_options/result.rb +29 -0
  20. data/lib/yard/lint/validators/documentation/undocumented_options/validator.rb +38 -0
  21. data/lib/yard/lint/validators/documentation/undocumented_options.rb +40 -0
  22. data/lib/yard/lint/validators/semantic/abstract_methods.rb +31 -1
  23. data/lib/yard/lint/validators/tags/api_tags.rb +34 -1
  24. data/lib/yard/lint/validators/tags/collection_type/config.rb +2 -1
  25. data/lib/yard/lint/validators/tags/collection_type/messages_builder.rb +40 -11
  26. data/lib/yard/lint/validators/tags/collection_type/parser.rb +6 -5
  27. data/lib/yard/lint/validators/tags/collection_type/validator.rb +26 -7
  28. data/lib/yard/lint/validators/tags/collection_type.rb +38 -2
  29. data/lib/yard/lint/validators/tags/example_syntax/config.rb +20 -0
  30. data/lib/yard/lint/validators/tags/example_syntax/messages_builder.rb +28 -0
  31. data/lib/yard/lint/validators/tags/example_syntax/parser.rb +79 -0
  32. data/lib/yard/lint/validators/tags/example_syntax/result.rb +42 -0
  33. data/lib/yard/lint/validators/tags/example_syntax/validator.rb +88 -0
  34. data/lib/yard/lint/validators/tags/example_syntax.rb +42 -0
  35. data/lib/yard/lint/validators/tags/invalid_types/validator.rb +2 -2
  36. data/lib/yard/lint/validators/tags/invalid_types.rb +25 -1
  37. data/lib/yard/lint/validators/tags/meaningless_tag/validator.rb +2 -4
  38. data/lib/yard/lint/validators/tags/meaningless_tag.rb +31 -3
  39. data/lib/yard/lint/validators/tags/option_tags/validator.rb +7 -1
  40. data/lib/yard/lint/validators/tags/option_tags.rb +26 -1
  41. data/lib/yard/lint/validators/tags/order.rb +25 -1
  42. data/lib/yard/lint/validators/tags/redundant_param_description/config.rb +33 -0
  43. data/lib/yard/lint/validators/tags/redundant_param_description/messages_builder.rb +61 -0
  44. data/lib/yard/lint/validators/tags/redundant_param_description/parser.rb +67 -0
  45. data/lib/yard/lint/validators/tags/redundant_param_description/result.rb +25 -0
  46. data/lib/yard/lint/validators/tags/redundant_param_description/validator.rb +148 -0
  47. data/lib/yard/lint/validators/tags/redundant_param_description.rb +168 -0
  48. data/lib/yard/lint/validators/tags/tag_type_position/validator.rb +2 -4
  49. data/lib/yard/lint/validators/tags/tag_type_position.rb +39 -2
  50. data/lib/yard/lint/validators/tags/type_syntax.rb +26 -2
  51. data/lib/yard/lint/validators/warnings/duplicated_parameter_name.rb +26 -1
  52. data/lib/yard/lint/validators/warnings/invalid_directive_format.rb +26 -1
  53. data/lib/yard/lint/validators/warnings/invalid_tag_format.rb +25 -1
  54. data/lib/yard/lint/validators/warnings/unknown_directive.rb +26 -1
  55. data/lib/yard/lint/validators/warnings/unknown_parameter_name.rb +23 -1
  56. data/lib/yard/lint/validators/warnings/unknown_tag.rb +26 -1
  57. data/lib/yard/lint/version.rb +1 -1
  58. metadata +39 -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: 95017b70fd77952580b3bf10466c79efff2fb1bbd353d1ba49ce84eab7feb5e9
4
+ data.tar.gz: 0e5015d8cd2b15b38ccc98d149b3b923997c3952ccc8d799050e51e226d8f14b
5
5
  SHA512:
6
- metadata.gz: d14c94827a3b20f08c283aff9e60f82473dd91522e35f434012cf7b90bd23f7aeaaa3e4f95788d3e7fd32870ac96ee75c953b2bf176c4f38cc44ef9d0cb2e874
7
- data.tar.gz: b8d9bdf4583ea0553b8badd02266d03b402a50926f26492ba1d5c956ee275d2e9fab97bcc773e9d7d160acae76e10746a8103937fa5ea01aeb46e0480fd0a0e2
6
+ metadata.gz: d4825147326c85f9af2faaa95200f797321e06d12bbfe4063ea5b0acd851496bc541546d0885ccdd3d674242670a573be396bc4ae454361a266cadc240c813e8
7
+ data.tar.gz: cb1fa4762efdbecfc0265791a93ffb3ef4a9668e9a6905da29acb966f3bbd650ebd7b21ccb826a5dab2dd972762d4f642e17ecccd986d22354af4837633991cd
data/CHANGELOG.md CHANGED
@@ -1,5 +1,45 @@
1
1
  # YARD-Lint Changelog
2
2
 
3
+ ## 1.1.0 (2025-11-11)
4
+ - **[Feature]** Add `Tags/ExampleSyntax` validator to validate Ruby syntax in `@example` tags
5
+ - Uses Ruby 3.2's `RubyVM::InstructionSequence.compile()` to parse example code
6
+ - Automatically strips output indicators (`#=>`) before validation
7
+ - Intelligently skips incomplete single-line snippets (e.g., `multiply(3, 4)`)
8
+ - Reports multi-line syntax errors with full context from Ruby's parser
9
+ - Enabled by default with 'warning' severity
10
+ - Helps prevent broken code examples in documentation
11
+ - **[Feature]** Add `Tags/RedundantParamDescription` validator to detect meaningless parameter descriptions
12
+ - Detects 7 types of redundant patterns: article+param, possessive, type restatement, param-to-verb, ID pattern, directional date, type+generic
13
+ - Configurable pattern toggles to enable/disable individual pattern types
14
+ - Word count threshold (`MaxRedundantWords`: 6) prevents false positives on longer descriptions
15
+ - Character length threshold (`MinMeaningfulLength`: 15) for additional context
16
+ - Configurable articles list (`Articles`: The, the, A, a, An, an)
17
+ - Configurable generic terms list (`GenericTerms`: object, instance, value, data, item, element)
18
+ - Pattern-specific error messages with actionable suggestions
19
+ - EXACT pattern matching (not prefix) to avoid false positives
20
+ - Enabled by default with 'convention' severity
21
+ - Helps maintain high-quality, meaningful documentation
22
+ - **[Feature]** Add `--init` command to generate `.yard-lint.yml` configuration file with sensible defaults
23
+ - **[Feature]** Add `--force` flag to overwrite existing config file when using `--init`
24
+ - **[Feature]** Add `EnforcedStyle` configuration option to `Tags/CollectionType` validator for bidirectional style enforcement
25
+ - Supports 'long' style: `Hash{K => V}` (default, standard YARD syntax)
26
+ - Supports 'short' style: `{K => V}` (Ruby-like syntax without Hash prefix)
27
+ - Automatically detects violations in either direction and suggests correct style
28
+ - Updated messages to show correct suggestion based on enforced style
29
+ - **[Feature]** Add `Documentation/UndocumentedOptions` validator to detect methods with options hash parameters but no @option tags
30
+ - Detects `options = {}`, `opts = {}`, `**kwargs`, and similar patterns
31
+ - Helps catch missing documentation for option hash parameters
32
+ - Configurable via `Documentation/UndocumentedOptions` in config
33
+ - **[Feature]** Add `Documentation/MarkdownSyntax` validator to detect common markdown syntax errors in documentation
34
+ - Detects unclosed backticks in inline code
35
+ - Detects unclosed code blocks (```)
36
+ - Detects unclosed bold formatting (**)
37
+ - Detects invalid list markers (• instead of - or *)
38
+ - Configurable via `Documentation/MarkdownSyntax` in config
39
+ - [Enhancement] Simplify README by condensing alternative style examples
40
+ - [Documentation] Add Quick Start section to README with `--init` command
41
+ - [Documentation] Update CLI help to show new `--init` and `--force` options
42
+
3
43
  ## 1.0.0 (2025-11-09)
4
44
  - [Fix] Fix "Argument list too long" error on large codebases by using xargs pattern with temporary file lists
5
45
  - [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:
@@ -71,6 +83,10 @@ yard-lint --config config/yard-lint.yml lib/
71
83
 
72
84
  # Output as JSON
73
85
  yard-lint --format json lib/ > report.json
86
+
87
+ # Generate config file (use --force to overwrite existing)
88
+ yard-lint --init
89
+ yard-lint --init --force
74
90
  ```
75
91
 
76
92
  ## Configuration
@@ -360,6 +376,8 @@ Supported glob patterns:
360
376
  | `Documentation/UndocumentedObjects` | Checks for classes, modules, and methods without documentation | Enabled (warning) | `Enabled`, `Severity`, `Exclude`, `ExcludedMethods` |
361
377
  | `Documentation/UndocumentedMethodArguments` | Checks for method parameters without `@param` tags | Enabled (warning) | `Enabled`, `Severity`, `Exclude` |
362
378
  | `Documentation/UndocumentedBooleanMethods` | Checks that question mark methods document their boolean return | Enabled (warning) | `Enabled`, `Severity`, `Exclude` |
379
+ | `Documentation/UndocumentedOptions` | Detects methods with options hash/kwargs parameters but no `@option` tags | Enabled (warning) | `Enabled`, `Severity`, `Exclude` |
380
+ | `Documentation/MarkdownSyntax` | Detects common markdown syntax errors in documentation (unclosed backticks, invalid list markers, etc.) | Enabled (warning) | `Enabled`, `Severity`, `Exclude` |
363
381
  | **Tags Validators** |
364
382
  | `Tags/Order` | Enforces consistent ordering of YARD tags | Enabled (convention) | `Enabled`, `Severity`, `Exclude`, `EnforcedOrder` |
365
383
  | `Tags/InvalidTypes` | Validates type definitions in `@param`, `@return`, `@option` tags | Enabled (warning) | `Enabled`, `Severity`, `Exclude`, `ValidatedTags`, `ExtraTypes` |
@@ -369,6 +387,8 @@ Supported glob patterns:
369
387
  | `Tags/TagTypePosition` | Validates type annotation position (`@param name [Type]` vs `@param [Type] name`) | Enabled (convention) | `Enabled`, `Severity`, `Exclude`, `CheckedTags`, `EnforcedStyle` |
370
388
  | `Tags/ApiTags` | Enforces `@api` tags on public objects | Disabled (opt-in) | `Enabled`, `Severity`, `Exclude`, `AllowedApis` |
371
389
  | `Tags/OptionTags` | Requires `@option` tags for methods with options parameters | Enabled (warning) | `Enabled`, `Severity`, `Exclude` |
390
+ | `Tags/ExampleSyntax` | Validates Ruby syntax in `@example` tags to catch broken code examples | Enabled (warning) | `Enabled`, `Severity`, `Exclude` |
391
+ | `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
392
  | **Warnings Validators** |
373
393
  | `Warnings/UnknownTag` | Detects unknown YARD tags | Enabled (error) | `Enabled`, `Severity`, `Exclude` |
374
394
  | `Warnings/UnknownDirective` | Detects unknown YARD directives | Enabled (error) | `Enabled`, `Severity`, `Exclude` |
@@ -379,117 +399,41 @@ Supported glob patterns:
379
399
  | **Semantic Validators** |
380
400
  | `Semantic/AbstractMethods` | Ensures `@abstract` methods don't have real implementations | Enabled (warning) | `Enabled`, `Severity`, `Exclude` |
381
401
 
382
- ### Excluding Methods from Documentation Validation
383
-
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:
402
+ ### Detailed Validator Documentation
385
403
 
386
- #### Pattern Types
404
+ For detailed documentation on each validator including configuration examples, pattern types, and troubleshooting guides, see the validator module documentation:
387
405
 
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.
406
+ - Each validator module file in `lib/yard/lint/validators/` contains comprehensive YARD documentation
407
+ - You can browse the source files directly, or generate YARD documentation to view in HTML format:
395
408
 
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.
409
+ ```bash
410
+ yard doc lib/yard/lint/validators/**/*.rb
411
+ yard server
412
+ ```
404
413
 
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
- ```
414
+ Then open http://localhost:8808 in your browser to browse the full validator documentation with examples.
412
415
 
413
- #### Examples
416
+ ### Quick Configuration Examples
414
417
 
415
418
  ```yaml
416
- # Minimal setup: only exclude parameter-less initialize
417
- Documentation/UndocumentedObjects:
418
- ExcludedMethods:
419
- - 'initialize/0'
420
-
421
- # Common Rails/Ruby patterns
419
+ # Exclude specific methods from documentation requirements
422
420
  Documentation/UndocumentedObjects:
423
421
  ExcludedMethods:
424
422
  - 'initialize/0' # Parameter-less constructors
425
423
  - '/^_/' # Private methods (by convention)
426
424
  - '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
425
 
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
426
+ # Enable @api tag validation (disabled by default)
427
+ Tags/ApiTags:
428
+ Enabled: true
429
+ AllowedApis:
430
+ - public
431
+ - private
432
+
433
+ # Disable a validator
434
+ Tags/RedundantParamDescription:
435
+ Enabled: false
436
+ ```
493
437
 
494
438
  ### Global Configuration
495
439
 
@@ -537,173 +481,6 @@ Options:
537
481
 
538
482
  All configuration (tag order, exclude patterns, severity levels, validator settings) should be defined in `.yard-lint.yml`.
539
483
 
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
484
  ## License
708
485
 
709
486
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/bin/yard-lint CHANGED
@@ -32,6 +32,14 @@ OptionParser.new do |opts|
32
32
  options[:progress] = value
33
33
  end
34
34
 
35
+ opts.on('--init', 'Generate .yard-lint.yml config file with defaults') do
36
+ options[:init] = true
37
+ end
38
+
39
+ opts.on('--force', 'Force overwrite when using --init') do
40
+ options[:force] = true
41
+ end
42
+
35
43
  opts.on('-v', '--version', 'Show version') do
36
44
  puts "yard-lint #{Yard::Lint::VERSION}"
37
45
  exit
@@ -43,6 +51,18 @@ OptionParser.new do |opts|
43
51
  end
44
52
  end.parse!
45
53
 
54
+ # Handle --init flag
55
+ if options[:init]
56
+ if Yard::Lint::ConfigGenerator.generate(force: options[:force])
57
+ puts 'Created .yard-lint.yml with default configuration'
58
+ exit 0
59
+ else
60
+ puts 'Error: .yard-lint.yml already exists'
61
+ puts 'Use --init --force to overwrite'
62
+ exit 1
63
+ end
64
+ end
65
+
46
66
  # Get path argument
47
67
  path = ARGV[0]
48
68
 
@@ -199,8 +199,6 @@ module Yard
199
199
  respond_to?(key) ? send(key) : nil
200
200
  end
201
201
 
202
- private
203
-
204
202
  # Generic helper to set validator configuration
205
203
  # @param validator_name [String] full validator name (e.g., 'Tags/Order')
206
204
  # @param key [String] configuration key
@@ -0,0 +1,191 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yard
4
+ module Lint
5
+ # Generates default .yard-lint.yml configuration file
6
+ class ConfigGenerator
7
+ # Default configuration template
8
+ DEFAULT_CONFIG = <<~YAML
9
+ # YARD-Lint Configuration
10
+ # See https://github.com/mensfeld/yard-lint for documentation
11
+
12
+ # Global settings for all validators
13
+ AllValidators:
14
+ # YARD command-line options (applied to all validators by default)
15
+ YardOptions:
16
+ - --private
17
+ - --protected
18
+
19
+ # Global file exclusion patterns
20
+ Exclude:
21
+ - '\\.git'
22
+ - 'vendor/**/*'
23
+ - 'node_modules/**/*'
24
+ - 'spec/**/*'
25
+ - 'test/**/*'
26
+
27
+ # Exit code behavior (error, warning, convention, never)
28
+ FailOnSeverity: warning
29
+
30
+ # Documentation validators
31
+ Documentation/UndocumentedObjects:
32
+ Description: 'Checks for classes, modules, and methods without documentation.'
33
+ Enabled: true
34
+ Severity: warning
35
+ ExcludedMethods:
36
+ - 'initialize/0' # Exclude parameter-less initialize
37
+ - '/^_/' # Exclude private methods (by convention)
38
+
39
+ Documentation/UndocumentedMethodArguments:
40
+ Description: 'Checks for method parameters without @param tags.'
41
+ Enabled: true
42
+ Severity: warning
43
+
44
+ Documentation/UndocumentedBooleanMethods:
45
+ Description: 'Checks that question mark methods document their boolean return.'
46
+ Enabled: true
47
+ Severity: warning
48
+
49
+ Documentation/UndocumentedOptions:
50
+ Description: 'Detects methods with options hash parameters but no @option tags.'
51
+ Enabled: true
52
+ Severity: warning
53
+
54
+ Documentation/MarkdownSyntax:
55
+ Description: 'Detects common markdown syntax errors in documentation.'
56
+ Enabled: true
57
+ Severity: warning
58
+
59
+ # Tags validators
60
+ Tags/Order:
61
+ Description: 'Enforces consistent ordering of YARD tags.'
62
+ Enabled: true
63
+ Severity: convention
64
+ EnforcedOrder:
65
+ - param
66
+ - option
67
+ - return
68
+ - raise
69
+ - example
70
+
71
+ Tags/InvalidTypes:
72
+ Description: 'Validates type definitions in @param, @return, @option tags.'
73
+ Enabled: true
74
+ Severity: warning
75
+ ValidatedTags:
76
+ - param
77
+ - option
78
+ - return
79
+
80
+ Tags/TypeSyntax:
81
+ Description: 'Validates YARD type syntax using YARD parser.'
82
+ Enabled: true
83
+ Severity: warning
84
+ ValidatedTags:
85
+ - param
86
+ - option
87
+ - return
88
+ - yieldreturn
89
+
90
+ Tags/MeaninglessTag:
91
+ Description: 'Detects @param/@option tags on classes, modules, or constants.'
92
+ Enabled: true
93
+ Severity: warning
94
+ CheckedTags:
95
+ - param
96
+ - option
97
+ InvalidObjectTypes:
98
+ - class
99
+ - module
100
+ - constant
101
+
102
+ Tags/CollectionType:
103
+ Description: 'Validates Hash collection syntax consistency.'
104
+ Enabled: true
105
+ Severity: convention
106
+ EnforcedStyle: long # 'long' for Hash{K => V} (YARD standard), 'short' for {K => V}
107
+ ValidatedTags:
108
+ - param
109
+ - option
110
+ - return
111
+ - yieldreturn
112
+
113
+ Tags/TagTypePosition:
114
+ Description: 'Validates type annotation position in tags.'
115
+ Enabled: true
116
+ Severity: convention
117
+ CheckedTags:
118
+ - param
119
+ - option
120
+ # EnforcedStyle: 'type_after_name' (YARD standard: @param name [Type])
121
+ # or 'type_first' (@param [Type] name)
122
+ EnforcedStyle: type_after_name
123
+
124
+ Tags/ApiTags:
125
+ Description: 'Enforces @api tags on public objects.'
126
+ Enabled: false # Opt-in validator
127
+ Severity: warning
128
+ AllowedApis:
129
+ - public
130
+ - private
131
+ - internal
132
+
133
+ Tags/OptionTags:
134
+ Description: 'Requires @option tags for methods with options parameters.'
135
+ Enabled: true
136
+ Severity: warning
137
+
138
+ # Warnings validators - catches YARD parser errors
139
+ Warnings/UnknownTag:
140
+ Description: 'Detects unknown YARD tags.'
141
+ Enabled: true
142
+ Severity: error
143
+
144
+ Warnings/UnknownDirective:
145
+ Description: 'Detects unknown YARD directives.'
146
+ Enabled: true
147
+ Severity: error
148
+
149
+ Warnings/InvalidTagFormat:
150
+ Description: 'Detects malformed tag syntax.'
151
+ Enabled: true
152
+ Severity: error
153
+
154
+ Warnings/InvalidDirectiveFormat:
155
+ Description: 'Detects malformed directive syntax.'
156
+ Enabled: true
157
+ Severity: error
158
+
159
+ Warnings/DuplicatedParameterName:
160
+ Description: 'Detects duplicate @param tags.'
161
+ Enabled: true
162
+ Severity: error
163
+
164
+ Warnings/UnknownParameterName:
165
+ Description: 'Detects @param tags for non-existent parameters.'
166
+ Enabled: true
167
+ Severity: error
168
+
169
+ # Semantic validators
170
+ Semantic/AbstractMethods:
171
+ Description: 'Ensures @abstract methods do not have real implementations.'
172
+ Enabled: true
173
+ Severity: warning
174
+ YAML
175
+
176
+ # Generate .yard-lint.yml file in current directory
177
+ # @param force [Boolean] overwrite existing file if true
178
+ # @return [Boolean] true if file was created, false if already exists
179
+ def self.generate(force: false)
180
+ config_path = File.join(Dir.pwd, Config::DEFAULT_CONFIG_FILE)
181
+
182
+ if File.exist?(config_path) && !force
183
+ false
184
+ else
185
+ File.write(config_path, DEFAULT_CONFIG)
186
+ true
187
+ end
188
+ end
189
+ end
190
+ end
191
+ end