yard-lint 0.2.1 → 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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +73 -1
- data/README.md +121 -89
- data/bin/yard-lint +44 -0
- data/lib/yard/lint/config.rb +35 -3
- data/lib/yard/lint/config_generator.rb +191 -0
- data/lib/yard/lint/config_loader.rb +1 -1
- data/lib/yard/lint/result_builder.rb +10 -1
- data/lib/yard/lint/validators/base.rb +77 -12
- data/lib/yard/lint/validators/documentation/markdown_syntax/config.rb +20 -0
- data/lib/yard/lint/validators/documentation/markdown_syntax/messages_builder.rb +44 -0
- data/lib/yard/lint/validators/documentation/markdown_syntax/parser.rb +53 -0
- data/lib/yard/lint/validators/documentation/markdown_syntax/result.rb +25 -0
- data/lib/yard/lint/validators/documentation/markdown_syntax/validator.rb +38 -0
- data/lib/yard/lint/validators/documentation/markdown_syntax.rb +37 -0
- data/lib/yard/lint/validators/documentation/undocumented_boolean_methods/validator.rb +7 -6
- data/lib/yard/lint/validators/documentation/undocumented_boolean_methods.rb +26 -1
- data/lib/yard/lint/validators/documentation/undocumented_method_arguments/validator.rb +4 -5
- data/lib/yard/lint/validators/documentation/undocumented_method_arguments.rb +26 -1
- data/lib/yard/lint/validators/documentation/undocumented_objects/config.rb +2 -1
- data/lib/yard/lint/validators/documentation/undocumented_objects/parser.rb +95 -5
- data/lib/yard/lint/validators/documentation/undocumented_objects/validator.rb +15 -11
- data/lib/yard/lint/validators/documentation/undocumented_objects.rb +131 -2
- data/lib/yard/lint/validators/documentation/undocumented_options/config.rb +20 -0
- data/lib/yard/lint/validators/documentation/undocumented_options/parser.rb +53 -0
- data/lib/yard/lint/validators/documentation/undocumented_options/result.rb +29 -0
- data/lib/yard/lint/validators/documentation/undocumented_options/validator.rb +38 -0
- data/lib/yard/lint/validators/documentation/undocumented_options.rb +40 -0
- data/lib/yard/lint/validators/semantic/abstract_methods/validator.rb +4 -5
- data/lib/yard/lint/validators/semantic/abstract_methods.rb +31 -1
- data/lib/yard/lint/validators/tags/api_tags/validator.rb +4 -5
- data/lib/yard/lint/validators/tags/api_tags.rb +34 -1
- data/lib/yard/lint/validators/tags/collection_type/config.rb +22 -0
- data/lib/yard/lint/validators/tags/collection_type/messages_builder.rb +73 -0
- data/lib/yard/lint/validators/tags/collection_type/parser.rb +50 -0
- data/lib/yard/lint/validators/tags/collection_type/result.rb +25 -0
- data/lib/yard/lint/validators/tags/collection_type/validator.rb +92 -0
- data/lib/yard/lint/validators/tags/collection_type.rb +50 -0
- data/lib/yard/lint/validators/tags/example_syntax/config.rb +20 -0
- data/lib/yard/lint/validators/tags/example_syntax/messages_builder.rb +28 -0
- data/lib/yard/lint/validators/tags/example_syntax/parser.rb +79 -0
- data/lib/yard/lint/validators/tags/example_syntax/result.rb +42 -0
- data/lib/yard/lint/validators/tags/example_syntax/validator.rb +88 -0
- data/lib/yard/lint/validators/tags/example_syntax.rb +42 -0
- data/lib/yard/lint/validators/tags/invalid_types/validator.rb +8 -8
- data/lib/yard/lint/validators/tags/invalid_types.rb +25 -1
- data/lib/yard/lint/validators/tags/meaningless_tag/config.rb +22 -0
- data/lib/yard/lint/validators/tags/meaningless_tag/messages_builder.rb +28 -0
- data/lib/yard/lint/validators/tags/meaningless_tag/parser.rb +53 -0
- data/lib/yard/lint/validators/tags/meaningless_tag/result.rb +26 -0
- data/lib/yard/lint/validators/tags/meaningless_tag/validator.rb +82 -0
- data/lib/yard/lint/validators/tags/meaningless_tag.rb +43 -0
- data/lib/yard/lint/validators/tags/option_tags/validator.rb +11 -6
- data/lib/yard/lint/validators/tags/option_tags.rb +26 -1
- data/lib/yard/lint/validators/tags/order/validator.rb +4 -5
- data/lib/yard/lint/validators/tags/order.rb +25 -1
- data/lib/yard/lint/validators/tags/redundant_param_description/config.rb +33 -0
- data/lib/yard/lint/validators/tags/redundant_param_description/messages_builder.rb +61 -0
- data/lib/yard/lint/validators/tags/redundant_param_description/parser.rb +67 -0
- data/lib/yard/lint/validators/tags/redundant_param_description/result.rb +25 -0
- data/lib/yard/lint/validators/tags/redundant_param_description/validator.rb +148 -0
- data/lib/yard/lint/validators/tags/redundant_param_description.rb +168 -0
- data/lib/yard/lint/validators/tags/tag_type_position/config.rb +22 -0
- data/lib/yard/lint/validators/tags/tag_type_position/messages_builder.rb +38 -0
- data/lib/yard/lint/validators/tags/tag_type_position/parser.rb +51 -0
- data/lib/yard/lint/validators/tags/tag_type_position/result.rb +25 -0
- data/lib/yard/lint/validators/tags/tag_type_position/validator.rb +111 -0
- data/lib/yard/lint/validators/tags/tag_type_position.rb +51 -0
- data/lib/yard/lint/validators/tags/type_syntax/config.rb +21 -0
- data/lib/yard/lint/validators/tags/type_syntax/messages_builder.rb +27 -0
- data/lib/yard/lint/validators/tags/type_syntax/parser.rb +54 -0
- data/lib/yard/lint/validators/tags/type_syntax/result.rb +25 -0
- data/lib/yard/lint/validators/tags/type_syntax/validator.rb +76 -0
- data/lib/yard/lint/validators/tags/type_syntax.rb +38 -0
- data/lib/yard/lint/validators/warnings/duplicated_parameter_name/validator.rb +4 -5
- data/lib/yard/lint/validators/warnings/duplicated_parameter_name.rb +26 -1
- data/lib/yard/lint/validators/warnings/invalid_directive_format/validator.rb +4 -5
- data/lib/yard/lint/validators/warnings/invalid_directive_format.rb +26 -1
- data/lib/yard/lint/validators/warnings/invalid_tag_format/validator.rb +4 -5
- data/lib/yard/lint/validators/warnings/invalid_tag_format.rb +25 -1
- data/lib/yard/lint/validators/warnings/unknown_directive/validator.rb +4 -5
- data/lib/yard/lint/validators/warnings/unknown_directive.rb +26 -1
- data/lib/yard/lint/validators/warnings/unknown_parameter_name/parser.rb +4 -1
- data/lib/yard/lint/validators/warnings/unknown_parameter_name/validator.rb +4 -5
- data/lib/yard/lint/validators/warnings/unknown_parameter_name.rb +23 -1
- data/lib/yard/lint/validators/warnings/unknown_tag/validator.rb +4 -5
- data/lib/yard/lint/validators/warnings/unknown_tag.rb +26 -1
- data/lib/yard/lint/version.rb +1 -1
- data/lib/yard/lint.rb +1 -0
- data/misc/logo.png +0 -0
- metadata +64 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 95017b70fd77952580b3bf10466c79efff2fb1bbd353d1ba49ce84eab7feb5e9
|
|
4
|
+
data.tar.gz: 0e5015d8cd2b15b38ccc98d149b3b923997c3952ccc8d799050e51e226d8f14b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d4825147326c85f9af2faaa95200f797321e06d12bbfe4063ea5b0acd851496bc541546d0885ccdd3d674242670a573be396bc4ae454361a266cadc240c813e8
|
|
7
|
+
data.tar.gz: cb1fa4762efdbecfc0265791a93ffb3ef4a9668e9a6905da29acb966f3bbd650ebd7b21ccb826a5dab2dd972762d4f642e17ecccd986d22354af4837633991cd
|
data/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,76 @@
|
|
|
1
|
-
# Changelog
|
|
1
|
+
# YARD-Lint Changelog
|
|
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
|
+
|
|
43
|
+
## 1.0.0 (2025-11-09)
|
|
44
|
+
- [Fix] Fix "Argument list too long" error on large codebases by using xargs pattern with temporary file lists
|
|
45
|
+
- [Enhancement] Expand default exclusion patterns to include typical Ruby/Rails directories (test/, log/, coverage/, db/migrate/, etc.)
|
|
46
|
+
- **[Feature]** Add `Tags/TypeSyntax` validator to detect malformed YARD type syntax using YARD's built-in parser
|
|
47
|
+
- Detects unclosed brackets: `Array<`, `Hash{Symbol =>`
|
|
48
|
+
- Detects empty generics: `Array<>`
|
|
49
|
+
- Detects malformed hash syntax: `Hash{Symbol}`
|
|
50
|
+
- Configurable `ValidatedTags` option (default: param, option, return, yieldreturn)
|
|
51
|
+
- **[Feature]** Add `Tags/MeaninglessTag` validator to detect `@param` and `@option` tags on non-method objects
|
|
52
|
+
- Prevents meaningless tags on classes, modules, and constants
|
|
53
|
+
- Configurable `CheckedTags` (default: param, option) and `InvalidObjectTypes` (default: class, module, constant)
|
|
54
|
+
- **[Feature]** Add `Tags/CollectionType` validator to enforce YARD's Hash collection syntax
|
|
55
|
+
- Enforces `Hash{K => V}` over `Hash<K, V>` (generic syntax from other languages)
|
|
56
|
+
- Configurable `ValidatedTags` (default: param, option, return, yieldreturn)
|
|
57
|
+
- Provides automatic correction suggestions
|
|
58
|
+
- **[Feature]** Add `Tags/TagTypePosition` validator to validate type annotation position in tags
|
|
59
|
+
- Configurable style: `type_after_name` (YARD standard: `@param name [Type]`) or `type_first` (`@param [Type] name`)
|
|
60
|
+
- Only validates `@param` and `@option` tags (excludes `@return` as it has no parameter name)
|
|
61
|
+
- Reads source code directly to avoid false positives from YARD's internal docstring normalization
|
|
62
|
+
- [Fix] Fix `Warnings/UnknownParameterName` validator showing only line number instead of full file path by correcting regex pattern
|
|
63
|
+
- [Enhancement] Add comprehensive integration tests for `UnknownParameterName` validator
|
|
64
|
+
- [Documentation] Add inline documentation explaining cache clearing in bin/yard-lint
|
|
65
|
+
- [Documentation] Expand README with troubleshooting section for ExcludedMethods patterns
|
|
66
|
+
|
|
67
|
+
## 0.2.2 (2025-11-07)
|
|
68
|
+
- **[Feature]** Add `ExcludedMethods` configuration option to exclude methods from validation using simple names, regex patterns, or arity notation (default excludes parameter-less `initialize/0` methods).
|
|
69
|
+
- [Fix] Fix `UndocumentedObjects` validator incorrectly flagging methods with `@return [Boolean]` tags as undocumented by using `docstring.all.empty?` instead of `docstring.blank?`.
|
|
70
|
+
- [Fix] Fix `UndocumentedBooleanMethods` validator incorrectly flagging methods with `@return [Boolean]` (type without description text) by checking for return types instead of description text.
|
|
71
|
+
- [Enhancement] Implement per-arguments YARD database isolation using SHA256 hash of arguments to prevent contamination between validators with different file selections.
|
|
72
|
+
- [Refactoring] Remove file filtering workaround as database isolation eliminates the need for it.
|
|
73
|
+
- [Change] YARD database directories are now created under a base temp directory with unique subdirectories per argument set.
|
|
2
74
|
|
|
3
75
|
## 0.2.1 (2025-11-07)
|
|
4
76
|
- Release to validate Trusted Publishing flow.
|
data/README.md
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
[](https://github.com/mensfeld/yard-lint/actions/workflows/ci.yml)
|
|
4
|
+
[](http://badge.fury.io/rb/yard-lint)
|
|
5
|
+
|
|
1
6
|
# YARD-Lint
|
|
2
7
|
|
|
3
8
|
A comprehensive linter for YARD documentation that helps you maintain clean, consistent, and complete documentation in your Ruby and Ruby on Rails projects.
|
|
@@ -17,11 +22,17 @@ YARD-Lint validates your YARD documentation for:
|
|
|
17
22
|
- **Undocumented code**: Classes, modules, methods, and constants without documentation
|
|
18
23
|
- **Missing parameter documentation**: Methods with undocumented parameters
|
|
19
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.)
|
|
20
26
|
- **Invalid tag ordering**: Tags that don't follow your specified order
|
|
27
|
+
- **Meaningless tags**: `@param` or `@option` tags on classes, modules, or constants (only valid on methods)
|
|
28
|
+
- **Collection type syntax**: Enforces `Hash{K => V}` over `Hash<K, V>` (YARD standard)
|
|
29
|
+
- **Type annotation position**: Validates whether types appear before or after parameter names (configurable)
|
|
21
30
|
- **Boolean method documentation**: Question mark methods missing return type documentation
|
|
22
31
|
- **API tag validation**: Enforce @api tags on public objects and validate API values
|
|
23
32
|
- **Abstract method validation**: Ensure @abstract methods don't have real implementations
|
|
24
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`)
|
|
25
36
|
- **YARD warnings**: Unknown tags, invalid directives, duplicated parameter names, and more
|
|
26
37
|
|
|
27
38
|
## Installation
|
|
@@ -46,6 +57,16 @@ gem install yard-lint
|
|
|
46
57
|
|
|
47
58
|
## Usage
|
|
48
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
|
+
|
|
49
70
|
### Command Line
|
|
50
71
|
|
|
51
72
|
Basic usage:
|
|
@@ -62,6 +83,10 @@ yard-lint --config config/yard-lint.yml lib/
|
|
|
62
83
|
|
|
63
84
|
# Output as JSON
|
|
64
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
|
|
65
90
|
```
|
|
66
91
|
|
|
67
92
|
## Configuration
|
|
@@ -96,6 +121,14 @@ Documentation/UndocumentedObjects:
|
|
|
96
121
|
Description: 'Checks for classes, modules, and methods without documentation.'
|
|
97
122
|
Enabled: true
|
|
98
123
|
Severity: warning
|
|
124
|
+
# List of methods to exclude from validation
|
|
125
|
+
# Supports three patterns:
|
|
126
|
+
# - Exact names: 'method_name' (excludes all methods with this name)
|
|
127
|
+
# - Arity notation: 'method_name/N' (excludes only if method has N parameters)
|
|
128
|
+
# - Regex patterns: '/pattern/' (excludes methods matching the regex)
|
|
129
|
+
ExcludedMethods:
|
|
130
|
+
- 'initialize/0' # Exclude only parameter-less initialize (default)
|
|
131
|
+
- '/^_/' # Exclude private methods (by convention)
|
|
99
132
|
|
|
100
133
|
Documentation/UndocumentedMethodArguments:
|
|
101
134
|
Description: 'Checks for method parameters without @param tags.'
|
|
@@ -130,6 +163,49 @@ Tags/InvalidTypes:
|
|
|
130
163
|
- CustomType
|
|
131
164
|
- MyType
|
|
132
165
|
|
|
166
|
+
Tags/TypeSyntax:
|
|
167
|
+
Description: 'Validates YARD type syntax using YARD parser.'
|
|
168
|
+
Enabled: true
|
|
169
|
+
Severity: warning
|
|
170
|
+
ValidatedTags:
|
|
171
|
+
- param
|
|
172
|
+
- option
|
|
173
|
+
- return
|
|
174
|
+
- yieldreturn
|
|
175
|
+
|
|
176
|
+
Tags/MeaninglessTag:
|
|
177
|
+
Description: 'Detects @param/@option tags on classes, modules, or constants.'
|
|
178
|
+
Enabled: true
|
|
179
|
+
Severity: warning
|
|
180
|
+
CheckedTags:
|
|
181
|
+
- param
|
|
182
|
+
- option
|
|
183
|
+
InvalidObjectTypes:
|
|
184
|
+
- class
|
|
185
|
+
- module
|
|
186
|
+
- constant
|
|
187
|
+
|
|
188
|
+
Tags/CollectionType:
|
|
189
|
+
Description: 'Validates Hash collection syntax (enforces Hash{K => V} over Hash<K, V>).'
|
|
190
|
+
Enabled: true
|
|
191
|
+
Severity: convention
|
|
192
|
+
ValidatedTags:
|
|
193
|
+
- param
|
|
194
|
+
- option
|
|
195
|
+
- return
|
|
196
|
+
- yieldreturn
|
|
197
|
+
|
|
198
|
+
Tags/TagTypePosition:
|
|
199
|
+
Description: 'Validates type annotation position in tags.'
|
|
200
|
+
Enabled: true
|
|
201
|
+
Severity: convention
|
|
202
|
+
CheckedTags:
|
|
203
|
+
- param
|
|
204
|
+
- option
|
|
205
|
+
# EnforcedStyle: 'type_after_name' (YARD standard: @param name [Type])
|
|
206
|
+
# or 'type_first' (@param [Type] name)
|
|
207
|
+
EnforcedStyle: type_after_name
|
|
208
|
+
|
|
133
209
|
Tags/ApiTags:
|
|
134
210
|
Description: 'Enforces @api tags on public objects.'
|
|
135
211
|
Enabled: false # Opt-in validator
|
|
@@ -297,14 +373,22 @@ Supported glob patterns:
|
|
|
297
373
|
| Validator | Description | Default | Configuration Options |
|
|
298
374
|
|-----------|-------------|---------|----------------------|
|
|
299
375
|
| **Documentation Validators** |
|
|
300
|
-
| `Documentation/UndocumentedObjects` | Checks for classes, modules, and methods without documentation | Enabled (warning) | `Enabled`, `Severity`, `Exclude` |
|
|
376
|
+
| `Documentation/UndocumentedObjects` | Checks for classes, modules, and methods without documentation | Enabled (warning) | `Enabled`, `Severity`, `Exclude`, `ExcludedMethods` |
|
|
301
377
|
| `Documentation/UndocumentedMethodArguments` | Checks for method parameters without `@param` tags | Enabled (warning) | `Enabled`, `Severity`, `Exclude` |
|
|
302
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` |
|
|
303
381
|
| **Tags Validators** |
|
|
304
382
|
| `Tags/Order` | Enforces consistent ordering of YARD tags | Enabled (convention) | `Enabled`, `Severity`, `Exclude`, `EnforcedOrder` |
|
|
305
383
|
| `Tags/InvalidTypes` | Validates type definitions in `@param`, `@return`, `@option` tags | Enabled (warning) | `Enabled`, `Severity`, `Exclude`, `ValidatedTags`, `ExtraTypes` |
|
|
384
|
+
| `Tags/TypeSyntax` | Validates YARD type syntax (detects unclosed brackets, empty generics, etc.) | Enabled (warning) | `Enabled`, `Severity`, `Exclude`, `ValidatedTags` |
|
|
385
|
+
| `Tags/MeaninglessTag` | Detects `@param`/`@option` tags on classes, modules, or constants (only valid on methods) | Enabled (warning) | `Enabled`, `Severity`, `Exclude`, `CheckedTags`, `InvalidObjectTypes` |
|
|
386
|
+
| `Tags/CollectionType` | Enforces `Hash{K => V}` over `Hash<K, V>` (YARD standard collection syntax) | Enabled (convention) | `Enabled`, `Severity`, `Exclude`, `ValidatedTags` |
|
|
387
|
+
| `Tags/TagTypePosition` | Validates type annotation position (`@param name [Type]` vs `@param [Type] name`) | Enabled (convention) | `Enabled`, `Severity`, `Exclude`, `CheckedTags`, `EnforcedStyle` |
|
|
306
388
|
| `Tags/ApiTags` | Enforces `@api` tags on public objects | Disabled (opt-in) | `Enabled`, `Severity`, `Exclude`, `AllowedApis` |
|
|
307
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` |
|
|
308
392
|
| **Warnings Validators** |
|
|
309
393
|
| `Warnings/UnknownTag` | Detects unknown YARD tags | Enabled (error) | `Enabled`, `Severity`, `Exclude` |
|
|
310
394
|
| `Warnings/UnknownDirective` | Detects unknown YARD directives | Enabled (error) | `Enabled`, `Severity`, `Exclude` |
|
|
@@ -315,6 +399,42 @@ Supported glob patterns:
|
|
|
315
399
|
| **Semantic Validators** |
|
|
316
400
|
| `Semantic/AbstractMethods` | Ensures `@abstract` methods don't have real implementations | Enabled (warning) | `Enabled`, `Severity`, `Exclude` |
|
|
317
401
|
|
|
402
|
+
### Detailed Validator Documentation
|
|
403
|
+
|
|
404
|
+
For detailed documentation on each validator including configuration examples, pattern types, and troubleshooting guides, see the validator module documentation:
|
|
405
|
+
|
|
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:
|
|
408
|
+
|
|
409
|
+
```bash
|
|
410
|
+
yard doc lib/yard/lint/validators/**/*.rb
|
|
411
|
+
yard server
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
Then open http://localhost:8808 in your browser to browse the full validator documentation with examples.
|
|
415
|
+
|
|
416
|
+
### Quick Configuration Examples
|
|
417
|
+
|
|
418
|
+
```yaml
|
|
419
|
+
# Exclude specific methods from documentation requirements
|
|
420
|
+
Documentation/UndocumentedObjects:
|
|
421
|
+
ExcludedMethods:
|
|
422
|
+
- 'initialize/0' # Parameter-less constructors
|
|
423
|
+
- '/^_/' # Private methods (by convention)
|
|
424
|
+
- 'to_s' # String conversion
|
|
425
|
+
|
|
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
|
+
```
|
|
437
|
+
|
|
318
438
|
### Global Configuration
|
|
319
439
|
|
|
320
440
|
| Option | Description | Default | Type |
|
|
@@ -361,94 +481,6 @@ Options:
|
|
|
361
481
|
|
|
362
482
|
All configuration (tag order, exclude patterns, severity levels, validator settings) should be defined in `.yard-lint.yml`.
|
|
363
483
|
|
|
364
|
-
## Examples
|
|
365
|
-
|
|
366
|
-
### Check a directory
|
|
367
|
-
|
|
368
|
-
```bash
|
|
369
|
-
yard-lint lib/
|
|
370
|
-
```
|
|
371
|
-
|
|
372
|
-
### Check a single file
|
|
373
|
-
|
|
374
|
-
```bash
|
|
375
|
-
yard-lint lib/my_class.rb
|
|
376
|
-
```
|
|
377
|
-
|
|
378
|
-
### Use custom config file
|
|
379
|
-
|
|
380
|
-
```bash
|
|
381
|
-
yard-lint --config config/yard-lint.yml lib/
|
|
382
|
-
```
|
|
383
|
-
|
|
384
|
-
### Configure fail-on-severity
|
|
385
|
-
|
|
386
|
-
Add to `.yard-lint.yml`:
|
|
387
|
-
```yaml
|
|
388
|
-
AllValidators:
|
|
389
|
-
FailOnSeverity: error # Only fail on errors, not warnings
|
|
390
|
-
```
|
|
391
|
-
|
|
392
|
-
### Enable @api tag validation
|
|
393
|
-
|
|
394
|
-
Add to `.yard-lint.yml`:
|
|
395
|
-
```yaml
|
|
396
|
-
Tags/ApiTags:
|
|
397
|
-
Enabled: true
|
|
398
|
-
AllowedApis:
|
|
399
|
-
- public
|
|
400
|
-
- private
|
|
401
|
-
```
|
|
402
|
-
|
|
403
|
-
This will enforce that all public classes, modules, and methods have an `@api` tag:
|
|
404
|
-
|
|
405
|
-
```ruby
|
|
406
|
-
# Good
|
|
407
|
-
# @api public
|
|
408
|
-
class MyClass
|
|
409
|
-
# @api public
|
|
410
|
-
def public_method
|
|
411
|
-
end
|
|
412
|
-
|
|
413
|
-
# @api private
|
|
414
|
-
def internal_helper
|
|
415
|
-
end
|
|
416
|
-
end
|
|
417
|
-
|
|
418
|
-
# Bad - missing @api tags
|
|
419
|
-
class AnotherClass
|
|
420
|
-
def some_method
|
|
421
|
-
end
|
|
422
|
-
end
|
|
423
|
-
```
|
|
424
|
-
|
|
425
|
-
### @option tag validation (enabled by default)
|
|
426
|
-
|
|
427
|
-
This validator ensures that methods with options parameters document them. It's **enabled by default**. To disable it, add to `.yard-lint.yml`:
|
|
428
|
-
|
|
429
|
-
```yaml
|
|
430
|
-
Tags/OptionTags:
|
|
431
|
-
Enabled: false
|
|
432
|
-
```
|
|
433
|
-
|
|
434
|
-
Examples:
|
|
435
|
-
|
|
436
|
-
```ruby
|
|
437
|
-
# Good
|
|
438
|
-
# @param name [String] the name
|
|
439
|
-
# @param options [Hash] configuration options
|
|
440
|
-
# @option options [Boolean] :enabled Whether to enable the feature
|
|
441
|
-
# @option options [Integer] :timeout Timeout in seconds
|
|
442
|
-
def configure(name, options = {})
|
|
443
|
-
end
|
|
444
|
-
|
|
445
|
-
# Bad - missing @option tags
|
|
446
|
-
# @param name [String] the name
|
|
447
|
-
# @param options [Hash] configuration options
|
|
448
|
-
def configure(name, options = {})
|
|
449
|
-
end
|
|
450
|
-
```
|
|
451
|
-
|
|
452
484
|
## License
|
|
453
485
|
|
|
454
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
|
|
|
@@ -52,6 +72,30 @@ unless path
|
|
|
52
72
|
exit 1
|
|
53
73
|
end
|
|
54
74
|
|
|
75
|
+
# Clear YARD database and command cache to ensure fresh run on each CLI invocation
|
|
76
|
+
#
|
|
77
|
+
# Why this is necessary:
|
|
78
|
+
#
|
|
79
|
+
# 1. **Command Cache Reset** (`reset_command_cache!`)
|
|
80
|
+
# - The command cache stores results from YARD commands across validator instances
|
|
81
|
+
# - This cache is shared at the class level (Base.@shared_command_cache)
|
|
82
|
+
# - Without reset: Results from a previous CLI run could leak into the current run
|
|
83
|
+
# - Critical for CLI: Each `yard-lint` invocation should start with clean state
|
|
84
|
+
# - Not needed in-process: Within a single run, caching YARD results is beneficial
|
|
85
|
+
#
|
|
86
|
+
# 2. **YARD Database Clear** (`clear_yard_database!`)
|
|
87
|
+
# - YARD creates temp database directories for parsing documentation
|
|
88
|
+
# - Directories are isolated per-argument-set using SHA256 hash (see base.rb:84-97)
|
|
89
|
+
# - Base temp dir (YARDOC_BASE_TEMP_DIR) persists across CLI invocations
|
|
90
|
+
# - Without clear: Old databases accumulate in /tmp, wasting disk space
|
|
91
|
+
# - Database isolation prevents contamination within a single run, but doesn't
|
|
92
|
+
# clean up between runs
|
|
93
|
+
#
|
|
94
|
+
# In summary: These ensure each CLI invocation is independent and doesn't leak state
|
|
95
|
+
# from previous runs, while also preventing temp directory accumulation.
|
|
96
|
+
Yard::Lint::Validators::Base.reset_command_cache!
|
|
97
|
+
Yard::Lint::Validators::Base.clear_yard_database!
|
|
98
|
+
|
|
55
99
|
# Run the linter with config_file (it will be loaded internally)
|
|
56
100
|
result = Yard::Lint.run(
|
|
57
101
|
path: path,
|
data/lib/yard/lint/config.rb
CHANGED
|
@@ -86,7 +86,41 @@ module Yard
|
|
|
86
86
|
# Global file exclusion patterns
|
|
87
87
|
# @return [Array<String>] exclusion patterns
|
|
88
88
|
def exclude
|
|
89
|
-
all_validators['Exclude'] ||
|
|
89
|
+
all_validators['Exclude'] || default_exclusions
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# Default exclusion patterns for typical Ruby/Rails projects
|
|
93
|
+
# @return [Array<String>] default exclusion patterns
|
|
94
|
+
def default_exclusions
|
|
95
|
+
[
|
|
96
|
+
# Version control
|
|
97
|
+
'\.git',
|
|
98
|
+
# Dependencies
|
|
99
|
+
'vendor/**/*',
|
|
100
|
+
'node_modules/**/*',
|
|
101
|
+
# Test directories
|
|
102
|
+
'spec/**/*',
|
|
103
|
+
'test/**/*',
|
|
104
|
+
'features/**/*',
|
|
105
|
+
# Temporary and cache directories
|
|
106
|
+
'tmp/**/*',
|
|
107
|
+
'log/**/*',
|
|
108
|
+
'coverage/**/*',
|
|
109
|
+
'.bundle/**/*',
|
|
110
|
+
# Rails-specific
|
|
111
|
+
'db/schema.rb',
|
|
112
|
+
'db/migrate/**/*',
|
|
113
|
+
'public/assets/**/*',
|
|
114
|
+
'public/packs/**/*',
|
|
115
|
+
'public/system/**/*',
|
|
116
|
+
# Build artifacts
|
|
117
|
+
'pkg/**/*',
|
|
118
|
+
'doc/**/*',
|
|
119
|
+
'.yardoc/**/*',
|
|
120
|
+
# Configuration that doesn't need docs
|
|
121
|
+
'config/initializers/**/*',
|
|
122
|
+
'config/environments/**/*'
|
|
123
|
+
]
|
|
90
124
|
end
|
|
91
125
|
|
|
92
126
|
# Minimum severity level to fail on
|
|
@@ -165,8 +199,6 @@ module Yard
|
|
|
165
199
|
respond_to?(key) ? send(key) : nil
|
|
166
200
|
end
|
|
167
201
|
|
|
168
|
-
private
|
|
169
|
-
|
|
170
202
|
# Generic helper to set validator configuration
|
|
171
203
|
# @param validator_name [String] full validator name (e.g., 'Tags/Order')
|
|
172
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
|
|
@@ -37,7 +37,7 @@ module Yard
|
|
|
37
37
|
# Auto-discover validators from the codebase
|
|
38
38
|
# Scans the validators directory and loads all validator modules that have
|
|
39
39
|
# an .id method and .defaults method (indicating they're valid validators)
|
|
40
|
-
# @return [Hash
|
|
40
|
+
# @return [Hash{String => Array<String>}] hash of category names to validator names
|
|
41
41
|
def discover_validators
|
|
42
42
|
categories = Hash.new { |h, k| h[k] = [] }
|
|
43
43
|
|