PowerShell / PSScriptAnalyzer

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

Set Invoke-ScriptAnalyzer Path default value #1889

Open ThomasNieto opened 1 year ago

ThomasNieto commented 1 year ago

PR Summary

Removes Path as a mandatory parameter and sets the default to the current working directory.

Resolves #1887

PR Checklist

bergmeister commented 1 year ago

Nice idea but you'd need to fix existing tests

ThomasNieto commented 1 year ago

I'm not sure why the tests are failing with change as the tests would be using a provided path and not a default.

bergmeister commented 1 year ago

I will try look into it another time and see whether I can do something about it, definitely before next release, sorry it's taken so long

liamjpeters commented 6 months ago

@ThomasNieto This seems like a good idea to me 🙂

@bergmeister, This fails many of the tests as the path now always has some value. If -ScriptDefinition is supplied - it's ignored

https://github.com/PowerShell/PSScriptAnalyzer/blob/ab1dd25ccf266c6798d8c63c91f7e7c451790c4e/Engine/Commands/InvokeScriptAnalyzerCommand.cs#L433

https://github.com/PowerShell/PSScriptAnalyzer/blob/ab1dd25ccf266c6798d8c63c91f7e7c451790c4e/Engine/Commands/InvokeScriptAnalyzerCommand.cs#L526

You should probably make a change to the IsFileParameterSet() function to instead check that ScriptDefinition doesn't have some value. Or maybe better still return this.ParameterSetName.StartsWith("Path").

You will also need to update the markdown help file for Invoke-ScriptAnalyzer to tell the help system that path is no longer required:

https://github.com/PowerShell/PSScriptAnalyzer/blob/a0365a56068f711ee1ec08fae11a85fcc1542f8c/docs/Cmdlets/Invoke-ScriptAnalyzer.md?plain=1#L391

Or you'll get a test failure from Tests\Engine\ModuleHelp.Tests.ps1

https://github.com/PowerShell/PSScriptAnalyzer/blob/a0365a56068f711ee1ec08fae11a85fcc1542f8c/Tests/Engine/ModuleHelp.Tests.ps1#L229

Hope that helps 😀!