Skip to content

Commit e996733

Browse files
committed
Tests/Rules/AvoidTrailingWhitespace: Added test for usage of Invoke-Formatter with PSAvoidTrailingWhitespace and also checking that single-character lines that have trailing whitespace are not removed
1 parent f1f53f6 commit e996733

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Tests/Rules/AvoidTrailingWhitespace.tests.ps1

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ BeforeAll {
99

1010
$settings = @{
1111
IncludeRules = @($ruleName)
12+
Rules = @{
13+
$ruleName = @{}
14+
}
1215
}
1316
}
1417

@@ -34,4 +37,26 @@ Describe "AvoidTrailingWhitespace" {
3437
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings
3538
Test-CorrectionExtentFromContent $def $violations 1 $Whitespace ''
3639
}
40+
41+
It 'Should be used by Invoke-Formatter, when in settings, replacing trailing <Type>' -TestCases $testCases {
42+
param (
43+
[string] $Whitespace
44+
)
45+
# Test also guards against regression where single-character lines, with trailing whitespace
46+
# would be removed entirely. See issues #1757, #1992
47+
$def = @"
48+
Function Get-Example {
49+
'Example'$Whitespace
50+
}$Whitespace
51+
"@
52+
53+
$expected = @"
54+
Function Get-Example {
55+
'Example'
3756
}
57+
"@
58+
$formatted = Invoke-Formatter -ScriptDefinition $def -Settings $settings
59+
$formatted | Should -Be $expected
60+
}
61+
62+
}

0 commit comments

Comments
 (0)