-
Notifications
You must be signed in to change notification settings - Fork 407
Closed
Description
When PSUseConsistentIndentation.PipelineIndentation is set to None or 3 it deletes where-object and foreach-object
Steps to reproduce
Sample input:
Get-ChildItem |
Where-Object Name -Like 'foo'
Get-ChildItem |
ForEach-Object NameIt happens using the format
foo |
barThese formats work correctly
foo | bar
foo
| barTest cases
$script = @'
Get-ChildItem |
Where-Object Name -Like 'foo'
Get-ChildItem |
ForEach-Object Name
'@
$settings = @{
IncludeRules = @('PSUseConsistentIndentation')
Rules = @{
PSUseConsistentIndentation = @{
Enable = $true
# Kind = 'space'
PipelineIndentation = 'None' # broke
# IndentationSize = 4
}
}
}
"
To reproduce: PipelineIndentation = None/3`n"
Invoke-Formatter -ScriptDefinition $script -Settings $settings
foreach ($mode in ('IncreaseIndentationAfterEveryPipeline', 'IncreaseIndentationForFirstPipeline', 'IncreaseIndentationAfterEveryPipeline', 'NoIndentation', 'None', ''))
{
"`n`nMode: '$Mode'`n"
$settings.Rules.PSUseConsistentIndentation.PipelineIndentation = $Mode
Invoke-Formatter -ScriptDefinition $script -Settings $settings
}Expected behavior
Results that contain Foreach-Object and Where-Object
Get-ChildItem |
Where-Object Name -Like 'foo'
Get-ChildItem |
ForEach-Object NameActual behavior
Get-ChildItem |
Name -Like 'foo'
Get-ChildItem |
NameAll enum types:
Mode: 'IncreaseIndentationAfterEveryPipeline'
Get-ChildItem |
Where-Object Name -Like 'foo'
Get-ChildItem |
ForEach-Object Name
Mode: 'IncreaseIndentationForFirstPipeline'
Get-ChildItem |
Where-Object Name -Like 'foo'
Get-ChildItem |
ForEach-Object Name
Mode: 'IncreaseIndentationAfterEveryPipeline'
Get-ChildItem |
Where-Object Name -Like 'foo'
Get-ChildItem |
ForEach-Object Name
Mode: 'NoIndentation'
Get-ChildItem |
Where-Object Name -Like 'foo'
Get-ChildItem |
ForEach-Object Name
Mode: 'None'
Get-ChildItem |
Name -Like 'foo'
Get-ChildItem |
Name
Mode: ''
Get-ChildItem |
Where-Object Name -Like 'foo'
Get-ChildItem |
ForEach-Object NameEnvironment data
Occurs in normal powershell and vscode-powershell's integrated terminal
> $PSVersionTable
Name Value
---- -----
PSVersion 7.0.3
PSEdition Core
GitCommitId 7.0.3
OS Microsoft Windows 10.0.19041
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.19.1
1.19.1The existing issues like #1168 deal with formatting, not mutating code