PowerShell / PowerShell/PSScriptAnalyzer

Accept `-Fix` for `-ScriptDefinition`

Open
#1,938 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Issue - Enhancement Up-for-Grabs
Dominant language
C#
Stars
2.2k
Forks
414
Avg merge
13h 1m
Merged PRs (30d)
2

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the Invoke-ScriptAnalyzer entry point and its current handling of -ScriptDefinition and -Fix. Verify how the command currently returns diagnostics, then define coverage for accepting both parameters, returning the fixed script definition, and confirming SuggestedCorrections are applied.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell
Domain
cli, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.