forked from PowerShell/PSReadLine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CheckHelp.ps1
62 lines (56 loc) · 2.06 KB
/
CheckHelp.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
Import-Module -Name PSReadline
$about_topic = Get-Help -Name about_PSReadline
$methods = [Microsoft.PowerShell.PSConsoleReadLine].GetMethods('public,static') |
Where-Object {
$method = $_
$parameters = $method.GetParameters()
$parameters.Count -eq 2 -and
$parameters[0].ParameterType -eq [Nullable[ConsoleKeyInfo]] -and
$parameters[1].ParameterType -eq [object]
}
foreach ($method in $methods)
{
$parameters = $method.GetParameters()
if ($parameters[0].Name -ne 'key' -or $parameters[1].Name -ne 'arg')
{
"Function $($method.Name) parameter names should be key and arg"
}
if (!$parameters[1].HasDefaultValue -or ($null -ne $parameters[1].DefaultValue))
{
"Function $($method.Name) arg parameter missing default"
}
if (!$parameters[0].HasDefaultValue -or ($null -ne $parameters[0].DefaultValue))
{
"Function $($method.Name) key parameter missing default"
}
}
$methods.Name | ForEach-Object {
if ($about_topic -cnotmatch "\n +$_ +")
{
"Function not documented: $_"
}
}
$commonParameters = Write-Output Debug Verbose OutVariable OutBuffer ErrorAction WarningAction ErrorVariable WarningVariable PipelineVariable
Get-Command -Type Cmdlet -Module PSReadline |
ForEach-Object {
$cmdletInfo = $_
$cmdletName = $cmdletInfo.Name
$cmdletHelp = Get-Help -Detailed $cmdletName
$cmdletInfo.Parameters.Keys |
ForEach-Object {
$parameterName = $_
if ($parameterName -notin $commonParameters)
{
$parameterHelp = $cmdletHelp.Parameters.parameter | Where-Object Name -eq $parameterName
if ($parameterHelp -eq $null)
{
"Parameter $parameterName not documented in cmdlet $cmdletName"
}
}
}
}
Get-PSReadlineKeyHandler |
Where-Object { $_.Function -eq $_.Description } |
ForEach-Object {
"Function missing description: $($_.Function)"
}