Skip to content

Commit

Permalink
Clean up PSScriptAnalyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaykul committed Oct 7, 2024
1 parent 76e474a commit c2e8937
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Reference/default.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function Get-ConciseViewPositionMessage {
$message = $message.Replace($newline, ' ').Replace("`n", ' ').Replace("`t", ' ')

$windowWidth = 120
if ($Host.UI.RawUI -ne $null) {
if ($null -ne $Host.UI.RawUI) {
$windowWidth = $Host.UI.RawUI.WindowSize.Width
}

Expand Down
4 changes: 4 additions & 0 deletions ScriptAnalyzerSettings.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@{
Severity = @('Error', 'Warning')
ExcludeRules = @('PSAvoidGlobalVars')
}
4 changes: 1 addition & 3 deletions source/private/GetConciseMessage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ filter GetConciseMessage {
$err = $InputObject
$posmsg = ''
$headerWhitespace = ''
$offsetWhitespace = ''
$message = ''
$prefix = ''

Expand Down Expand Up @@ -90,7 +89,6 @@ filter GetConciseMessage {
}

$posmsg += "${accentColor}${lineWhitespace}${ScriptLineNumber} ${verticalBar} ${resetcolor}${line}"
$offsetWhitespace = ' ' * $offsetInLine
$prefix = "${accentColor}${headerWhitespace} ${verticalBar} ${errorColor}"
if ($highlightLine -ne '') {
$posMsg += "${prefix}${highlightLine}${newline}"
Expand Down Expand Up @@ -122,7 +120,7 @@ filter GetConciseMessage {
$message = $message.Replace($newline, ' ').Replace("`n", ' ').Replace("`t", ' ')

$windowWidth = 120
if ($Host.UI.RawUI -ne $null) {
if ($null -ne $Host.UI.RawUI) {
$windowWidth = $Host.UI.RawUI.WindowSize.Width
}

Expand Down
20 changes: 10 additions & 10 deletions source/private/GetErrorMessage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ filter GetErrorTitle {
[System.Management.Automation.ErrorRecord]
$InputObject
)
if (! $err.ErrorDetails -or ! $err.ErrorDetails.Message) {
if ($err.CategoryInfo.Category -eq 'ParserError' -and $err.Exception.Message.Contains("~$newline")) {
if ($InputObject.ErrorDetails -and $InputObject.ErrorDetails.Message) {
$InputObject.ErrorDetails.Message
} else {
if ($InputObject.CategoryInfo.Category -eq 'ParserError' -and $InputObject.Exception.Message.Contains("~$newline")) {
# need to parse out the relevant part of the pre-rendered positionmessage
$err.Exception.Message.split("~$newline")[1].split("${newline}${newline}")[0]
} elseif ($err.Exception) {
$err.Exception.Message
} elseif ($err.Message) {
$err.Message
$InputObject.Exception.Message.split("~$newline")[1].split("${newline}${newline}")[0]
} elseif ($InputObject.Exception) {
$InputObject.Exception.Message
} elseif ($InputObject.Message) {
$InputObject.Message
} else {
$err.ToString()
$InputObject.ToString()
}
} else {
$err.ErrorDetails.Message
}
}
4 changes: 2 additions & 2 deletions source/public/ConvertTo-DetailedErrorView.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ filter ConvertTo-DetailedErrorView {
process {
$newline + (GetListRecursive $InputObject) + $newline
if ($Env:GITHUB_ACTIONS) {
Write-Host "::error $(GetGoogleWorkflowPositionMesage),title=$(GetErrorTitle $InputObject)::$(GetErrorMessage $InputObject)"
"::error $(GetGoogleWorkflowPositionMesage),title=$(GetErrorTitle $InputObject)::$(GetErrorMessage $InputObject)"
} elseif ($Env:TF_BUILD) {
Write-Host "##vso[task.logissue type=error;$(GetAzurePipelinesPositionMesage)]$(GetErrorTitle $InputObject): $(GetErrorMessage $InputObject)"
"##vso[task.logissue type=error;$(GetAzurePipelinesPositionMesage)]$(GetErrorTitle $InputObject): $(GetErrorMessage $InputObject)"
}
}
}
1 change: 1 addition & 0 deletions source/public/ConvertTo-YamlErrorView.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
.DESCRIPTION
This produces valid Yaml output from ErrorRecord you pass to it, recursively.
#>
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', 'maxDepth')]
[CmdletBinding()]
param(
# The object that you want to convert to YAML
Expand Down

0 comments on commit c2e8937

Please sign in to comment.