FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

PSAvoidTrailingWhitespace: Rule not applied when using formatter + single character lines with trailing whitespace are truncated by liamjpeters · Pull Request #1993 · PowerShell/PSScriptAnalyzer · GitHub

PSAvoidTrailingWhitespace: Rule not applied when using formatter + single character lines with trailing whitespace are truncated - #1993

Merged
Andy Jordan (andyleejordan) merged 4 commits into
PowerShell:mainfrom
liamjpeters:#1992PSAvoidTrailingWhitespaceNotApplied
Feb 25, 2025
Merged

PSAvoidTrailingWhitespace: Rule not applied when using formatter + single character lines with trailing whitespace are truncated#1993
Andy Jordan (andyleejordan) merged 4 commits into
PowerShell:mainfrom
liamjpeters:#1992PSAvoidTrailingWhitespaceNotApplied

Conversation

Liam Peters (liamjpeters) commented Apr 10, 2024
edited
Loading

Copy link
Copy Markdown
Contributor

PR Summary

PR Checklist

…character, followed by multiple white-spaces were truncated when fixed/formatted
…ormatter with PSAvoidTrailingWhitespace and also checking that single-character lines that have trailing whitespace are not removed
Liam Peters (liamjpeters) changed the title WIP: PSAvoidTrailingWhitespace: Rule not applied when using formatter + single character lines with trailing whitespace are truncated PSAvoidTrailingWhitespace: Rule not applied when using formatter + single character lines with trailing whitespace are truncated Apr 10, 2024

Ju-l1a left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

It works as expected now and all tests pass. Looks good to me!

Ju-l1a commented Jul 17, 2024
edited
Loading

Copy link
Copy Markdown

I don't know if this is to do with this issue specifically but I've found that with this branch the fix for PSAvoidTrailingWhitespace gets applied when using Invoke-ScriptAnalyzer -Fix ... but not when using Invoke-Formatter .... I don't seem to have this problem for any other rules I've tried.

Edit: actually I'm getting the same for PSPossibleIncorrectComparisonWithNull.

Copy link
Copy Markdown
Contributor Author

Hey Ju-l1a 👋,

You need to tell the formatter to include that rule when carrying out the formatting.

$Settings = @{
    IncludeRules = @("PSAvoidTrailingWhitespace")
    Rules = @{
        "PSAvoidTrailingWhitespace" = @{}
    }
}

So the below code, with lots of trailing whitespace:

$ScriptDef = @"
    Function Get-Example {
        'Example'`t`t`t
    }`t`t`t
"@

Is not altered when running:

Invoke-Formatter -ScriptDefinition $ScriptDef

But is fixed when running:

Invoke-Formatter -ScriptDefinition $ScriptDef -Settings $Settings

Hope that helps!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thanks! Sorry it took so long to get to these.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The PSAvoidTrailingWhitespace rule is not applied when using Invoke-Formatter Fixing PSAvoidTrailingWhitespace is broken

4 participants


Back | FazBrowse Home | New Git URL