ProvideCommentHelp

严重性级别:信息

默认状态:启用

描述

该规则检测没有基于注释帮助的函数和命令小子。 每个PowerShell命令都应包含基于注释的帮助,以记录其目的、参数和使用情况。 PSScriptAnalyzer 会检查是否有基于评论的帮助,但不会验证其内容或格式。

如需评论帮助,请使用该命令 Get-Help about_comment_based_help 或参考以下资源:

非符合性

function Get-File
{
    [CmdletBinding()]
    Param
    (
        ...
    )

}

合规的

<#
.Synopsis
    Short description
.DESCRIPTION
    Long description
.EXAMPLE
    Example of how to use this cmdlet
.EXAMPLE
    Another example of how to use this cmdlet
.INPUTS
    Inputs to this cmdlet (if any)
.OUTPUTS
    Output from this cmdlet (if any)
.NOTES
    General notes
.COMPONENT
    The component this cmdlet belongs to
.ROLE
    The role this cmdlet belongs to
.FUNCTIONALITY
    The functionality that best describes this cmdlet
#>

function Get-File
{
    [CmdletBinding()]
    Param
    (
        ...
    )

}

配置规则

Rules = @{
    PSProvideCommentHelp = @{
        Enable = $true
        ExportedOnly = $false
        BlockComment = $true
        VSCodeSnippetCorrection = $false
        Placement = 'before'
    }
}

参数

启用

该参数控制 ScriptAnalyzer 是否会根据该规则检查代码。 它接受一个布尔值。 默认值为 $true

仅导出

该参数控制是否仅报告使用 Export-ModuleMember 该命令的函数和命令子。 它接受一个布尔值。 默认值为 $true

封锁评论

该参数控制规则返回的评论帮助风格。 它接受一个布尔值。 当设置为 $true时,评论帮助以块式评论风格<#...#>返回()。 当设置为 $false时,评论帮助以行注释样式返回,每条评论行以 开头。# 默认值为 $true

VSCodeSnippetCorrection

该参数控制评论帮助是否以 Visual Studio Code 摘要格式返回。 它接受一个布尔值。 默认值为 $false

安置

该参数控制注释帮助相对于函数定义的位置。 它接受字符串值。 如果给定了任何无效值,则属性默认为 before。 默认值为 before

可能的值为:

  • before:注释置于函数定义之前
  • begin:注释置于函数定义体的开头
  • end: 注释置于函数定义正文末尾