Skip to content

Commit bb3be23

Browse files
committed
Add doc linter to check outdated templates
We don't often change the tempaltes of validators, but when we do it's extremely important that the documentation of the validators match the exact template the validator has.
1 parent ed129b4 commit bb3be23

13 files changed

Lines changed: 165 additions & 33 deletions

File tree

bin/console

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use Respect\Dev\Markdown\Differ as MarkdownDiffer;
2020
use Respect\Dev\Markdown\Linters\ValidatorHeaderLinter;
2121
use Respect\Dev\Markdown\Linters\ValidatorIndexLinter;
2222
use Respect\Dev\Markdown\Linters\ValidatorRelatedLinter;
23+
use Respect\Dev\Markdown\Linters\ValidatorTemplatesLinter;
2324
use SebastianBergmann\Diff\Differ;
2425
use SebastianBergmann\Diff\Output\UnifiedDiffOutputBuilder;
2526
use Symfony\Component\Console\Application;
@@ -33,6 +34,7 @@ return (static function () {
3334
new ValidatorHeaderLinter(),
3435
new ValidatorIndexLinter(),
3536
new ValidatorRelatedLinter(),
37+
new ValidatorTemplatesLinter(),
3638
)));
3739
$application->addCommand(new UpdateDomainSuffixesCommand());
3840
$application->addCommand(new UpdateDomainToplevelCommand());

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
"docs:validators:headers": "bin/console docs:validators:headers",
7676
"docs:validators:index": "bin/console docs:validators:index",
7777
"docs:validators:related": "bin/console docs:validators:related",
78+
"docs:validators:templates": "bin/console docs:validators:templates",
7879
"docheader": "vendor/bin/docheader check library/ tests/",
7980
"phpcs": "vendor/bin/phpcs",
8081
"phpstan": "vendor/bin/phpstan analyze",
@@ -83,7 +84,8 @@
8384
"docs": [
8485
"@docs:validators:headers",
8586
"@docs:validators:index",
86-
"@docs:validators:related"
87+
"@docs:validators:related",
88+
"@docs:validators:templates"
8789
],
8890
"qa": [
8991
"@docheader",

docs/validators/All.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ This validator uses [Length](Length.md) with [GreaterThan][GreaterThan.md] inter
2424
| `default` | Every item in |
2525
| `inverted` | Every item in |
2626

27-
This template serve as message prefixes.:
27+
## Template as prefix
28+
29+
The template serves as a prefix to the template of the inner validator.
2830

2931
```php
3032
v::all(v::floatType())->assert([1.5, 2]);

docs/validators/DateTimeDiff.md

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,6 @@ The supported types are:
3131

3232
## Templates
3333

34-
The first two templates serve as message suffixes:
35-
36-
```php
37-
v::dateTimeDiff('years', v::equals(2))->assert('1 year ago')
38-
// The number of years between now and 1 year ago must be equal to 2
39-
40-
v::not(v::dateTimeDiff('years', v::lessThan(8)))->assert('7 year ago')
41-
// The number of years between now and 7 year ago must not be less than 8
42-
```
43-
4434
### `DateTimeDiff::TEMPLATE_STANDARD`
4535

4636
Used when `$format` and `$now` are not defined.
@@ -54,10 +44,17 @@ Used when `$format` and `$now` are not defined.
5444

5545
Used when `$format` or `$now` are defined.
5646

57-
| Mode | Template |
58-
| ---------- | -------------------------------------------------------------- |
59-
| `default` | The number of {{type|trans}} between {{now|raw}} and |
60-
| `inverted` | The number of {{type|trans}} between {{now|raw}} and |
47+
| Mode | Template |
48+
| ---------- | ----------------------------------------------------- |
49+
| `default` | The number of {{type|trans}} between {{now}} and |
50+
| `inverted` | The number of {{type|trans}} between {{now}} and |
51+
52+
### `DateTimeDiff::TEMPLATE_NOT_A_DATE`
53+
54+
| Mode | Template |
55+
| ---------- | ------------------------------------------------------------------------------ |
56+
| `default` | For comparison with {{now|raw}}, {{subject}} must be a valid datetime |
57+
| `inverted` | For comparison with {{now|raw}}, {{subject}} must not be a valid datetime |
6158

6259
### `DateTimeDiff::TEMPLATE_WRONG_FORMAT`
6360

@@ -68,6 +65,18 @@ Used when the input cannot be parsed with the given format.
6865
| `default` | For comparison with {{now|raw}}, {{subject}} must be a valid datetime in the format {{sample|raw}} |
6966
| `inverted` | For comparison with {{now|raw}}, {{subject}} must not be a valid datetime in the format {{sample|raw}} |
7067

68+
## Template as prefix
69+
70+
The template serves as a prefix to the template of the inner validator.
71+
72+
```php
73+
v::dateTimeDiff('years', v::equals(2))->assert('1 year ago')
74+
// The number of years between now and 1 year ago must be equal to 2
75+
76+
v::not(v::dateTimeDiff('years', v::lessThan(8)))->assert('7 year ago')
77+
// The number of years between now and 7 year ago must not be less than 8
78+
```
79+
7180
## Template placeholders
7281

7382
| Placeholder | Description |

docs/validators/Instance.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ Message template for this validator includes `{{instanceName}}`.
1717

1818
| Mode | Template |
1919
| ---------- | ----------------------------------------------------------- |
20-
| `default` | {{subject}} must be an instance of `{{class|raw}}` |
21-
| `inverted` | {{subject}} must not be an instance of `{{class|raw}}` |
20+
| `default` | {{subject}} must be an instance of {{class|quote}} |
21+
| `inverted` | {{subject}} must not be an instance of {{class|quote}} |
2222

2323
## Template placeholders
2424

docs/validators/Length.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,16 @@ Used when it's possible to get the length of the input.
3131
| `default` | The length of |
3232
| `inverted` | The length of |
3333

34-
This template serve as message prefixes.:
34+
### `Length::TEMPLATE_WRONG_TYPE`
35+
36+
| Mode | Template |
37+
| ---------- | ----------------------------------------------------- |
38+
| `default` | {{subject}} must be a countable value or a string |
39+
| `inverted` | {{subject}} must not be a countable value or a string |
40+
41+
## Template as prefix
42+
43+
The template serves as a prefix to the template of the inner validator.
3544

3645
```php
3746
v::length(v::equals(3))->assert('tulip');

docs/validators/Max.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ This validator uses [Length](Length.md) with [GreaterThan][GreaterThan.md] inter
2828
| `default` | The maximum of |
2929
| `inverted` | The maximum of |
3030

31+
## Template as prefix
32+
33+
The template serves as a prefix to the template of the inner validator.
34+
3135
## Template placeholders
3236

3337
| Placeholder | Description |

docs/validators/Min.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ This validator uses [Length](Length.md) with [GreaterThan][GreaterThan.md] inter
2828
| `default` | The minimum of |
2929
| `inverted` | The minimum of |
3030

31+
## Template as prefix
32+
33+
The template serves as a prefix to the template of the inner validator.
34+
3135
## Template placeholders
3236

3337
| Placeholder | Description |

docs/validators/NullOr.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ v::nullOrBetween(1, 3)->isValid(null); // true
3131
| `default` | or must be null |
3232
| `inverted` | and must not be null |
3333

34-
The templates from this validator serve as message suffixes:
34+
## Template as suffix
35+
36+
The template serves as a suffix to the template of the inner validator.
3537

3638
```php
3739
v::nullOr(v::alpha())->assert('has1number');

docs/validators/Regex.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ Message template for this validator includes `{{regex}}`.
1616

1717
| Mode | Template |
1818
| ---------- | ----------------------------------------------------------- |
19-
| `default` | {{subject}} must match the pattern `{{regex|raw}}` |
20-
| `inverted` | {{subject}} must not match the pattern `{{regex|raw}}` |
19+
| `default` | {{subject}} must match the pattern {{regex|quote}} |
20+
| `inverted` | {{subject}} must not match the pattern {{regex|quote}} |
2121

2222
## Template placeholders
2323

0 commit comments

Comments
 (0)