Repository navigation
Description
Prerequisites
- Existing Issue: Search the existing issues for this repository. If there is an issue that fits your needs do not file a new one. Subscribe, react, or comment on that issue instead.
- Descriptive Title: Write the title for this issue as a short synopsis. If possible, provide context. For example, "Typo in
Get-Foocmdlet" instead of "Typo." - Verify Version: If there is a mismatch between documentation and the behavior on your system, ensure that the version you are using is the same as the documentation. Check this box if they match or the issue you are reporting is not version specific.
Links
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_requires?view=powershell-7.6#rules-for-use
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_comments?view=powershell-7.6#comment-based-help
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_comments?view=powershell-7.6#requires
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_comment_based_help?view=powershell-7.6#syntax-for-comment-based-help-in-scripts
Summary
None of the pages that describe #Requires or comment-based help say whether a #Requires statement should come before or after a script's comment-based help block, or whether the two interact at all. The pages only say #Requires can appear on any line, and separately say script help may be preceded only by comments and blank lines. They never connect the two, and no example shows a script that has both. Readers (and team style guides) are left to infer an order the documentation does not specify.
Details
What the pages say today (PowerShell 7.6 docs):
about_Requires, "Rules for use":
The #Requires statements can appear on any line in a script.
about_Comments, "#Requires":
#Requires can appear on any line in a script, but is processed in the same manner regardless of position.
about_Comment_Based_Help, "Syntax for comment-based help in scripts":
At the beginning of the script file. Script help can be preceded in the script only by comments and blank lines.
If the first item in the script body (after the help) is a function declaration, there must be at least two blank lines between the end of the script help and the function declaration.
about_Comment_Based_Help, "Syntax for comment-based help":
If a comment-based help topic follows a comment that's not part of the help topic, there must be at least one blank line between the last non-help comment line and the beginning of the comment-based help.
What is left unanswered:
- Is a script that starts with
#Requires... followed by the help block valid, or must the help block come first? "Can be preceded ... only by comments and blank lines" does not say whether a#Requiresline counts as a comment for this rule. - Is a script with the help block first and
#Requiresafter it (before param()) equally valid? "Any line" suggests yes, but the two topics never say so together. - Does a
#Requiresline placed directly above <# count as a "non-help comment" needing a blank line before the help block? - Does a
#Requiresline between the help block and a function declaration or param() block count towards the "at least two blank lines" spacing rule? - For a signed script, where help is advised to be at the beginning of the file, does that advice change the ordering?
Each of these pages is correct on its own, but a reader who needs both features in one script cannot tell from the documentation which ordering is supported, so unwritten rules (such as "#Requires must go after the help") get passed around as if they were documented.
No page currently contains an example script with both a #Requires statement and a comment-based help block.
Suggested Fix
- Add a short note to the scripts section of about_Comment_Based_Help stating explicitly whether
#Requiresmay appear before the help block, and whether it counts as a "comment" for the "preceded only by comments and blank lines" rule. - Add a matching sentence to "Rules for use" in about_Requires (and the #Requires section of about_Comments), linking to the comment-based help guidance.
- Add one example script showing a
#Requiresstatement and a comment-based help block together, with the blank-line spacing the help parser expects before param() or the first function declaration. - Cross-link about_Requires and about_Comment_Based_Help so each points to the other.
Activity