Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In some circumstances the build file process is not properly returning PSScriptAnalyzer violations #99

Open
techthoughts2 opened this issue Oct 11, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@techthoughts2
Copy link
Owner

Expected Behavior

Analyze build tasks should always return any PSScriptAnalyzer violations

Current Behavior

In some circumstances the Analyze build task returns null even though individual files have known PSScriptAnalyzer violations

Possible Solution

This is likely due to the way that the $scriptAnalyzerResults is being loaded.

Switching to a list context seems to solve the problem:

$analyzerResults = New-Object System.Collections.Generic.List[Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.DiagnosticRecord]
foreach ($file in $filesToAnalyze) {
    $results = $null
    $results = Invoke-ScriptAnalyzer -Path $file.FullName
    if ($results) {
        foreach ($result in $results) {
            $analyzerResults.Add($result)
        }
    }
}
@techthoughts2 techthoughts2 added the bug Something isn't working label Oct 11, 2024
@techthoughts2 techthoughts2 self-assigned this Oct 11, 2024
@SamErde
Copy link
Contributor

SamErde commented Oct 11, 2024

Happy to test this. The example looks very different from the structure of the analyze tasks in the {ModuleName}.build.ps1 script, though. Do you have a test branch where that is updated?

@techthoughts2
Copy link
Owner Author

techthoughts2 commented Oct 12, 2024

I should have been more clear in the bug description.
This bug isn't impacting the downstream use of Catesta.
If you use Catesta to build a module, the build file will reliably run PSScriptAnalyzer in the newly created module.

This bug is specific to the build file for building the Catesta module itself. This is due to some of the unique characteristics of Catesta containing the resource files (including tests) inside of src/Catesa/Resources.

I should have a fix up shortly. But users of Catesta are not impacted by this bug.

@SamErde
Copy link
Contributor

SamErde commented Oct 12, 2024

Gotcha. That makes sense now. 😀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants