1717
1818use function array_keys ;
1919use function dirname ;
20+ use function implode ;
2021use function ksort ;
22+ use function preg_match ;
2123use function sort ;
2224use function sprintf ;
2325use function str_ends_with ;
@@ -38,15 +40,19 @@ public function lint(File $file): File
3840 $ validators = $ this ->getSortedListOfValidators ();
3941
4042 $ validatorsByCategory = [];
43+ $ validatorsDescriptions = [];
44+ $ validatorsExamples = [];
4145 foreach ($ validators as $ validator ) {
42- foreach ($ this ->getCategoriesByValidator ($ validator ) as $ category ) {
46+ $ validatorInfo = $ this ->getValidatorInfo ($ validator );
47+ foreach ($ validatorInfo ['categories ' ] as $ category ) {
4348 $ validatorsByCategory [$ category ] ??= [];
4449 $ validatorsByCategory [$ category ][] = $ validator ;
50+ $ validatorsDescriptions [$ validator ] = $ validatorInfo ['description ' ];
51+ $ validatorsExamples [$ validator ] = $ validatorInfo ['example ' ];
4552 }
4653 }
4754
4855 ksort ($ validatorsByCategory );
49- $ validatorsByCategory ['Alphabetically ' ] = $ validators ;
5056
5157 $ categories = array_keys ($ validatorsByCategory );
5258
@@ -55,16 +61,33 @@ public function lint(File $file): File
5561 $ content ->emptyLine ();
5662
5763 foreach ($ categories as $ category ) {
58- $ content ->h2 ($ category );
5964 $ categoryValidators = $ validatorsByCategory [$ category ];
6065 sort ($ categoryValidators );
66+ $ refs = [];
6167 foreach ($ categoryValidators as $ categoryValidator ) {
62- $ content -> anchorListItem ( $ categoryValidator , sprintf ('validators/%s.md ' , $ categoryValidator) );
68+ $ refs [] = sprintf ('[%s][] ' , $ categoryValidator );
6369 }
6470
71+ $ content ->paragraph (sprintf ('**%s**: %s ' , $ category , implode (' - ' , $ refs )));
72+
6573 $ content ->emptyLine ();
6674 }
6775
76+ $ content ->h2 ('Alphabetically ' );
77+ foreach ($ validators as $ validator ) {
78+ $ content ->listItem (sprintf ('[%s][] - `%s` ' , $ validator , $ validatorsExamples [$ validator ]));
79+ }
80+
81+ $ content ->emptyLine ();
82+
83+ foreach (array_keys ($ validatorsDescriptions ) as $ validator ) {
84+ $ content ->reference (
85+ $ validator ,
86+ sprintf ('validators/%s.md ' , $ validator ),
87+ $ validatorsDescriptions [$ validator ],
88+ );
89+ }
90+
6891 return $ file ->withContent ($ content );
6992 }
7093
@@ -88,10 +111,22 @@ private function getSortedListOfValidators(): array
88111 }
89112
90113 /** @return array<string> */
91- private function getCategoriesByValidator (string $ validator ): array
114+ private function getValidatorInfo (string $ validator ): array
92115 {
93116 $ content = Content::from (sprintf ('%s/validators/%s.md ' , dirname (__DIR__ , 2 ) . '/../docs ' , $ validator ));
94117 $ section = $ content ->getSection ('## Categorization ' );
118+ $ description = '' ;
119+ $ example = '' ;
120+ foreach ($ content ->getSection (sprintf ('# %s ' , $ validator )) as $ line ) {
121+ if ($ description === '' && preg_match ('/^[A-Z]/ ' , $ line ) === 1 ) {
122+ $ description = $ line ;
123+ }
124+
125+ if (preg_match ('/^v::/ ' , $ line ) === 1 ) {
126+ $ example = $ line ;
127+ break ;
128+ }
129+ }
95130
96131 $ categories = [];
97132 foreach ($ section as $ line ) {
@@ -102,6 +137,10 @@ private function getCategoriesByValidator(string $validator): array
102137 $ categories [] = trim (substr ($ line , 1 ));
103138 }
104139
105- return $ categories ;
140+ return [
141+ 'categories ' => $ categories ,
142+ 'description ' => Content::stripRefs ($ description ),
143+ 'example ' => $ example ,
144+ ];
106145 }
107146}
0 commit comments