Public/Invoke-PSPlumbingScriptAnalyzer.ps1
|
function Invoke-PSPlumbingScriptAnalyzer { [CmdletBinding(DefaultParameterSetName = 'Path')] param( [Parameter(Mandatory, ParameterSetName = 'Path', Position = 0, ValueFromPipeline, ValueFromPipelineByPropertyName)] [string[]] $Path, [Parameter(Mandatory, ParameterSetName = 'ScriptDefinition')] [string] $ScriptDefinition, [string[]] $IncludeRule, [string[]] $ExcludeRule, [string[]] $Severity, [string] $Settings, [switch] $Recurse, [switch] $Fix, [switch] $SuppressedOnly, [switch] $ReportSummary ) Import-Module PSScriptAnalyzer -Force $invokeParams = @{ CustomRulePath = Get-PSPlumbingRulePath } if ($PSCmdlet.ParameterSetName -ne 'Path') { $invokeParams.ScriptDefinition = $ScriptDefinition } foreach ($name in 'Settings') { if ($PSBoundParameters.ContainsKey($name)) { $invokeParams[$name] = $PSBoundParameters[$name] } } foreach ($name in 'Recurse', 'Fix', 'SuppressedOnly', 'ReportSummary') { if ($PSBoundParameters.ContainsKey($name) -and $PSBoundParameters[$name].IsPresent) { $invokeParams[$name] = $true } } $diagnostics = @() if ($PSCmdlet.ParameterSetName -eq 'Path') { foreach ($inputPath in @($Path)) { $pathInvokeParams = @{} foreach ($entry in $invokeParams.GetEnumerator()) { $pathInvokeParams[$entry.Key] = $entry.Value } $pathInvokeParams.Path = $inputPath $diagnostics += @(Invoke-ScriptAnalyzer @pathInvokeParams) } } else { $diagnostics = @(Invoke-ScriptAnalyzer @invokeParams) } if ($PSBoundParameters.ContainsKey('IncludeRule')) { $diagnostics = @($diagnostics | Where-Object { $IncludeRule -contains $_.RuleName }) } if ($PSBoundParameters.ContainsKey('ExcludeRule')) { $diagnostics = @($diagnostics | Where-Object { $ExcludeRule -notcontains $_.RuleName }) } if ($PSBoundParameters.ContainsKey('Severity')) { $diagnostics = @($diagnostics | Where-Object { $Severity -contains $_.Severity.ToString() }) } $diagnostics } |