This repository was archived by the owner on Aug 8, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpslint.ps1
More file actions
44 lines (38 loc) · 1.23 KB
/
pslint.ps1
File metadata and controls
44 lines (38 loc) · 1.23 KB
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
38
39
40
41
42
43
44
Set-StrictMode -Version 3.0;
$ErrorActionPreference = "Stop";
trap { Write-Error $_ -ErrorAction Continue; exit 1 };
if ( Test-Path env:GITHUB_ACTIONS ) {
Install-Module -Name PSScriptAnalyzer -Force;
} else {
Install-Module -Name PSScriptAnalyzer;
}
$Exclude = @("output", "release");
$Files = Get-ChildItem -Path $PSScriptRoot -Directory -Name -Recurse -ErrorAction 'SilentlyContinue'
| Where-Object {
foreach ( $Name in $Exclude ) {
if ( ($_ -like "$Name\*") -or ($_ -eq $Name) ) {
return $false;
}
return $true;
}
}
| ForEach-Object {
Get-ChildItem -Path "$_\*.ps1" -ErrorAction 'SilentlyContinue';
}
$Files += Get-ChildItem -Path ".\*.ps1" -ErrorAction 'SilentlyContinue';
$Problems = [string[]]@();
foreach ($File in $Files) {
$Output = Invoke-ScriptAnalyzer -Path $File;
Write-Output "Analyzing '$File'";
foreach ($Data in $Output) {
$Problems += "$($Data.ScriptName):$($Data.Line)`t[$($Data.RuleName)]`t$($Data.Message)"
}
}
if ( $Problems.Count -ne 0 ) {
Write-Output "Problems found:";
foreach ( $Problem in $Problems ) {
Write-Output $Problem;
}
exit 1;
}
Write-Output "No problems found."