-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[PSR-5] enhancements #1339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
[PSR-5] enhancements #1339
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great
proposed/phpdoc.md
Outdated
@@ -208,7 +173,7 @@ Examples of use are included in chapter 5.4. | |||
|
|||
### 5.1. Summary | |||
|
|||
A Summary MUST contain an abstract of the "Structural Element" defining the | |||
A Summary MUST provide an abstract of the "Structural Element" defining the | |||
purpose. It is RECOMMENDED for Summaries to span a single line or two, but not |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"A single line or two" is very squishy language. Should we just require a single line? PER-CS gives you up to 120 characters...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is again based on the existing implementations of the tools reading docblocks. I took phpDocumentor as a standard here, since all tools are following. I'm not trying to set a new standard here, as the docblocks are already like this for many years.
But I get your point. We need to sharpen the definition here.
The full definition of a summary is complex. :-(
https://github.com/phpDocumentor/ReflectionDocBlock/blob/5.x/src/DocBlockFactory.php#L226C1-L238C14
# 2. Extract the summary
(?:
(?! @\pL ) # The summary may not start with an @
(
[^\n.]+
(?:
(?! \. \n | \n{2} ) # End summary upon a dot followed by newline or two newlines
[\n.]* (?! [ \t]* @\pL ) # End summary when an @ is found as first character on a new line
[^\n.]+ # Include anything else
)*
\.?
)?
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the wording a bit. To make it more explicit.
A Summary MUST be a concise abstract of the Structural Element’s purpose. It is RECOMMENDED to keep the Summary to a single line, though two lines MAY be used if needed.
The description MUST support Markdown as a formatting language. The | ||
description of the tag MAY start on the same line or next line. The following | ||
The description MUST support Markdown as a formatting language. The | ||
description of the tag MAY start on the same line or next line. The following |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this implicitly mean supporting HTML, too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also... which Markdown? :-) There are many flavors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we just have to pick CommonMark as that's the most common standard I know in markdown. The set is limited, but as far as I know, most tools support the syntax of CommonMark.
I need to do some more research on how other php based tools are doing this, but mostly it's just phpDocumentor doing this. I didn't find any other libraries that handle the description of docblocks in the wild. Apart from the IDE's. We would need some people from those sides to have a look at this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/yiisoft/yii2-apidoc, https://www.yiiframework.com/doc/api/2.0 are generated using it.
phpDocumentor supports inline tags in the description. Which has been part of the standard usage for docblocks. This inline description is supported by most editors supporting php. Therefor the inline tags belong in this spec.
since the introduction of static analysis tools in php we see that those tools (phpstan, psalm) both support prefixed tags in their parsing. By explicit mention the already supported syntax for those tags, we make sure to include those tool specs in the standard.
The types and keywords belong to specific tags. Which means when we focus just on docblock structure. They do not belong in this PSR. The text will be used in a PER focusing on tags.
Co-authored-by: Pol Dellaiera <[email protected]>
I updated the document with some small improvements regarding "summary" and an extra section about the usage of Markdown in descriptions. Please let me know what you think. |
This pull request introduces enhancements to the PHPDoc specification (
proposed/phpdoc.md
) by refining tag handling and adding support for inline tags. The most important changes include updates to the ABNF definition for tags, the introduction of inline tags, and the addition of tag specialization for improved metadata organization.Enhancements to tag handling:
Updated the ABNF definition to modify the syntax for
tag-specialization
andtag
:tag-specialization
now excludes the-
character, andtag
syntax includes an optional specialization prefix followed by a hyphen.Added the concept of tag specialization (
5.3.1 Tag Specialization
) to provide a scoped context for tags. Specialized tags can differ from the standard catalog, and parsers may ignore unsupported specialized tags.Support for inline tags:
5.2.1 Inline tags
) within descriptions. Inline tags must start with{@
and end with}
. Escaping is supported for closing braces using{}
. Inline tags are limited to regular tags and do not apply to annotation tags.Structural refinements:
Minor Adjustments: