function Invoke-Linter() { <# .SYNOPSIS Runs all PSScriptAnalyzer Rules within this repo. .DESCRIPTION This Cmdlet is used in Drone pipeline to run the PSScriptAnalyzer rules.. .INPUTS [None] No pipeline input. .OUTPUTS [None] No pipeline output. .EXAMPLE Invoke-Linter #> [CmdletBinding()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute( 'PSUseConsistentWhitespace', '', Justification = 'Hashtable bug in ScriptAnalyzer 1.19.1' )] param() process { $Repo = Get-RepoPath # Use repo local defaults. if not present use the DroneHelper included as defaults. if ($Repo.Resources.ScriptAnalyzerSettingsExist) { $currentRules = $Repo.Resources.ScriptAnalyzerSettingsPath } else { $currentRules = $repo.DroneHelper.ScriptAnalyzerDefaultsPath } $AnalyzerParams = @{ Path = $Repo.Src.Path Recurse = $true Settings = $currentRules Verbose = $VerbosePreference ReportSummary = $true } $AnalyzerResults = Invoke-ScriptAnalyzer @AnalyzerParams if ( $AnalyzerResults ) { $AnalyzerResults | Sort-Object -Property @( "ScriptName", "Line" ) | Format-Table @( "Severity", "ScriptName", "Line", "RuleName", "Message" ) -AutoSize | Out-String | Write-Verbose -Verbose $ResultParams = @{ Type = 'PSScriptAnalyzer' Path = $Repo.Build.ScriptAnalyzerLogPath InputObject = $AnalyzerResults } Write-ResultFile @ResultParams Write-FailureStateFile -StepName 'PSScriptAnalyzer' throw 'PS Script Analyzer failed!' } else { $ResultParams = @{ Type = 'Custom' Path = $Repo.Build.ScriptAnalyzerLogPath InputObject = ':heavy_check_mark: No violations found.' } Write-ResultFile @ResultParams } } }