vscode-powershell
vscode-powershell copied to clipboard
Formatting an It block with unbalanced spacing causes issues
Prerequisites
- [X] I have written a descriptive issue title.
- [X] I have searched all issues to ensure it has not already been reported.
- [X] I have read the troubleshooting guide.
- [X] I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
- [X] I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.
- [X] If this is a security issue, I have read the security issue reporting guidance.
Summary
With the code (note two spaces between ) and { on line 7):
It "should create applications in Intune (<_>)" -ForEach @(
$Packages
@{
Name = 'installpackage'
Version = '1.0.0'
}
) {
$Output.Lines | Should -Contain "Application created in Intune: $_ ($" -Because $Output.String
}
When selecting to Format Document, results in:
It
$Output.Lines | Should -Contain "Application created in Intune: $_ ($" -Because $Output.String
}
When updating the code to include two spaces between -ForEach and @(:
It "should create applications in Intune (<_>)" -ForEach @(
$Packages
@{
Name = 'installpackage'
Version = '1.0.0'
}
) {
$Output.Lines | Should -Contain "Application created in Intune: $_ ($" -Because $Output.String
}
It correctly formats:
It "should create applications in Intune (<_>)" -ForEach @(
$Packages
@{
Name = 'installpackage'
Version = '1.0.0'
}
) {
$Output.Lines | Should -Contain "Application created in Intune: $_ ($" -Because $Output.String
}
And here's where it gets weird... When changing to three or more spaces on line 7:
It "should create applications in Intune (<_>)" -ForEach @(
$Packages
@{
Name = 'installpackage'
Version = '1.0.0'
}
) {
$Output.Lines | Should -Contain "Application created in Intune: $_ ($" -Because $Output.String
}
It does not format at all. Until... there are 2 or more spaces between -ForEach and @{, then it formats correctly.
Compounding the issue, if you remove the It, the formatting works correctly.
"should create applications in Intune (<_>)" -ForEach @(
$Packages
@{
Name = 'installpackage'
Version = '1.0.0'
}
) {
$Output.Lines | Should -Contain "Application created in Intune: $_ ($" -Because $Output.String
}
Formats to:
"should create applications in Intune (<_>)" -ForEach @(
$Packages
@{
Name = 'installpackage'
Version = '1.0.0'
}
) {
$Output.Lines | Should -Contain "Application created in Intune: $_ ($" -Because $Output.String
}
Finally: When run through Invoke-Formatter in the integrated terminal, formatting occurs as expected:
PS /Users/coryknox/git/chocolatey/ctk/16_engtasks_1510> Invoke-Formatter @'
>> It "should create applications in Intune (<_>)" -ForEach @(
>> $Packages
>> @{
>> Name = 'installpackage'
>> Version = '1.0.0'
>> }
>> ) {
>> $Output.Lines | Should -Contain "Application created in Intune: $_ ($" -Because $Output.String
>> }
>> '@
It "should create applications in Intune (<_>)" -ForEach @(
$Packages
@{
Name = 'installpackage'
Version = '1.0.0'
}
) {
$Output.Lines | Should -Contain "Application created in Intune: $_ ($" -Because $Output.String
}
PowerShell Version
[32;1mName Value[0m
[32;1m---- -----[0m
PSVersion 7.2.3
PSEdition Core
GitCommitId 7.2.3
OS Darwin 21.4.0 Darwin Kernel Version 21.4.0: Fri Mar 18 00:45:05 PDT 2022; root:xnu-8020.101.4~15/RELEASE_X86_64
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Visual Studio Code Version
1.67.0-insider
ed2619e11b68bec43b788486230b0c2afeb4672d
x64
Extension Version
[email protected]
[email protected]
[email protected]
Steps to Reproduce
See Summary above
Visuals
https://user-images.githubusercontent.com/30301021/166330615-e23be282-6aae-4f80-9384-76535ac081f1.mp4
Logs
No response
That's strange, I'm not reproing with the Preview and pwsh 7.2.3 on macOS...
What's the output of Get-Module Pester in the PSIC for you? I have version 5.2.2.
I have version 5.3.1... Interestingly it's still reproducing for me even with pester not imported into PSIC.
It also reproduces on both stable and preview extensions.
It also reproduces on both stable and preview extensions.
Something weird is going on for sure.
Try disabling TylerLeonhardt.vscode-inline-values-powershell? IDK.
Well FWIW I updated to 5.3.3 and it still doesn't repro for me. Trying on Windows now, who knows.
Nope, not there either.
Hey! It repro'd with the installed PowerShell Preview, but not when I was loading under a dev environment. Interesting.
~~I'm not able to repro it on Windows with either version of Code, and on my Mac it's not reproducing on stable Code. It's looking like it's a stray setting somewhere because I just installed all the same extensions onto my Windows system and the issue doesn't repro like that either.~~
~~Given that it's only one of the 4 code environments on my system, and you can't reproduce it, I'll go ahead and close this issue. If I happen to find what's causing it I'll reopen it.~~
I was going to close it since I can't repro it outside of my one install, but if you're able to repro then maybe it's worth keeping open?
Yeah leave it open...can you list all your extensions for me? Big difference with dev environment is that all other extensions are disabled. I don't believe that my settings are changed though, and I tried a dev build of an older version of the extension so as to rule that out too.
> code --list-extensions
alefragnani.Bookmarks
bungcip.better-toml
DavidAnson.vscode-markdownlint
eamodio.gitlens
EditorConfig.EditorConfig
fabiospampinato.vscode-highlight
GitHub.copilot
GitHub.vscode-pull-request-github
josefpihrt-vscode.roslynator
ms-azure-devops.azure-pipelines
ms-dotnettools.csharp
ms-python.python
ms-python.vscode-pylance
ms-vscode.azure-account
ms-vscode.hexeditor
ms-vscode.powershell-preview
ms-vscode.vscode-typescript-tslint-plugin
pspester.pester-test
qcz.text-power-tools
redhat.vscode-xml
richie5um2.vscode-sort-json
rusnason
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
I installed them all with the PowerShell:
@('[email protected]','[email protected]','[email protected]','[email protected]','[email protected]','[email protected]','[email protected]','[email protected]','[email protected]','[email protected]','[email protected]','[email protected]','[email protected]','[email protected]','[email protected]','[email protected]','[email protected]','[email protected]','[email protected]','[email protected]','[email protected]','[email protected]','[email protected]','[email protected]','[email protected]','[email protected]','[email protected]','[email protected]','[email protected]','[email protected]','[email protected]','[email protected]','[email protected]') | % {
code-insiders --install-extension ($_.Split('@')[0])
}
Here are our common extensions:
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
Still repros with all those disabled...
@andschwa and @corbob If you have a working case and test case -- check the log file, it prints the parameters that are sent -- ( In the past, there was a case where it didn't match user's settings in the UI/Config file )
I wrote a script to detect the correct log and grep it
Mine was reproducing it on ms-vscode.powershell-2022.5.1 with code.cmd . I was trying to determine which setting was the cause by manually toggling them on. It seemed almost like it wasn't always updating. I'd hit save in the json, then format. Unless the double-quotes to single quotes interacts with it?
This config breaks
> Find-VSCodeScriptAnalyzerConfig ms-vscode.powershell-2022.5.1
{
"IncludeRules": [
"PSPlaceCloseBrace",
"PSPlaceOpenBrace",
"PSUseConsistentWhitespace",
"PSUseConsistentIndentation",
"PSAlignAssignmentStatement",
"PSAvoidUsingDoubleQuotesForConstantString"
],
"Rules": {
"PSAvoidUsingCmdletAliases": {},
"PSUseConsistentWhitespace": {
"CheckInnerBrace": true,
"CheckPipe": true,
"CheckOpenParen": true,
"CheckSeparator": true,
"CheckParameter": true,
"Enable": true,
"CheckOpenBrace": true,
"CheckPipeForRedundantWhitespace": true,
"CheckOperator": true
},
"PSAlignAssignmentStatement": {
"Enable": true,
"CheckHashtable": true
},
"PSPlaceCloseBrace": {
"NewLineAfter": false,
"IgnoreOneLineBlock": false,
"Enable": true
},
"PSUseConsistentIndentation": {
"IndentationSize": 4,
"PipelineIndentation": 2,
"Kind": "space",
"Enable": true
},
"PSAvoidUsingDoubleQuotesForConstantString": {
"Enable": true
},
"PSUseCorrectCasing": {
"Enable": true
},
"PSPlaceOpenBrace": {
"NewLineAfter": true,
"Enable": true,
"IgnoreOneLineBlock": false,
"OnSameLine": true
}
}
}