-
Notifications
You must be signed in to change notification settings - Fork 382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Whitespace Between Parameters Is Trimming Required Quotes #1561
Comments
@sheldonhull what's the output of |
@rjmholt the PowerShell Editor Services extension diagnostic level logs pointed this out:
I think it has something to do with the variable int he string for "it".
no issue will occur. As soon as you add the |
@sheldonhull how about Is the formatting issue you're seeing something occurring when formatting through the extension or with |
I was using the Format Document command in VSCode.
When running Invoke-Formatter I was able to narrow down the option that seems to be causing this for me. Reproduce via Run SelectionImport-Module PSScriptAnalyzer -RequiredVersion 1.19.1
Write-Host "PSScriptAnalyzer Version: $((Get-Module PSScriptAnalyzer).Version.ToString())"
$script = @'
Describe "DescribeName" {
Context "ContextName" {
It "ItName" {
Assertion
}
It "output: attributes matches $($outputs.attributes)" {
$results.attributes | Should -Be $outputs.attributes
}
}
}
'@
$Rules = @{
IncludeRules = @(
'PSPlaceOpenBrace',
'PSPlaceCloseBrace',
'PSUseConsistentWhitespace',
'PSUseConsistentIndentation',
'PSAlignAssignmentStatement',
'PSUseCorrectCasing'
)
Rules = @{
PSPlaceOpenBrace = @{
Enable = $true
OnSameLine = $true
NewLineAfter = $true
IgnoreOneLineBlock = $true
}
PSPlaceCloseBrace = @{
Enable = $true
NewLineAfter = $true
IgnoreOneLineBlock = $true
NoEmptyLineBefore = $false
}
PSUseConsistentIndentation = @{
Enable = $true
Kind = 'space'
PipelineIndentation = 'IncreaseIndentationForFirstPipeline'
IndentationSize = 4
}
PSUseConsistentWhitespace = @{
Enable = $true
CheckInnerBrace = $true
CheckOpenBrace = $true
CheckOpenParen = $true
CheckOperator = $true
CheckPipe = $true
CheckPipeForRedundantWhitespace = $true
CheckSeparator = $true
CheckParameter = $false
}
PSAlignAssignmentStatement = @{
Enable = $true
CheckHashtable = $true
}
PSUseCorrectCasing = @{
Enable = $true
}
}
}
Invoke-Formatter -ScriptDefinition $script -Settings $Rules
|
I'm assuming the output of this reproduces your issue. Well done on working out the settings btw — we really need a simple way to convert those from VSCode to PSSA form. If you can try in a fresh console with |
I just installed that version, and then ran the statement with I just searched the repo and found the commit :-) Thanks for the kind words. |
Ah ok, so does that mean it's fixed in 1.19.1? If so that means you're actually experiencing PowerShell/vscode-powershell#2697 |
I'll have to revisit again tomorrow. I tried manually as we talked about it and it didn't seem to have an issue, but yet the editorservices issue doesn't explain that as it showed it did load 1.19.1 in the comments above. Am I missing something else? |
Hmmm, yeah that's true. Two possibilities are:
In any case, this seems to not occur with just PSSA, so I think PowerShell/vscode-powershell#2697 is the best place for us to continue investigating |
If When I run
I ran pwsh outside of vs code then imported the module. Test case $Original = @'
Function BadCode {
"stuff" | Measure-Object" 'ps1'
$InputList | ForEach-Object {
} | Select-Object -First 2
| Join-String -sep ", " -OutputPrefix 'Results: '
}
'@
$settings = @{
IncludeRules = @(
"PSUseConsistentWhitespace"
)
Rules = @{
PSUseConsistentWhitespace = @{
Enable = $True
CheckParameter = $false
}
}
}
$out1 = Invoke-Formatter -ScriptDefinition $Original -Settings $settings
$settings.rules.PSUseConsistentWhitespace.CheckParameter = $True
$out2 = Invoke-Formatter -ScriptDefinition $Original -Settings $settings
$out1
'+' * 30
$out2
if ($out1 -ne $out2) {
Write-Error 'formatting does not match'
} Expected Function BadCode {
"stuff" | Measure-Object" 'ps1'
$InputList | ForEach-Object {
} | Select-Object -First 2
| Join-String -sep ", " -OutputPrefix 'Results: '
} Actual Function BadCode {
"stuff" | Measure-Object" -OutputPrefix 'Results: '
} If you change the line from "stuff" | Measure-Object " 'ps1' system > $psEditor | select EditorServicesVersion
> $PSVersionTable | ft
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 |
I got the same problem with the following line (and many other .. this is just an example) in script not written by me: Visual Studio Code v1.48.2 64-bit Also: the extension doesn't care that i don't want to load my profile scripts .. i really dunno what happened to the PowerShell extension in the last few months but i gets worse with every release. I just no possible to work with PwSh and VSCode anymore. There so many bugs that i think i have to abandon it. I was using VSCode as my main PwSh development tool since the very beginning of VSCode but on my private machine i get constant errors and on my work machine i have so many bugs that i stopped counting them. Thanks for all your work and everything and it's great that all of this is for free .. but all those bugs frustrates me so much that i disabled the PwSh extension (heck.. just look at the new -parallel foreach option which consumes a ton of RAM cause the GC seems not able to catch it .. how is it possible to not catch such a bug or at least make a note about it if it's a 'feature'?). |
This bug was fixed in PSSA 1.19.1 but the stable PowerShell extension is not shipping that yet (not sure why, will chase that). If you use the preview extension and restart vs-code then this should not happen any more |
The Powershell Extension still seems to ship with an old version as I also experience bugs when turning that parameter on. How can I check which version is bundled with the Powershell extension? |
This was one of the more simple examples I could find.
I found this issue popping up in random files and finally realized it was a formatter issue.
Steps to reproduce
Expected behavior
Actual behavior
Environment data
The text was updated successfully, but these errors were encountered: