You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Whitespace Between Parameters Is Trimming Required Quotes #1561
sheldonhull (@sheldonhull) what's the output of Get-Module PSScriptAnalyzer here? You have 1.19.1 installed, but is that the one that's loaded and running?
sheldonhull (@sheldonhull) how about Get-Module PSScriptAnalyzer? Get-InstalledModule isn't going to help here.
Is the formatting issue you're seeing something occurring when formatting through the extension or with Invoke-Formatter? Are you able to reproduce with just Invoke-Formatter in the console?
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 Import-Module PSScriptAnalyzer -RequiredVersion 1.19.1 and then your repro, just let me know if that also reproduces the issue.
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?
If Invoke-ScriptAnalyzer is returning multiple ParserErrors, shouldn't Invoke-ScriptFormatter exit without attempting to format? That combined with certain flags seems to trigger the code deletion bugs.
When I run Invoke-ScriptAnalyzer it gives parse errors. If PSUseConsistentWhitespace.CheckParameter = True the formatter breaks on this test case.
RuleName Severity Message
-------- -------- -------
MissingArgument ParseError Missing argument in parameter list.
TerminatorExpectedAtEndOfString ParseError The string is missing the terminator: ".
MissingEndCurlyBrace ParseError Missing closing '}' in statement block or type definition.
I ran pwsh outside of vs code then imported the module.
I got the same problem with the following line (and many other .. this is just an example) in script not written by me: Write-Host ($Error[0]).Exception
this gets formatted to this if "Whitespace Between Parameters" is switched on: Write-Host ($Error[0]Exception
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
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?
Activity
rjmholt commentedon Aug 4, 2020
sheldonhull (@sheldonhull) what's the output of
Get-Module PSScriptAnalyzerhere? You have 1.19.1 installed, but is that the one that's loaded and running?sheldonhull commentedon Aug 4, 2020
Rob Holt (@rjmholt) the PowerShell Editor Services extension diagnostic level logs pointed this out:
get-installedmodule psscriptanalyzer |FLprovided thisI think it has something to do with the variable int he string for "it".
For instance, if you change the value to:
no issue will occur. As soon as you add the
$outputsit begins to fail.Does this provide more useful context?
rjmholt commentedon Aug 4, 2020
sheldonhull (@sheldonhull) how about
Get-Module PSScriptAnalyzer?Get-InstalledModuleisn't going to help here.Is the formatting issue you're seeing something occurring when formatting through the extension or with
Invoke-Formatter? Are you able to reproduce with justInvoke-Formatterin the console?sheldonhull commentedon Aug 4, 2020
I was using the Format Document command in VSCode.
I just ran manual import and it reported:
When running Invoke-Formatter I was able to narrow down the option that seems to be causing this for me.
Reproduce via Run Selection
rjmholt commentedon Aug 4, 2020
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
Import-Module PSScriptAnalyzer -RequiredVersion 1.19.1and then your repro, just let me know if that also reproduces the issue.sheldonhull commentedon Aug 4, 2020
I just installed that version, and then ran the statement with
CheckParameter = $trueand no issue now. Did you figure it out?I just searched the repo and found the commit :-) Thanks for the kind words.
Let me know if you need anything else. 🥂
rjmholt commentedon Aug 4, 2020
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
sheldonhull commentedon Aug 4, 2020
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?
rjmholt commentedon Aug 4, 2020
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
ninmonkey commentedon Aug 19, 2020
If
Invoke-ScriptAnalyzeris returning multipleParserErrors, shouldn'tInvoke-ScriptFormatterexit without attempting to format? That combined with certain flags seems to trigger the code deletion bugs.When I run
Invoke-ScriptAnalyzerit gives parse errors. IfPSUseConsistentWhitespace.CheckParameter = Truethe formatter breaks on this test case.I ran pwsh outside of vs code then imported the module.
Test case
Expected
Actual
If you change the line from
Object" 'ps1'toObject " 'ps1'it's still invalid code, but the formatter no longer mutates it.system
Velocet commentedon Sep 8, 2020
I got the same problem with the following line (and many other .. this is just an example) in script not written by me:
Write-Host ($Error[0]).Exceptionthis gets formatted to this if "Whitespace Between Parameters" is switched on:
Write-Host ($Error[0]ExceptionVisual Studio Code v1.48.2 64-bit
PowerShell Extension v2020.6.0
PowerShell runtime version: 5.1.18362.752, edition: Desktop
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'?).
bergmeister commentedon Oct 22, 2020
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
jansohn commentedon Dec 2, 2020
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?