Allow formatter to optionally correct aliases by bergmeister · Pull Request #1277 · PowerShell/PSScriptAnalyzer
PR Summary
Invoke-Formatter has a hard-coded list of rules that is supports. Add support for PSAvoidUsingCmdletAliases as the community has expressed interest in being able to auto-replace them when formatting in VS-Code (optionally, not on by default).
https://twitter.com/PrzemyslawKlys/status/1144342766408937490
Although Invoke-ScriptAnalyzer has a -Fix switch, the switch is only on for the -Path parameter set, therefore being able to optionally run this rule in the formatter is going to make it easier in the future to add a setting to vs code to optionally correct aliases. This change does not change the defaults behavior of Invoke-Formatter, it enables the following scenario to work
> Invoke-Formatter -ScriptDefinition gci -Settings @{IncludeRules=@('PSAvoidUsingCmdletAliases'); Rules=@{'PSAvoidUsingCmdletAliases'=@{}}} Get-ChildItem
Yes, the current debt of the code base is not ideal that invoke-formatter has the allowed rules hard-coded but given the narrow use case of it, refactoring it would be a separate item. I cannot even improve it to use resource strings because they are in the Rules project and the Rules project has a dependency on the Engine project (or would you want me to move the resource strings into the Engine project?)
PR Checklist
- PR has a meaningful title
- Use the present tense and imperative mood when describing your changes
- Summarized changes
- Change is not breaking
- Make sure all
.cs,.ps1and.psm1files have the correct copyright header - Make sure you've added a new test if existing tests do not effectively test the code changed and/or updated documentation
- This PR is ready to merge and is not Work in Progress.
- If the PR is work in progress, please add the prefix
WIP:to the beginning of the title and remove the prefix when the PR is ready.
- If the PR is work in progress, please add the prefix