summaryrefslogtreecommitdiffstats
path: root/test/lib/ansible_test/_util/controller/sanity/pslint/pslint.ps1
blob: 0cf3c7fcaaf8f01928040d1dbbc22873f1e1ca95 (plain)
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
#Requires -Version 6
#Requires -Modules PSScriptAnalyzer, PSSA-PSCustomUseLiteralPath

$ErrorActionPreference = "Stop"
$WarningPreference = "Stop"

$LiteralPathRule = Import-Module -Name PSSA-PSCustomUseLiteralPath -PassThru
$LiteralPathRulePath = Join-Path -Path $LiteralPathRule.ModuleBase -ChildPath $LiteralPathRule.RootModule

$PSSAParams = @{
    CustomRulePath = @($LiteralPathRulePath)
    IncludeDefaultRules = $true
    Setting = (Join-Path -Path $PSScriptRoot -ChildPath "settings.psd1")
}

$Results = @(
    ForEach ($Path in $Args) {
        $Retries = 3

        Do {
            Try {
                Invoke-ScriptAnalyzer -Path $Path @PSSAParams 3> $null
                $Retries = 0
            }
            Catch {
                If (--$Retries -le 0) {
                    Throw
                }
            }
        }
        Until ($Retries -le 0)
    }
)

# Since pwsh 7.1 results that exceed depth will produce a warning which fails the process.
# Ignore warnings only for this step.
ConvertTo-Json -InputObject $Results -Depth 1 -WarningAction SilentlyContinue