PowerShell / PSScriptAnalyzer

Download ScriptAnalyzer from PowerShellGallery
https://www.powershellgallery.com/packages/PSScriptAnalyzer/
MIT License
1.8k stars 366 forks source link

Add tests for #1504 PSUseUsingScopeModifierInNewRunspaces #2005

Open o-l-a-v opened 1 month ago

o-l-a-v commented 1 month ago

PR Summary

Wrote two tests for issue #1504. The issue is not fixed yet, but I had two scenarios that could easily be added to the relevant test file.

Repro to wrongfully trigger PSUseUsingScopeModifierInNewRunspaces, which I added to test:

# Microsoft.PowerShell.Core \ Start-Job
Start-Job -ScriptBlock {
    Param($Foo)
    $Foo
} -ArgumentList 'Bar' | Receive-Job -Wait -AutoRemoveJob

# Microsoft.PowerShell.ThreadJob
Start-ThreadJob -ScriptBlock {
    Param($Foo)
    $Foo
} -ArgumentList 'Bar' | Receive-Job -Wait -AutoRemoveJob

PR Checklist