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

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

liamjpeters
Copy link
Contributor

@liamjpeters liamjpeters commented Apr 10, 2024

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
@liamjpeters 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
Copy link

@Ju-l1a Ju-l1a left a comment

Choose a reason for hiding this comment

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

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

@Ju-l1a
Copy link

Ju-l1a commented Jul 17, 2024

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.

@liamjpeters
Copy link
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

image

But is fixed when running:

Invoke-Formatter -ScriptDefinition $ScriptDef -Settings $Settings

image

Hope that helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants