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

Have PowerShell formatter remove trailing whitespace when formatting a file #5111

Open
2 tasks done
plmcgrn opened this issue Dec 3, 2024 · 2 comments
Open
2 tasks done

Comments

@plmcgrn
Copy link

plmcgrn commented Dec 3, 2024

Prerequisites

  • I have written a descriptive issue title.
  • 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.

image

Proposed Design

No response

@plmcgrn plmcgrn added Issue-Enhancement A feature request (enhancement). Needs: Triage Maintainer attention needed! labels Dec 3, 2024
@JustinGrote JustinGrote removed the Needs: Triage Maintainer attention needed! label Dec 3, 2024
@JustinGrote
Copy link
Collaborator

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.

@plmcgrn
Copy link
Author

plmcgrn commented Dec 3, 2024

Agreed. I consider whitespace to be formatting whereas alias conversions would be code modifications.

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

2 participants