forked from adityapatwardhan/ps-codacy
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrunTool.ps1
More file actions
23 lines (22 loc) · 1011 Bytes
/
runTool.ps1
File metadata and controls
23 lines (22 loc) · 1011 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/env pwsh
if (Test-Path '/.codacyrc') {
$config = Get-Content '/.codacyrc' -Raw | ConvertFrom-Json ;
$files = $config.files | ForEach-Object { Join-Path '/src' -ChildPath $_ };
$rules = $config.tools | Where-Object { $_.name -eq 'psscriptanalyzer'} | ForEach-Object { $_.patterns.patternId };
}
if ($null -eq $rules) {
$rules = '*' ;
}
if ($null -eq $files) {
$output = Invoke-ScriptAnalyzer -Path /src -IncludeRule $rules -ExcludeRule PSUseDeclaredVarsMoreThanAssignments -Recurse;
} else {
$output = $files | ForEach-Object { Invoke-ScriptAnalyzer -Path $_ -IncludeRule $rules -ExcludeRule PSUseDeclaredVarsMoreThanAssignments -Recurse; }
}
$output | ForEach-Object {
$fileName = $_.ScriptPath.subString(5, $_.ScriptPath.Length-5) ;
$message = $_.message;
$patternId = $_.RuleName.ToLower();
$line = $_.line;
$result = [ordered] @{ filename = $fileName; message = $message; patternId = $patternId; line = $line };
$result | ConvertTo-Json -Compress
}