From 478c8d57ef90f13157cf8eb158b8bc3a9636efd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Wed, 3 Jul 2024 17:44:25 +0200 Subject: [PATCH 01/11] Fixing that file path/line/column weren't displayed for violations during GHA workflows --- Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 b/Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 index 47222c6..8cb3539 100644 --- a/Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 +++ b/Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 @@ -49,7 +49,7 @@ function Write-FileError([string] $Message, [string] $Path, [int] $Line = 0, [in if ($ForGitHubActions) { $Message = $Message -replace '\s*(\r?\n\s*)+', ' ' - Write-Output "::error$(if ($Path) { " file=$Path,line=$Line,col=$Column::$Message" } else { "::$Message" })" + Write-Output "::error$(if ($Path) { " title=$Path (Line: $Line; Column: $Column)::$Message" } else { "::$Message" })" } elseif ($ForMsBuild) { From 5c64126c41308094fa14494db56225e9fa9f0e51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Wed, 3 Jul 2024 17:45:04 +0200 Subject: [PATCH 02/11] Pointing GHA to issue branch --- .github/workflows/static-code-analysis-this-repo.yml | 2 +- .github/workflows/static-code-analysis.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/static-code-analysis-this-repo.yml b/.github/workflows/static-code-analysis-this-repo.yml index 2188010..a5a0c8e 100644 --- a/.github/workflows/static-code-analysis-this-repo.yml +++ b/.github/workflows/static-code-analysis-this-repo.yml @@ -10,7 +10,7 @@ on: jobs: powershell-static-code-analysis: name: PowerShell Static Code Analysis - uses: Lombiq/PowerShell-Analyzers/.github/workflows/static-code-analysis.yml@dev + uses: Lombiq/PowerShell-Analyzers/.github/workflows/static-code-analysis.yml@issue/OSOE-875 with: # Making sure that analysis runs through both PowerShell editions regardless of the default configuration of the # workflow and the underlying action to ensure backwards-compatibility. diff --git a/.github/workflows/static-code-analysis.yml b/.github/workflows/static-code-analysis.yml index d4b0d04..a74fc24 100644 --- a/.github/workflows/static-code-analysis.yml +++ b/.github/workflows/static-code-analysis.yml @@ -79,7 +79,7 @@ jobs: token: ${{ secrets.CHECKOUT_TOKEN }} - name: PowerShell Static Code Analysis - uses: Lombiq/PowerShell-Analyzers/.github/actions/static-code-analysis@dev + uses: Lombiq/PowerShell-Analyzers/.github/actions/static-code-analysis@issue/OSOE-875 with: run-windows-powershell: ${{ inputs.run-windows-powershell }} run-powershell-core: ${{ inputs.run-powershell-core }} From a99adbcf853fc540b4989889ae5cd4f4c8e617c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Wed, 3 Jul 2024 17:48:16 +0200 Subject: [PATCH 03/11] Error annotation doesn't work --- Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 b/Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 index 8cb3539..e2a98fd 100644 --- a/Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 +++ b/Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 @@ -49,7 +49,7 @@ function Write-FileError([string] $Message, [string] $Path, [int] $Line = 0, [in if ($ForGitHubActions) { $Message = $Message -replace '\s*(\r?\n\s*)+', ' ' - Write-Output "::error$(if ($Path) { " title=$Path (Line: $Line; Column: $Column)::$Message" } else { "::$Message" })" + Write-Output "::error::$Message $(if ($Path) { "(Path: $Path; Line: $Line; Column: $Column)" })" } elseif ($ForMsBuild) { From 69fa6759acb5ecf36df2afe5f4fafa3f053bdaeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Wed, 3 Jul 2024 17:52:32 +0200 Subject: [PATCH 04/11] Formatting analyzer violation error similar to MSBuild errors --- Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 b/Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 index e2a98fd..cf3cbcf 100644 --- a/Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 +++ b/Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 @@ -49,7 +49,7 @@ function Write-FileError([string] $Message, [string] $Path, [int] $Line = 0, [in if ($ForGitHubActions) { $Message = $Message -replace '\s*(\r?\n\s*)+', ' ' - Write-Output "::error::$Message $(if ($Path) { "(Path: $Path; Line: $Line; Column: $Column)" })" + Write-Output "::error::$(if ($Path) { "$Path($Line,$Column): " })$Message)" } elseif ($ForMsBuild) { From 27c0fdb455e8bb4a338fca6f0d5c844948c75e9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Wed, 3 Jul 2024 17:54:33 +0200 Subject: [PATCH 05/11] Removing leftover bracket --- Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 b/Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 index cf3cbcf..48aff27 100644 --- a/Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 +++ b/Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 @@ -49,7 +49,7 @@ function Write-FileError([string] $Message, [string] $Path, [int] $Line = 0, [in if ($ForGitHubActions) { $Message = $Message -replace '\s*(\r?\n\s*)+', ' ' - Write-Output "::error::$(if ($Path) { "$Path($Line,$Column): " })$Message)" + Write-Output "::error::$(if ($Path) { "$Path($Line,$Column): " })$Message" } elseif ($ForMsBuild) { From 3eb4e07c4aae34c744a54f914db12fbbe7288c44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Wed, 3 Jul 2024 20:15:26 +0200 Subject: [PATCH 06/11] Debug output --- Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 b/Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 index 48aff27..5464416 100644 --- a/Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 +++ b/Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 @@ -44,8 +44,15 @@ function Find-Recursively([string] $Path = '.', [string[]] $IncludeFile, [string function Write-FileError([string] $Message, [string] $Path, [int] $Line = 0, [int] $Column = 0) { + Write-Output "::error::This is Path: $Path" + $relativePath = Resolve-Path -Relative -Path $Path + Write-Output "::error::This is relativePath: $relativePath" + if ($Path) { $Path = Get-Item $Path } + $relativePath = Resolve-Path -Relative -Path $Path + Write-Output "::error::This is relativePath after Get-Item: $relativePath" + if ($ForGitHubActions) { $Message = $Message -replace '\s*(\r?\n\s*)+', ' ' From a8b755f38aa42afd6d6dec61a6d855982c9fa806 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Wed, 3 Jul 2024 20:17:23 +0200 Subject: [PATCH 07/11] Revert "Debug output" This reverts commit 3eb4e07c4aae34c744a54f914db12fbbe7288c44. --- Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 b/Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 index 5464416..48aff27 100644 --- a/Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 +++ b/Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 @@ -44,15 +44,8 @@ function Find-Recursively([string] $Path = '.', [string[]] $IncludeFile, [string function Write-FileError([string] $Message, [string] $Path, [int] $Line = 0, [int] $Column = 0) { - Write-Output "::error::This is Path: $Path" - $relativePath = Resolve-Path -Relative -Path $Path - Write-Output "::error::This is relativePath: $relativePath" - if ($Path) { $Path = Get-Item $Path } - $relativePath = Resolve-Path -Relative -Path $Path - Write-Output "::error::This is relativePath after Get-Item: $relativePath" - if ($ForGitHubActions) { $Message = $Message -replace '\s*(\r?\n\s*)+', ' ' From 7b39241f8f00f935f46a9908216da3146ce254a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Wed, 3 Jul 2024 20:18:33 +0200 Subject: [PATCH 08/11] Using a relative path for the violating PS scripts --- Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 b/Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 index 48aff27..cb7d427 100644 --- a/Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 +++ b/Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 @@ -49,7 +49,7 @@ function Write-FileError([string] $Message, [string] $Path, [int] $Line = 0, [in if ($ForGitHubActions) { $Message = $Message -replace '\s*(\r?\n\s*)+', ' ' - Write-Output "::error::$(if ($Path) { "$Path($Line,$Column): " })$Message" + Write-Output "::error::$(if ($Path) { "$(Resolve-Path -Relative -Path $Path)($Line,$Column): " })$Message" } elseif ($ForMsBuild) { From 7694bab87c117cbc71fee772e202d4e5c5349489 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Wed, 3 Jul 2024 20:19:36 +0200 Subject: [PATCH 09/11] Intentional analyzer violation --- Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 b/Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 index cb7d427..5cfcb66 100644 --- a/Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 +++ b/Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 @@ -44,13 +44,14 @@ function Find-Recursively([string] $Path = '.', [string[]] $IncludeFile, [string function Write-FileError([string] $Message, [string] $Path, [int] $Line = 0, [int] $Column = 0) { - if ($Path) { $Path = Get-Item $Path } + if ($Path) { $Path = Get-Item $Path } if ($ForGitHubActions) { $Message = $Message -replace '\s*(\r?\n\s*)+', ' ' Write-Output "::error::$(if ($Path) { "$(Resolve-Path -Relative -Path $Path)($Line,$Column): " })$Message" } + elseif ($ForMsBuild) { if (-not $Message.Contains(':')) { $Message = ": $Message" } From f6085a6782c38fa8441bed48e38645c139f65d5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Wed, 3 Jul 2024 20:21:07 +0200 Subject: [PATCH 10/11] Revert "Intentional analyzer violation" This reverts commit 7694bab87c117cbc71fee772e202d4e5c5349489. --- Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 b/Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 index 5cfcb66..cb7d427 100644 --- a/Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 +++ b/Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 @@ -44,14 +44,13 @@ function Find-Recursively([string] $Path = '.', [string[]] $IncludeFile, [string function Write-FileError([string] $Message, [string] $Path, [int] $Line = 0, [int] $Column = 0) { - if ($Path) { $Path = Get-Item $Path } + if ($Path) { $Path = Get-Item $Path } if ($ForGitHubActions) { $Message = $Message -replace '\s*(\r?\n\s*)+', ' ' Write-Output "::error::$(if ($Path) { "$(Resolve-Path -Relative -Path $Path)($Line,$Column): " })$Message" } - elseif ($ForMsBuild) { if (-not $Message.Contains(':')) { $Message = ": $Message" } From 111f823a1251625be98721eae469c496bc36a48b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Wed, 3 Jul 2024 20:31:58 +0200 Subject: [PATCH 11/11] Updating test solution package reference --- .../Lombiq.Analyzers.PowerShell.PackageReference.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TestSolutions/Lombiq.Analyzers.PowerShell.PackageReference/Lombiq.Analyzers.PowerShell.PackageReference.csproj b/TestSolutions/Lombiq.Analyzers.PowerShell.PackageReference/Lombiq.Analyzers.PowerShell.PackageReference.csproj index def9b0c..5de961c 100644 --- a/TestSolutions/Lombiq.Analyzers.PowerShell.PackageReference/Lombiq.Analyzers.PowerShell.PackageReference.csproj +++ b/TestSolutions/Lombiq.Analyzers.PowerShell.PackageReference/Lombiq.Analyzers.PowerShell.PackageReference.csproj @@ -7,7 +7,7 @@ - +