-
Notifications
You must be signed in to change notification settings - Fork 379
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
Formatting .where and .foreach methods is incorrect #1168
Comments
Thank you @bergmeister , let's hope it's fixed already. Does the new version of PSScriptAnalyzer ship with the latest VS Code Insiders? |
@DarkLite1 |
@DarkLite1 This behaviour is still present in the current |
Thank you for your time @bergmeister , I appreciate the effort. Would this also be included in the It seems weird that the first indentation is by design. If that would be the case, then the closing bracket needs one indentation too I believe. Some examples, I think it should be like this: @().foreach({
}) But if that is not possible, this would be the next best thing: @().foreach( {
} ) Although we strongly recommend option A if possible. Keeps it more concise. |
Yes, the Powershell preview extension still contains PSSA but this is just a convenience so that it works out of the box. You can still manually install your preferred version, which will take precedence. |
Thank you, can it be this much customized that you can achieve the following: if (1 -ea 1) {
}
@().foreach({
}) So that after the We prefer to use the |
No, the |
If I had the skills I would definitely make a PR. But I'm not at home in other languages except for PowerShell. Thanks anyhow for the help. |
On a side note, I would like to argue that a |
Yup, IMO this treatment should be like parameters. You wouldn't allow |
Still the same issue in Here is some test code: $Processes = Get-Process
$Processes | Where-Object {
($_.ProcessName -eq 'PowerShell') -and ($_.Company -like 'Microsoft Corporation*')
}
$Processes.where( {
($_.ProcessName -eq 'PowerShell') -and ($_.Company -like 'Microsoft Corporation*')
}) Notice
|
Adding my 2 cents: $Processes.where( {
($_.ProcessName -eq 'PowerShell') -and ($_.Company -like 'Microsoft Corporation*')
}) The indention here is correct. At the end of the first line the indent level is 2, not 1, because both What's flawed is the lack of space missing from between the I would vote to remove the space: @DarkLite1, you should check out PowerShell/EditorSyntax#156, for a sample of an improved grammar for PowerShell that will resolve issue 4. I have a version of the grammar file already in JSON format ready for VSCode in my own repository list. |
I might also quickly point out that this behavior does not occur with the alternative syntax: $Processes.where{
($_.ProcessName -eq 'PowerShell') -and ($_.Company -like 'Microsoft Corporation*')
} So this behavior only happens between '(' and '{', and isn't related directly to the use of the special function method. |
Thank you for the feedback @msftrncs , much appreciated. With this part I totally agree with you:
And indeed, it would be best to have no space between them. That would already solve one thing.. Then there's still the incorrect coloring of the |
I just noticed looking at $script:BufferIsDirty = $false
$scriptView.Add_TextChanged( { $script:BufferIsDirty = $true })
$scriptView.Add_KeyUp( { OnTextBoxKeyUp @args }) https://github.com/lzybkr/ShowPSAst/blob/master/ShowPSAst.psm1 The file itself is inconsistent with relationship to spacing, I had formatted the script at some point while evaluating it and got the result shown above. |
Indeed, the current logic for spacing is incorrect for methods that are being passed a scriptblock. Just like @rkeithhill wrote:
|
Actually, I wouldn't allow Aside, in StructuredText (IEC 61131-3) I use |
Also seeing this for ValidateScript. Before: function Invoke-Build([ValidateScript({ /*...*/ })] $param1)
{ } And after: # ⮦Space ⮦No space
function Invoke-Build([ValidateScript( { /*...*/ })] $param1)
{ } The spacing within the parenthesis is not symmetrical, and I'd expect it to be. |
When using the methods
.where
and.foreach
in VS Code there's an incorrect indentation of the closing brackets and a space is added after the method.Expected behavior
Actual behavior
Environment data
Related to an issue in the PowerShell repo.
The text was updated successfully, but these errors were encountered: