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

Accept -Fix for -ScriptDefinition #1938

Open
iRon7 opened this issue Aug 29, 2023 · 1 comment
Open

Accept -Fix for -ScriptDefinition #1938

iRon7 opened this issue Aug 29, 2023 · 1 comment

Comments

@iRon7
Copy link

iRon7 commented Aug 29, 2023

Summary of the new feature

Currently the -Fix parameter is mutual exclusive with the -ScriptDefinition parameter:

Invoke-ScriptAnalyzer -ScriptDefinition 'GCI *' -Fix

Invoke-ScriptAnalyzer: Parameter set cannot be resolved using the specified named parameters. One or more parameters issued cannot; be used together or an insufficient number of parameters were provided.

Proposed technical implementation details (optional)

When both ( -Fixand -ScriptDefinition) parameters, are supplied, I would expect to get a fixed ScriptDefinition back (instead of a [Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.DiagnosticRecord]).
This way, it would be easier to (pester) test a rule with SuggestedCorrections.
(You might of cause check the SuggestedCorrections property but that will not confirm it has been correctly inserted in the script.)
Besides it will allow to fix scripts by creating a fixed copy rather than make sure that you have a backup of your files when using this parameter.

Wishful thinking:

Get-Content *.ps1 | Foreach-Object { Invoke-ScriptAnalyzer -ScriptDefinition $_ | Set-Content "Fixed\$($_.Name)" }

What is the latest version of PSScriptAnalyzer at the point of writing

1.21.0

@bergmeister
Copy link
Collaborator

You will find this to be hard to do because of the current functional structure but happy for you to give it a go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants