vscode-powershell
vscode-powershell copied to clipboard
Have PowerShell formatter remove trailing whitespace when formatting a file
Prerequisites
- [X] I have written a descriptive issue title.
- [X] I have searched all issues to ensure it has not already been reported.
Summary
When allowing the PSScriptAnalyzerSettings.psd1 to show Information-level problems, it adds a lot of overhead in formatting files that have lines with trailing whitespaces. Since this recommendation is mostly aesthetic/non-breaking, as is the automated code formatting in general, I'd like to see the formatter for PowerShell remove these trailing whitespaces characters.
https://learn.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/rules/avoidtrailingwhitespace?view=ps-modules
Because we can't store a centralized configuration for PSScriptAnalyzerSettings.psd1 in source control at the repo/workspace level to have it be taken automatically be any user working on that repo, having per-user rules to suppress this aren't really practical. I did see a separate thread in this project's issues noting individual users can set a configuration flag to do this, but again, having every user do that themselves vs. having a central linting rule is frustrating to maintain adherence on. Short of having a CI/CD pipeline hard reject any PSScriptAnalyzer errors to force them to check in cleaned code, an automated approach is best.
Proposed Design
No response
Thanks for your submission! I think I noted elsewhere that I think the ideal thing to do is to separate the formatting from the code actions in psscriptanalyzer when exposing via vscode, as format shouldn't expand aliases and whatnot but merely do whitespace adjustments, as this would allow other formatters to be used (such as prettier) without affecting psscriptanalyzer recommendations.
Auto-formatting of aliases and whatnot could still be done with CodeActionsOnSave setting if desired.
Agreed. I consider whitespace to be formatting whereas alias conversions would be code modifications.