PowerShell / PowerShell/PSScriptAnalyzer
Formatting the PowerShell script removes necessary pipe operator `|`
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 2.2k
- Forks
- 414
- Avg merge
- 13h 1m
- Merged PRs (30d)
- 2
Description
System Details
System Details Output
### VSCode version: 1.51.1 e5a624b788d92b8d34d1392e4c4d9789406efe8f x64
### VSCode extensions:
janisdd.vscode-edit-csv@0.6.0
ms-python.python@2021.2.633441544
ms-toolsai.jupyter@2021.2.576440691
ms-vscode.cpptools@1.1.3
ms-vscode.hexeditor@1.3.0
ms-vscode.powershell@2020.6.0
redhat.vscode-commons@0.0.6
redhat.vscode-xml@0.16.1
### PSES version: 2.2.0.0
### PowerShell version:
Name Value
---- -----
PSVersion 7.1.3
PSEdition Core
GitCommitId 7.1.3
OS Microsoft Windows 10.0.19043
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Issue Description
Create a PowerShell file, input following script, and hit Alt+Shift+F. The pipe operator in $a | ForEach-Object { $_ } is removed.
$a=@('a','b','c')
$b=@{
a=1
b=2
c=3
}
$b | Select-Object -Property ($a | ForEach-Object { $_ })
Related settings in settings.json:
"powershell.codeFormatting.trimWhitespaceAroundPipe": true,
"powershell.codeFormatting.useCorrectCasing": true,
"powershell.codeFormatting.whitespaceBetweenParameters": true,
Expected Behaviour
The format result should look like:
$a = @('a', 'b', 'c')
$b = @{
a = 1
b = 2
c = 3
}
$b | Select-Object -Property ($a | ForEach-Object { $_ })
Actual Behaviour
The format result is (note that the | is missing):
$a = @('a', 'b', 'c')
$b = @{
a = 1
b = 2
c = 3
}
$b | Select-Object -Property ($a ForEach-Object { $_ })
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the formatter issue using the PowerShell script and formatting settings shown in the issue, then trace the PowerShell formatting entry point that handles nested pipe expressions. Done means the inner | is preserved in the formatted output and a regression test covers this example; the issue names no source file or existing test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- powershell
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100