OCram85/DroneHelper
OCram85
/
DroneHelper
Archived
1
0
Fork 0
This repository has been archived on 2023-10-10. You can view files and clone it, but cannot push or open issues or pull requests.
DroneHelper/src/PSScriptAnalyzer/Invoke-Linter.ps1

72 lines
2.3 KiB
PowerShell

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
}
}
}