Repository navigation
PSUseConsistentIndentation.PipelineIndentation.None or 3 deletes commandlet name #1580
Description
Activity
- added and removed
on Sep 1, 2020 Jake Bolton (@ninmonkey) Can you confirm if this is still reproducing with v1.20.0?
SydneyhSmith commented
on Nov 4, 2021 CollaboratorMore actionsI was able to reproduce this on 1.20.0 with indentation style 'none'
Reacted by Andy JordanSeems like something we should prioritize, being destructive as it is.
Jake Bolton (@ninmonkey) Can you confirm if this is still reproducing with v1.20.0?
It appears to only be breaking when set to
PipelineIndentation = 'None'Environment
Module Version PSScriptAnalyzer 1.20.0 PowerShellEditorServices 0.2.0 Powershell 7.1.4 EditorServicesCommandSuite 1.0.0 PowerShellEditorServices.Commands 0.2.0 Initial script
Get-ChildItem | Where-Object Name -Like 'foo' Get-ChildItem | ForEach-Object Name
Mode:
IncreaseIndentationAfterEveryPipelineGet-ChildItem | Where-Object Name -Like 'foo' Get-ChildItem | ForEach-Object Name
Mode:
IncreaseIndentationForFirstPipelineGet-ChildItem | Where-Object Name -Like 'foo' Get-ChildItem | ForEach-Object Name
Mode:
IncreaseIndentationAfterEveryPipelineGet-ChildItem | Where-Object Name -Like 'foo' Get-ChildItem | ForEach-Object Name
Mode:
NoIndentationGet-ChildItem | Where-Object Name -Like 'foo' Get-ChildItem | ForEach-Object Name
Mode:
NoneGet-ChildItem | Name -Like 'foo' Get-ChildItem | Name
Mode: ``
Get-ChildItem | Where-Object Name -Like 'foo' Get-ChildItem | ForEach-Object Name
Write-Verbose "$functionName User did not specify Region, using default values $($Region -join ', ')."
Does that still occur in 1.20 ? I am not getting that, at least with this config
$settings = @{ IncludeRules = @('PSUseConsistentIndentation') Rules = @{ PSUseConsistentIndentation = @{ Enable = $true # Kind = 'space' PipelineIndentation = 'None' # broke # IndentationSize = 4 } } }
bergmeister commented
on Nov 8, 2021 CollaboratorMore actionsThanks for the updated repro info, I know there were a few cases with the formatter removing code in 1.19.0 that were fixed in 1.19.1 but it seems there is still one case outstanding (or re-introduced), I will take a look at it this week ✋. At least it's only for a non-default settings and the affected
PipelineIndentationStyle.Noneoption was also only introduced in 1.19.0.Reacted by Andy Jordan and Sydney Smithbergmeister commented
on Nov 13, 2021 CollaboratorMore actionsI had a first look at it today, I can confirm it's a bug of the
UseConsistentIndentationrule and it happens because when it gets toName, it thinks its the first token after newline. The reset of the newline therefore does not work correctly, which should happen at the previous cmdlet (i.e. Where-Object or ForEach-Object in your 2 examples). The reason for that is the following line that evaluates to true
if (pipelineIndentationStyle == PipelineIndentationStyle.None && PreviousLineEndedWithPipe(tokens, tokenIndex, token))
Below is a PR with a fix, it seems the existing test cases were too simple to not catch this scenario.
When
PSUseConsistentIndentation.PipelineIndentationis set toNoneor3it deleteswhere-objectandforeach-objectSteps to reproduce
Sample input:
It happens using the format
foo | barThese formats work correctly
Test cases
Expected behavior
Results that contain
Foreach-ObjectandWhere-ObjectActual behavior
All enum types:
Environment data
Occurs in normal powershell and
vscode-powershell's integrated terminalThe existing issues like #1168 deal with formatting, not mutating code