Skip to content

Commit 1817898

Browse files
committed
ci(config): Add YAML formatter configuration and generate rule documentation
- Introduce .yamlfmt.yml with formatting rules to ensure consistent YAML files - Add rule-doc-generator script for automated rule documentation generation - Create peck.json preset for Laravel-specific ignore words - Update composer.json to include rule-doc commands and dependencies for documentation and Rector categorization Signed-off-by: guanguans <ityaozm@gmail.com>
1 parent 7012894 commit 1817898

File tree

10 files changed

+127
-4
lines changed

10 files changed

+127
-4
lines changed

.yamlfmt.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
formatter:
2+
type: basic
3+
eof_newline: true
4+
retain_line_breaks: true
5+
retain_line_breaks_single: true
6+
scan_folded_as_literal: true
7+
trim_trailing_whitespace: true
8+

composer.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@
172172
"@composer-dependency-analyser",
173173
"@test",
174174
"@phpstan",
175+
"@rule-doc-rector-generate",
175176
"@rector-dry-run"
176177
],
177178
"class-leak": "@php ./vendor/bin/class-leak --ansi -v",
@@ -271,6 +272,12 @@
271272
"release-minor-dry-run": "@release-minor --dry-run",
272273
"release-patch": "@release patch",
273274
"release-patch-dry-run": "@release-patch --dry-run",
275+
"rule-doc": [
276+
"@putenvs",
277+
"$PHP82 rule-doc-generator --ansi -vv"
278+
],
279+
"rule-doc-rector-generate": "@rule-doc generate src/Support/Rectors/ --output-file=src/Support/Rectors/rector-rules-overview.md --categorize=rector",
280+
"rule-doc-rector-validate": "@rule-doc validate src/Support/Rectors/",
274281
"sk": "@php ./vendor/bin/swiss-knife --ansi -v",
275282
"sk-check-commented-code": "@sk check-commented-code ./config ./src --line-limit=5",
276283
"sk-check-conflicts": "@sk check-conflicts ./config ./src",

peck.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"preset": "laravel",
3+
"ignore": {
4+
"words": [
5+
"php"
6+
],
7+
"paths": []
8+
}
9+
}

rule-doc-generator

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
declare(strict_types=1);
5+
6+
/**
7+
* Copyright (c) 2021-2025 guanguans<ityaozm@gmail.com>
8+
*
9+
* For the full copyright and license information, please view
10+
* the LICENSE file that was distributed with this source code.
11+
*
12+
* @see https://github.com/guanguans/laravel-skeleton
13+
*/
14+
15+
namespace RuleDocGenerator202408;
16+
17+
require __DIR__.'/vendor/autoload.php';
18+
19+
require __DIR__.'/vendor-bin/common/vendor/symplify/rule-doc-generator/bin/rule-doc-generator.php';

src/Support/Rectors/AddHasOptionsDocCommentRector.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@
2525
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
2626
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
2727
use Rector\Rector\AbstractRector;
28+
use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface;
2829
use Symplify\RuleDocGenerator\Exception\PoorDocumentationException;
2930
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
3031
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
3132

3233
/**
3334
* @internal
3435
*/
35-
final class AddHasOptionsDocCommentRector extends AbstractRector
36+
final class AddHasOptionsDocCommentRector extends AbstractRector implements DocumentedRuleInterface
3637
{
3738
public function __construct(
3839
private readonly DocBlockUpdater $docBlockUpdater,

src/Support/Rectors/AddSoarOptionsDocCommentRector.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@
1919
use PhpParser\Node\ArrayItem;
2020
use Rector\PhpParser\Node\Value\ValueResolver;
2121
use Rector\Rector\AbstractRector;
22+
use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface;
2223
use Symplify\RuleDocGenerator\Exception\PoorDocumentationException;
2324
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
2425
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
2526

2627
/**
2728
* @internal
2829
*/
29-
final class AddSoarOptionsDocCommentRector extends AbstractRector
30+
final class AddSoarOptionsDocCommentRector extends AbstractRector implements DocumentedRuleInterface
3031
{
3132
public function __construct(
3233
private readonly ValueResolver $valueResolver

src/Support/Rectors/SimplifyListIndexRector.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@
2020
use PhpParser\Node\Scalar\Int_;
2121
use Rector\PhpParser\Node\Value\ValueResolver;
2222
use Rector\Rector\AbstractRector;
23+
use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface;
2324
use Symplify\RuleDocGenerator\Exception\PoorDocumentationException;
2425
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
2526
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
2627

2728
/**
2829
* @internal
2930
*/
30-
final class SimplifyListIndexRector extends AbstractRector
31+
final class SimplifyListIndexRector extends AbstractRector implements DocumentedRuleInterface
3132
{
3233
public function __construct(
3334
private readonly ValueResolver $valueResolver
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# 3 Rules Overview
2+
3+
## AddHasOptionsDocCommentRector
4+
5+
Add has options doc comment
6+
7+
- class: [`Guanguans\SoarPHP\Support\Rectors\AddHasOptionsDocCommentRector`](AddHasOptionsDocCommentRector.php)
8+
9+
```diff
10+
+/**
11+
+ * @method \Guanguans\SoarPHP\Soar exceptVerbose() // Verbose
12+
+ * @method \Guanguans\SoarPHP\Soar exceptVersion() // Print version info
13+
+ * @method \Guanguans\SoarPHP\Soar exceptHelp() // Help
14+
+ *
15+
+ * @mixin \Guanguans\SoarPHP\Soar
16+
+ */
17+
trait HasOptions
18+
{
19+
}
20+
```
21+
22+
<br>
23+
24+
## AddSoarOptionsDocCommentRector
25+
26+
Add soar options doc comment
27+
28+
- class: [`Guanguans\SoarPHP\Support\Rectors\AddSoarOptionsDocCommentRector`](AddSoarOptionsDocCommentRector.php)
29+
30+
```diff
31+
return [
32+
+ // AllowCharsets (default "utf8,utf8mb4")
33+
'-allow-charsets' => [
34+
0 => 'utf8',
35+
1 => 'utf8mb4',
36+
],
37+
+
38+
+ // AllowCollates
39+
'-allow-collates' => [
40+
],
41+
+
42+
+ // AllowDropIndex, 允许输出删除重复索引的建议
43+
'-allow-drop-index' => false,
44+
];
45+
```
46+
47+
<br>
48+
49+
## SimplifyListIndexRector
50+
51+
Simplify list index
52+
53+
- class: [`Guanguans\SoarPHP\Support\Rectors\SimplifyListIndexRector`](SimplifyListIndexRector.php)
54+
55+
```diff
56+
[
57+
- 0 => 'delimiter',
58+
- 1 => 'orderbynull',
59+
- 2 => 'groupbyconst',
60+
+ 'delimiter',
61+
+ 'orderbynull',
62+
+ 'groupbyconst',
63+
]
64+
```
65+
66+
<br>

tests/Pest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@
3030
->beforeEach(function (): void {})
3131
->afterEach(function (): void {})
3232
->afterAll(function (): void {})
33-
->in(__DIR__, __DIR__.'/Feature', __DIR__.'/Unit');
33+
->in(
34+
__DIR__,
35+
__DIR__.'/Arch/',
36+
__DIR__.'/Feature/',
37+
__DIR__.'/Integration/',
38+
__DIR__.'/Unit/'
39+
);
3440
/*
3541
|--------------------------------------------------------------------------
3642
| Expectations

vendor-bin/common/composer.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"require-dev": {
3+
"symplify/rule-doc-generator": "^12.2"
4+
}
5+
}

0 commit comments

Comments
 (0)