Skip to content
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

fix #1417 modulehelp false positives #1418

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions Tests/Engine/ModuleHelp.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,19 @@ Get-Module $ModuleName | Remove-Module
Import-Module $ModuleName -RequiredVersion $RequiredVersion -ErrorAction Stop
$ms = $null
$commands =$null
$paramBlackList = @()
$paramBlackList = @(
'AttachAndDebug' # Reason: When building with DEGUG configuration, an additional parameter 'AttachAndDebug' will be added to Invoke-ScriptAnalyzer and Invoke-Formatter, but there is no Help for those, as they are not intended for production usage.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change absolutely makes sense, I could reproduce the failure locally using a debug build. Thanks for taking the time to fix it.

)
if ($PSVersionTable.PSVersion -lt [Version]'5.0.0') {
$ms = New-Object -TypeName 'Microsoft.PowerShell.Commands.ModuleSpecification' -ArgumentList $ModuleName
$commands = Get-Command -Module $ms.Name
$paramBlackList += 'SaveDscDependency'
}
else {
$ms = [Microsoft.PowerShell.Commands.ModuleSpecification]@{ ModuleName = $ModuleName; RequiredVersion = $RequiredVersion }
$commands = Get-Command -FullyQualifiedModule $ms -CommandType Cmdlet,Function,Workflow # Not alias
# Because on Windows Powershell we have workflow, we need to include it there, but in pwsh, we can't. This makes sure this works on both.
$commandTypes = ([System.Enum]::GetNames("System.Management.Automation.CommandTypes") -match "^Cmdlet$|^Function$|^Workflow$")
$commands = Get-Command -FullyQualifiedModule $ms -CommandType $commandTypes
Copy link
Collaborator

@bergmeister bergmeister Feb 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ms is just PSScriptAnalyzer in this case if I read correctly and PSSA only exports 3 cmdlets, no function/alias/workflow at all, therefore why not simplify it to just:

$commands = Get-Command -FullyQualifiedModule $ms

I could reproduce the error where it complains about workflows locally and just using the proposed line worked fine as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, makes a lot of sense. will do that.

}

## When testing help, remember that help is cached at the beginning of each session.
Expand Down Expand Up @@ -276,7 +280,7 @@ foreach ($command in $commands) {
$HelpParameterNames = $Help.Parameters.Parameter.Name | Sort-Object -Unique

foreach ($parameter in $parameters) {
if ($parameter -in $paramBlackList) {
if ($parameter.Name -in $paramBlackList) {
continue
}
$parameterName = $parameter.Name
Expand Down