Skip to content
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 issue with New-Object and Trim Whitespace for Props #1540

Closed
jkewley opened this issue Jul 10, 2020 · 4 comments
Closed

Formatting issue with New-Object and Trim Whitespace for Props #1540

jkewley opened this issue Jul 10, 2020 · 4 comments

Comments

@jkewley
Copy link

jkewley commented Jul 10, 2020

Copied over from the VS Code repo

System Details

### VSCode version: 1.47.0 d5e9aa0227e057a60c82568bf31c04730dc15dcd x64

### VSCode extensions:
arcticicestudio.nord-visual-studio-code@0.14.0
bierner.emojisense@0.7.0
CoenraadS.bracket-pair-colorizer-2@0.2.0      
eamodio.gitlens@10.2.2
HookyQR.beautify@1.5.0
johnpapa.vscode-peacock@3.7.2
mechatroner.rainbow-csv@1.7.0
mhutchie.git-graph@1.24.0
mohsen1.prettify-json@0.0.3
ms-azuretools.vscode-azureappservice@0.17.0
ms-azuretools.vscode-azurefunctions@0.23.0 
ms-azuretools.vscode-azurestorage@0.9.0    
ms-azuretools.vscode-logicapps@0.2.41      
ms-dotnettools.csharp@1.22.1
ms-dotnettools.vscode-dotnet-runtime@0.1.2 
ms-vscode-remote.remote-wsl@0.44.4
ms-vscode.azure-account@0.8.11
ms-vscode.azurecli@0.5.0
ms-vscode.powershell@2020.6.0
ms-vsliveshare.vsliveshare@1.0.2427
ms-vsts.team@1.161.0
msazurermtools.azurerm-vscode-tools@0.11.0
PKief.material-icon-theme@4.2.0
richie5um2.vscode-sort-json@1.18.0
Shan.code-settings-sync@3.4.3
VisualStudioOnlineApplicationInsights.application-insights@0.4.2
vscode-icons-team.vscode-icons@10.1.1
vsls-contrib.codetour@0.0.34
vsls-contrib.gistfs@0.1.4


### PSES version: 2.2.0.0

### PowerShell version:

Name                           Value
----                           -----
PSVersion                      7.0.2
PSEdition                      Core
GitCommitId                    7.0.2
OS                             Microsoft Windows 10.0.18363
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Issue Description

PowerShell setting Code Formatting : Whitespace Between Parameters has a bug when formatting
New-Object PSObject -Property code.

Given:

$whoisthis = New-Object PSObject -Property @{
Somebody = "once told me"
That     = "the world is gonna roll me"
}

reformatting without the setting checked gives us

$whoisthis = New-Object PSObject -Property @{
    Somebody = "once told me"
    That     = "the world is gonna roll me"
}

with the option checked we get

$whoisthis = New-Object PSObject -Property @{
    Somebody "once told me"
    That = "the world is gonna roll me"
}

which is illegal (equals sign is gone after 'Somebody')

Expected Behaviour

I would expect this:

$whoisthis = New-Object PSObject -Property @{
    Somebody = "once told me"
    That = "the world is gonna roll me"
}
@ghost ghost added the Needs: Triage 🔍 label Jul 10, 2020
@SydneyhSmith
Copy link
Collaborator

Thanks @jkewley for opening this issue--this is an area we have made some recent changes to but appears that we still have some remaining issue....have you had the chance to see if this reproduces outside of VSCode using Invoke-Formatter command?

@rjmholt
Copy link
Contributor

rjmholt commented Jul 14, 2020

Something like this is required to reproduce:

$script = @'
$whoisthis = New-Object PSObject -Property @{
    Somebody = "once told me"
    That = "the world is gonna roll me"
}
'@

Invoke-Formatter -ScriptDefinition $script -Settings @{
    Rules = @{
        PSUseConsistentWhitespace = @{
            Enable = $true
            CheckParameter = $true
        }
    }
}

@jkewley
Copy link
Author

jkewley commented Jul 14, 2020

Thank you, @rjmholt. This does reproduce the bug with PSScriptAnalyzer 1.19.0

@bergmeister
Copy link
Collaborator

@rjmholt Can reproduce with 1.19.0 but not with latest master. Looking at it, I strongly believe #1497 was the fix for it.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants