Skip to content

Commit f131ef0

Browse files
committed
Add more named tags
1 parent ed67ca3 commit f131ef0

27 files changed

Lines changed: 635 additions & 67 deletions

docs/Writerside/tl.tree

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,11 @@
186186
<toc-element topic="psalm-self-out-tag.md" />
187187
<toc-element topic="psalm-stub-override-tag.md" />
188188
<toc-element topic="psalm-suppress-tag.md" />
189-
<toc-element topic="psalm-taint-escape-tag.md" wip="true" />
189+
<toc-element topic="psalm-taint-escape-tag.md" />
190190
<toc-element topic="psalm-taint-sink-tag.md" wip="true" />
191-
<toc-element topic="psalm-taint-source-tag.md" wip="true" />
191+
<toc-element topic="psalm-taint-source-tag.md" />
192192
<toc-element topic="psalm-taint-specialize-tag.md" />
193-
<toc-element topic="psalm-taint-unescape-tag.md" wip="true" />
193+
<toc-element topic="psalm-taint-unescape-tag.md" />
194194
<toc-element topic="psalm-template-tag.md" />
195195
<toc-element topic="psalm-template-contravariant-tag.md" />
196196
<toc-element topic="psalm-template-covariant-tag.md" />
@@ -285,19 +285,19 @@
285285
<toc-element topic="phanclosurescope-tag.md" />
286286
</toc-element>
287287
<toc-element toc-title="PhpStorm" topic="phpstorm-tags.md">
288-
<toc-element topic="noinspection-tag.md" wip="true" />
289-
<toc-element topic="language-tag.md" wip="true" />
288+
<toc-element topic="noinspection-tag.md" />
289+
<toc-element topic="language-tag.md" />
290290
<toc-element topic="expected-exception-tag.md" />
291291
<toc-element topic="formatter-off-tag.md" />
292292
<toc-element topic="formatter-on-tag.md" />
293293
</toc-element>
294294
<toc-element toc-title="PHP CodeSniffer" topic="phpcs-tags.md">
295-
<toc-element topic="phpcs-suppress-tag.md" wip="true" />
295+
<toc-element topic="phpcs-suppress-tag.md" />
296296
<toc-element topic="coding-standards-ignore-start-tag.md" />
297297
<toc-element topic="coding-standards-ignore-end-tag.md" />
298298
<toc-element topic="coding-standards-ignore-line-tag.md" />
299299
<toc-element topic="coding-standards-ignore-file-tag.md" />
300-
<toc-element topic="coding-standards-tag.md" wip="true" />
300+
<toc-element topic="coding-standards-tag.md" />
301301
</toc-element>
302302
<toc-element topic="custom-tags.md" toc-title="Custom Tags">
303303
<toc-element topic="tags.md" />
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# @codingStandards
22

33
<primary-label ref="phpdoc-component"/>
4-
<secondary-label ref="not-implemented"/>
54

65
The `@codingStandards` tag names a coding standard for reference. This is
76
pre-3.2.0 PHP_CodeSniffer-era syntax; current PHP_CodeSniffer prefers the
@@ -11,12 +10,12 @@ pre-3.2.0 PHP_CodeSniffer-era syntax; current PHP_CodeSniffer prefers the
1110
"@codingStandards" <Name> [ <Description> ]
1211
```
1312

14-
<note>
15-
Not yet recognized by <code>TypeLang\PhpDoc\DocBlockParser</code> — parsing
16-
a docblock containing this tag returns a plain <code>Tag</code>, its whole
17-
suffix folded into the description. See
18-
<a href="custom-tags.md">Custom Tags</a> for the current workaround if you
19-
need to recognize it yourself.
20-
</note>
13+
Parsing a `@codingStandards` tag produces a `CodingStandardsTag` instance, carrying the
14+
parsed `$identifier` alongside the `$name` and optional `$description`
15+
every [Tag](phpdoc.md#tag) already provides.
16+
17+
```php
18+
final class CodingStandardsTag extends IdentifierTag {}
19+
```
2120

2221
Associated with PHP_CodeSniffer.
Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
# @language
22

33
<primary-label ref="phpdoc-component"/>
4-
<secondary-label ref="not-implemented"/>
54

65
The `@language` tag injects a foreign-language grammar — SQL, HTML,
76
regular expressions, and the like — into a string literal, so PhpStorm can
87
apply the right syntax highlighting and completion inside it.
98

109
```
11-
"@language" <Name>
10+
"@language" <Name> [ <Description> ]
1211
```
1312

14-
<note>
15-
Not yet recognized by <code>TypeLang\PhpDoc\DocBlockParser</code> — parsing
16-
a docblock containing this tag returns a plain <code>Tag</code>, its whole
17-
suffix folded into the description. See
18-
<a href="custom-tags.md">Custom Tags</a> for the current workaround if you
19-
need to recognize it yourself.
20-
</note>
13+
Parsing a `@language` tag produces a `LanguageTag` instance, carrying the
14+
parsed `$identifier` alongside the `$name` and optional `$description`
15+
every [Tag](phpdoc.md#tag) already provides.
16+
17+
```php
18+
final class LanguageTag extends IdentifierTag {}
19+
```
2120

2221
Associated with PhpStorm; no dedicated JetBrains page documenting this
2322
exact doc-comment tag could be confirmed.
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# @noinspection
22

33
<primary-label ref="phpdoc-component"/>
4-
<secondary-label ref="not-implemented"/>
54

65
The `@noinspection` tag suppresses one or more named IDE inspections for
76
the element that follows it, so PhpStorm stops flagging a specific,
@@ -11,12 +10,12 @@ intentional pattern in that spot.
1110
"@noinspection" <Name> [ <Description> ]
1211
```
1312

14-
<note>
15-
Not yet recognized by <code>TypeLang\PhpDoc\DocBlockParser</code> — parsing
16-
a docblock containing this tag returns a plain <code>Tag</code>, its whole
17-
suffix folded into the description. See
18-
<a href="custom-tags.md">Custom Tags</a> for the current workaround if you
19-
need to recognize it yourself.
20-
</note>
13+
Parsing a `@noinspection` tag produces a `NoinspectionTag` instance, carrying the
14+
parsed `$identifier` alongside the `$name` and optional `$description`
15+
every [Tag](phpdoc.md#tag) already provides.
16+
17+
```php
18+
final class NoinspectionTag extends IdentifierTag {}
19+
```
2120

2221
Defined by [PhpStorm](https://www.jetbrains.com/help/phpstorm/disabling-and-enabling-inspections.html).
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# @phpcsSuppress
22

33
<primary-label ref="phpdoc-component"/>
4-
<secondary-label ref="not-implemented"/>
54

65
The `@phpcsSuppress` tag is pre-3.2.0 PHP_CodeSniffer syntax for
76
suppressing named coding-standard checks; current PHP_CodeSniffer prefers
@@ -12,12 +11,12 @@ tag-based forms.
1211
"@phpcsSuppress" <Name> [ <Description> ]
1312
```
1413

15-
<note>
16-
Not yet recognized by <code>TypeLang\PhpDoc\DocBlockParser</code> — parsing
17-
a docblock containing this tag returns a plain <code>Tag</code>, its whole
18-
suffix folded into the description. See
19-
<a href="custom-tags.md">Custom Tags</a> for the current workaround if you
20-
need to recognize it yourself.
21-
</note>
14+
Parsing a `@phpcsSuppress` tag produces a `PhpcsSuppressTag` instance, carrying the
15+
parsed `$identifier` alongside the `$name` and optional `$description`
16+
every [Tag](phpdoc.md#tag) already provides.
17+
18+
```php
19+
final class PhpcsSuppressTag extends IdentifierTag {}
20+
```
2221

2322
Associated with PHP_CodeSniffer.
Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
# @psalm-taint-escape
22

33
<primary-label ref="phpdoc-component"/>
4-
<secondary-label ref="not-implemented"/>
54

65
The `@psalm-taint-escape` tag marks a value as no longer tainted
76
after passing through the described element. It is part of Psalm's
87
taint-analysis annotations.
98

109
```
11-
"@psalm-taint-escape" <Name>
10+
"@psalm-taint-escape" <Name> [ <Description> ]
1211
```
1312

14-
<note>
15-
Not yet recognized by <code>TypeLang\PhpDoc\DocBlockParser</code> — parsing
16-
a docblock containing this tag returns a plain <code>Tag</code>, its whole
17-
suffix folded into the description. See
18-
<a href="custom-tags.md">Custom Tags</a> for the current workaround if you
19-
need to recognize it yourself.
20-
</note>
13+
Parsing a `@psalm-taint-escape` tag produces a `PsalmTaintEscapeTag` instance, carrying the
14+
parsed `$identifier` alongside the `$name` and optional `$description`
15+
every [Tag](phpdoc.md#tag) already provides.
16+
17+
```php
18+
final class PsalmTaintEscapeTag extends IdentifierTag {}
19+
```
2120

2221
See [Psalm's security analysis annotations](https://psalm.dev/docs/security_analysis/annotations/).
Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
# @psalm-taint-source
22

33
<primary-label ref="phpdoc-component"/>
4-
<secondary-label ref="not-implemented"/>
54

65
The `@psalm-taint-source` tag marks the return value as a taint
76
source of the given type. It is part of Psalm's taint-analysis
87
annotations.
98

109
```
11-
"@psalm-taint-source" <Name>
10+
"@psalm-taint-source" <Name> [ <Description> ]
1211
```
1312

14-
<note>
15-
Not yet recognized by <code>TypeLang\PhpDoc\DocBlockParser</code> — parsing
16-
a docblock containing this tag returns a plain <code>Tag</code>, its whole
17-
suffix folded into the description. See
18-
<a href="custom-tags.md">Custom Tags</a> for the current workaround if you
19-
need to recognize it yourself.
20-
</note>
13+
Parsing a `@psalm-taint-source` tag produces a `PsalmTaintSourceTag` instance, carrying the
14+
parsed `$identifier` alongside the `$name` and optional `$description`
15+
every [Tag](phpdoc.md#tag) already provides.
16+
17+
```php
18+
final class PsalmTaintSourceTag extends IdentifierTag {}
19+
```
2120

2221
See [Psalm's security analysis annotations](https://psalm.dev/docs/security_analysis/annotations/#psalm-taint-source-lttaint-typegt).
Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
# @psalm-taint-unescape
22

33
<primary-label ref="phpdoc-component"/>
4-
<secondary-label ref="not-implemented"/>
54

65
The `@psalm-taint-unescape` tag marks a value as tainted again after
76
passing through the described element, reversing an earlier
87
[@psalm-taint-escape](psalm-taint-escape-tag.md). It is part of
98
Psalm's taint-analysis annotations.
109

1110
```
12-
"@psalm-taint-unescape" <Name>
11+
"@psalm-taint-unescape" <Name> [ <Description> ]
1312
```
1413

15-
<note>
16-
Not yet recognized by <code>TypeLang\PhpDoc\DocBlockParser</code> — parsing
17-
a docblock containing this tag returns a plain <code>Tag</code>, its whole
18-
suffix folded into the description. See
19-
<a href="custom-tags.md">Custom Tags</a> for the current workaround if you
20-
need to recognize it yourself.
21-
</note>
14+
Parsing a `@psalm-taint-unescape` tag produces a `PsalmTaintUnescapeTag` instance, carrying the
15+
parsed `$identifier` alongside the `$name` and optional `$description`
16+
every [Tag](phpdoc.md#tag) already provides.
17+
18+
```php
19+
final class PsalmTaintUnescapeTag extends IdentifierTag {}
20+
```
2221

2322
See [Psalm's security analysis annotations](https://psalm.dev/docs/security_analysis/annotations/).
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TypeLang\PhpDoc\DocBlock\Tag\CodingStandardsTag;
6+
7+
use TypeLang\PhpDoc\DocBlock\Tag\IdentifierTag;
8+
9+
/**
10+
* The "@codingStandards" tag names a coding standard for reference.
11+
*/
12+
final class CodingStandardsTag extends IdentifierTag {}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TypeLang\PhpDoc\DocBlock\Tag\CodingStandardsTag;
6+
7+
use TypeLang\PhpDoc\DocBlock\Combinator\DescriptionCombinator;
8+
use TypeLang\PhpDoc\DocBlock\Combinator\NameCombinator;
9+
use TypeLang\PhpDoc\DocBlock\Description\DescriptionInterface;
10+
use TypeLang\PhpDoc\DocBlock\TagDefinition\Spec;
11+
use TypeLang\PhpDoc\DocBlock\TagDefinition\TagDefinition;
12+
use TypeLang\PhpDoc\DocBlock\TagDefinition\TagPayload;
13+
use TypeLang\PhpDoc\DocBlock\TagDefinition\TagPlacement;
14+
15+
/**
16+
* The "`@codingStandards`" tag names a coding standard for reference.
17+
*
18+
* ```
19+
* "@codingStandards" <Name> [ <Description> ]
20+
* ```
21+
*/
22+
final class CodingStandardsTagDefinition extends TagDefinition
23+
{
24+
public const string NAME = 'codingStandards';
25+
26+
public function __construct()
27+
{
28+
parent::__construct(
29+
name: self::NAME,
30+
spec: Spec::sequence(
31+
Spec::rule(NameCombinator::NAME, 'identifier'),
32+
Spec::maybe(
33+
Spec::rule(DescriptionCombinator::NAME, 'description'),
34+
),
35+
),
36+
placement: TagPlacement::Block,
37+
);
38+
}
39+
40+
public function create(string $name, TagPayload $result): CodingStandardsTag
41+
{
42+
/** @var non-empty-string $identifier */
43+
$identifier = $result->get('identifier');
44+
45+
/** @var DescriptionInterface|null $description */
46+
$description = $result->find('description');
47+
48+
return new CodingStandardsTag($name, $identifier, $description);
49+
}
50+
}

0 commit comments

Comments
 (0)