ps/Modules/Alkami.PowerShell.PSScriptAnalyzerRules/Public/Measure-HelpSynopsis.ps1
2023-05-30 22:51:22 -07:00

45 lines
1.7 KiB
PowerShell

function Measure-HelpSynopsis {
<#
.SYNOPSIS
Add a SYNOPSIS keyword in your comment-based help.
.DESCRIPTION
Comment-based help is written as a series of comments. You can write comment-based help topics for end users to better understand your functions. Additionally, it's better to explain the detail about how the function works.
To fix a violation of this rule, add a .SYNOPSIS keyword in your comment-based help. You can get more details by running: Get-Help about_Comment_Based_Help
.EXAMPLE
Measure-HelpSynopsis -FunctionDefinitionAst $FunctionDefinitionAst
.INPUTS
[System.Management.Automation.Language.FunctionDefinitionAst]
.OUTPUTS
[Microsoft.Windows.Powershell.ScriptAnalyzer.Generic.DiagnosticRecord[]]
.NOTES
Reference: Writing Help and Comments, Windows PowerShell Best Practices.
#>
[CmdletBinding()]
[OutputType([Microsoft.Windows.Powershell.ScriptAnalyzer.Generic.DiagnosticRecord[]])]
Param
(
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.Management.Automation.Language.FunctionDefinitionAst]
$FunctionDefinitionAst
)
Process {
$results = @()
$message = (Get-Help $MyInvocation.MyCommand.Name).Synopsis
try {
if (!$FunctionDefinitionAst.GetHelpContent().Synopsis) {
$result = New-Object `
-Typename "Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.DiagnosticRecord" `
-ArgumentList $message,$FunctionDefinitionAst.Extent,$PSCmdlet.MyInvocation.InvocationName,Warning,$null
$results += $result
}
return $results
} catch {
$PSCmdlet.ThrowTerminatingError($PSItem)
}
}
}