Open Mcgurk125 opened 10 months ago
Invoke-Formatter is for very narrow use cases. You could use -Fix switch on Invoke-ScriptAnalyser but be warned that the moment you have multiple rules that change nearby code, the order matters, which is a problem that Invoke-Formatter solves by re-running the rules multiple times until everything is in order (after every change you need to re-run as text positions have moved). Happy to look at a PR to make Invoke-Formatter use custom rules as well but be warned that performance will be very slow because custom rules are already slow and would need to run multiple times as explained.
When I run through Invoke-ScriptAnalyzer[1], I find all of my expected violations and I see all of my custom rules running. However, when using the same settings file for Invoke-Formatter[2], it only seems to show one rule running (and not a custom one (PSAvoidUsingCmdletAliases ))
Any ideas what could be causing this? I thought Invoke-Formatter supproted custom rules too, but maybe this is not the case?
Output: VERBOSE: Analyzing Script Definition. VERBOSE: Running PSAvoidUsingCmdletAliases rule. VERBOSE: Found 0 violations. VERBOSE: Fixed 0 violations.
Notes: PSScriptAnalyzer 1.21.0 Tested on both PowerShell 5.1 and PowerShell 7.2
Settings file content:
[1] Invoke-ScriptAnalyzer -ScriptDefinition (Get-Content -Raw -Path C:\Temp\test.ps1) -Verbose -Settings "$rootPath\PSScriptAnalyzerSettings.psd1"
[2] Invoke-Formatter -ScriptDefinition (Get-Content -Raw -Path C:\Temp\test.ps1) -Verbose -Settings "$rootPath\PSScriptAnalyzerSettings.psd1"