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

Change Whitespace settings to camelCase #1867

Merged
merged 2 commits into from
Apr 11, 2019

Conversation

rjmholt
Copy link
Contributor

@rjmholt rjmholt commented Apr 10, 2019

No description provided.

Copy link
Contributor

@rkeithhill rkeithhill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM except the PR title is not quite right. It should be change to camelCase from PascalCase.

@TylerLeonhardt TylerLeonhardt changed the title Change Whitespace settings to pascalCase Change Whitespace settings to camelCase Apr 10, 2019
Copy link
Member

@TylerLeonhardt TylerLeonhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rjmholt
Copy link
Contributor Author

rjmholt commented Apr 10, 2019

I've been trying to test this and the settings don't do anything. They also don't do anything in our current release. I've verified in the debugger that we send the right settings through, and also verified that the problem doesn't occur with Invoke-Formatter by itself. Running out of ideas here.

@rkeithhill
Copy link
Contributor

Any chance you could have an earlier version of PSSA loaded? (Get-Runspace 4).CreatePipeline("gmo", 0).Invoke()

@rjmholt
Copy link
Contributor Author

rjmholt commented Apr 11, 2019

PS C:\Users\roholt\Documents\Dev\PowerShell> (Get-Runspace 4).CreatePipeline("gmo", 0).Invoke()


ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Manifest   6.1.0.0    Microsoft.PowerShell.Management     {Add-Content, Clear-Content, Clear-Item, Clear-ItemProperty…}
Script     1.18.0     PSScriptAnalyzer                    {Get-ScriptAnalyzerRule, Invoke-Formatter, Invoke-ScriptAnalyzer}

@rkeithhill
Copy link
Contributor

Hmm, nope, that's not the problem.

@bergmeister
Copy link
Contributor

bergmeister commented Apr 11, 2019

  • powershell.codeFormatting.WhitespaceAroundPipe makes if ($true) {foo} change to if ($true) { foo } if the setting is enabled
  • powershell.codeFormatting.WhitespaceInsideBrace makes foo|bar change to foo | bar if the setting is enabled
    I have verified the setting can be turned on and off and works fine. Since I am a developer, I even installed the latest official releases versions of PowerShell 6.2.0, PSSA 1.18.0, code-insiders and v 1.12 of the code extension. I am on Windows 10 Pro 1809. Even when I locally build master with your changes then the (lowercased) settings still work.
    @rjmholt When you say it does not do anything is that before or after this change?

Copy link
Contributor

@bergmeister bergmeister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for correcting this. It would be great if the casing could also be changed in PSSA's release blog post that describes the new vscode settings:
https://devblogs.microsoft.com/powershell/powershell-scriptanalyzer-version-1-18-0-released/

@rjmholt
Copy link
Contributor Author

rjmholt commented Apr 11, 2019

@bergmeister

Script is:

gmo|
    ? {$_.IsDuck }|
    git

Settings include:

"powershell.codeFormatting.whitespaceAroundPipe": true,

At that point Shift+Alt+F does nothing in the program.

However, I've just realised while looking at it that this might be a problem in the client. I'm seeing this error when I send that key chord:

[ms-vscode.powershell] Accessing a resource scoped configuration without providing a resource is not expected. To get the effective value for 'editor.insertSpaces', provide the URI of a resource or 'null' for any resource.

Going to look into that now

@bergmeister
Copy link
Contributor

bergmeister commented Apr 11, 2019

Ok, interesting. I use Ctrl + K + F to format.

@rjmholt
Copy link
Contributor Author

rjmholt commented Apr 11, 2019

Fixing that warning didn't help

@bergmeister
Copy link
Contributor

bergmeister commented Apr 11, 2019

@rjmholt I tried your example and I think it is due to the (default) setting of "powershell.codeFormatting.pipelineIndentationStyle": "NoIndentation" that we set at the moment by default to suppress a PSSA 1.18 bug (that is fixed in development), changing that setting to any other value makes PSSA add a space before the pipe, we should raise an issue in PSSA to cover this case as well. Do the examples that I provided work for you? It would be nice to release a patch of PSSA in a few weeks to tidy some of the things up after the various edge cases that we found in the new feature settings, it shows at least how important configuration is

@rjmholt
Copy link
Contributor Author

rjmholt commented Apr 11, 2019

> $PSVersionTable                                                                                                            
Name                           Value
----                           -----
PSVersion                      6.2.0
PSEdition                      Core
GitCommitId                    6.2.0
OS                             Microsoft Windows 10.0.18875
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Examples you gave aren't working either unfortunately.

I'm stepping through in the debugger and have the following:

dbgView1
dbgView2

So as far as I can tell it's calling Invoke-Formatter with the right values. Equivalent to:

Invoke-Formatter -Settings @{
    Rules = @{
        PSPlaceCloseBrace = @{ NewLineAfter = $false; IgnoreOneLineBlock = $true; Enable = $true }
        PSUseConsistentWhitespace = @{
            Enable = $true
            CheckInnerBrace = $true
            CheckOperator = $true
            CheckPipe = $true
            CheckOpenParen = $true
            CheckSeparator = $true
            CheckOpenBrace = $true
        }
        PSAlignAssignmentStatement = @{ CheckHashtable = $true; Enable = $true }
        PSUseCorrectCasing = @{ Enable = $false }
        PSPlaceOpenBrace = @{
            NewLineAfter = $true
            IgnoreOneLineBlock = $true
            Enable = $true
            OnSameLine = $true
        }
        PSUseConsistentIndentation = @{
            Enable = $true
            PiplineIndentation = $true
            Kind = 'space'
            IndentationSize = 4
        }
    }
    IncludeRules = @(
        'PSPlaceCloseBrace'
        'PSPlaceOpenBrace'
        'PSUseConsistentWhitespace'
        'PSUseConsistentIndentation'
        'PSAlignAssignmentStatement'
    )
} -ScriptDefinition @'
if ($true) {foo}

foo|bar
'@ 

Running that on my machine in the console gives me:

if ($true) {foo}

foo|bar

I also get that result inside PSES and then that gets returned. So it looks like it's the Invoke-Formatter call where the problem is occurring here.

@rjmholt
Copy link
Contributor Author

rjmholt commented Apr 11, 2019

Here is the verbose output:

VERBOSE: Running PSUseConsistentWhitespace rule.
VERBOSE: Found 0 violations.
VERBOSE: Fixed 0 violations.
VERBOSE: Found Assembly: C:\Users\roholt\Documents\PowerShell\Modules\PSScriptAnalyzer\coreclr\Microsoft.PowerShell.CrossCompatibility.dll
VERBOSE: Loading Assembly:Microsoft.PowerShell.CrossCompatibility
VERBOSE: Found Assembly: C:\Users\roholt\Documents\PowerShell\Modules\PSScriptAnalyzer\coreclr\Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll
VERBOSE: Loading Assembly:Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules
VERBOSE: Found Assembly: C:\Users\roholt\Documents\PowerShell\Modules\PSScriptAnalyzer\coreclr\Microsoft.Windows.PowerShell.ScriptAnalyzer.dll
VERBOSE: Loading Assembly:Microsoft.Windows.PowerShell.ScriptAnalyzer
VERBOSE: Found Assembly: C:\Users\roholt\Documents\PowerShell\Modules\PSScriptAnalyzer\coreclr\Microsoft.PowerShell.CrossCompatibility.dll
VERBOSE: Loading Assembly:Microsoft.PowerShell.CrossCompatibility
VERBOSE: Found Assembly: C:\Users\roholt\Documents\PowerShell\Modules\PSScriptAnalyzer\coreclr\Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll
VERBOSE: Loading Assembly:Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules
VERBOSE: Found Assembly: C:\Users\roholt\Documents\PowerShell\Modules\PSScriptAnalyzer\coreclr\Microsoft.Windows.PowerShell.ScriptAnalyzer.dll
VERBOSE: Loading Assembly:Microsoft.Windows.PowerShell.ScriptAnalyzer
VERBOSE: Found Assembly: C:\Users\roholt\Documents\PowerShell\Modules\PSScriptAnalyzer\coreclr\Microsoft.PowerShell.CrossCompatibility.dll
VERBOSE: Loading Assembly:Microsoft.PowerShell.CrossCompatibility
VERBOSE: Found Assembly: C:\Users\roholt\Documents\PowerShell\Modules\PSScriptAnalyzer\coreclr\Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll
VERBOSE: Loading Assembly:Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules
VERBOSE: Found Assembly: C:\Users\roholt\Documents\PowerShell\Modules\PSScriptAnalyzer\coreclr\Microsoft.Windows.PowerShell.ScriptAnalyzer.dll
VERBOSE: Loading Assembly:Microsoft.Windows.PowerShell.ScriptAnalyzer
VERBOSE: Found Assembly: C:\Users\roholt\Documents\PowerShell\Modules\PSScriptAnalyzer\coreclr\Microsoft.PowerShell.CrossCompatibility.dll
VERBOSE: Loading Assembly:Microsoft.PowerShell.CrossCompatibility
VERBOSE: Found Assembly: C:\Users\roholt\Documents\PowerShell\Modules\PSScriptAnalyzer\coreclr\Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll
VERBOSE: Loading Assembly:Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules
VERBOSE: Found Assembly: C:\Users\roholt\Documents\PowerShell\Modules\PSScriptAnalyzer\coreclr\Microsoft.Windows.PowerShell.ScriptAnalyzer.dll
VERBOSE: Loading Assembly:Microsoft.Windows.PowerShell.ScriptAnalyzer
VERBOSE: Analyzing Script Definition.

@rjmholt
Copy link
Contributor Author

rjmholt commented Apr 11, 2019

More data:

> Invoke-Formatter -Settings @{
>>     Rules = @{
>>         PSUseConsistentWhitespace = @{
>>             Enable = $true
>>             CheckInnerBrace = $true
>>             CheckOperator = $true
>>             CheckPipe = $true
>>             CheckOpenParen = $true
>>             CheckSeparator = $true
>>             CheckOpenBrace = $true
>>         }
>>     }
>>     IncludeRules = @(
>>         'PSUseConsistentWhitespace'
>>     )
>> } -ScriptDefinition @'
>> if ($true) {foo}
>>
>> foo|bar
>> '@  -Verbose
VERBOSE: Using settings hashtable.
VERBOSE: Found Assembly: C:\Users\roholt\Documents\PowerShell\Modules\PSScriptAnalyzer\coreclr\Microsoft.PowerShell.CrossCompatibility.dll
VERBOSE: Loading Assembly:Microsoft.PowerShell.CrossCompatibility
VERBOSE: Found Assembly: C:\Users\roholt\Documents\PowerShell\Modules\PSScriptAnalyzer\coreclr\Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll
VERBOSE: Loading Assembly:Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules
VERBOSE: Found Assembly: C:\Users\roholt\Documents\PowerShell\Modules\PSScriptAnalyzer\coreclr\Microsoft.Windows.PowerShell.ScriptAnalyzer.dll
VERBOSE: Loading Assembly:Microsoft.Windows.PowerShell.ScriptAnalyzer
VERBOSE: Found Assembly: C:\Users\roholt\Documents\PowerShell\Modules\PSScriptAnalyzer\coreclr\Microsoft.PowerShell.CrossCompatibility.dll
VERBOSE: Loading Assembly:Microsoft.PowerShell.CrossCompatibility
VERBOSE: Found Assembly: C:\Users\roholt\Documents\PowerShell\Modules\PSScriptAnalyzer\coreclr\Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll
VERBOSE: Loading Assembly:Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules
VERBOSE: Found Assembly: C:\Users\roholt\Documents\PowerShell\Modules\PSScriptAnalyzer\coreclr\Microsoft.Windows.PowerShell.ScriptAnalyzer.dll
VERBOSE: Loading Assembly:Microsoft.Windows.PowerShell.ScriptAnalyzer
VERBOSE: Found Assembly: C:\Users\roholt\Documents\PowerShell\Modules\PSScriptAnalyzer\coreclr\Microsoft.PowerShell.CrossCompatibility.dll
VERBOSE: Loading Assembly:Microsoft.PowerShell.CrossCompatibility
VERBOSE: Found Assembly: C:\Users\roholt\Documents\PowerShell\Modules\PSScriptAnalyzer\coreclr\Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll
VERBOSE: Loading Assembly:Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules
VERBOSE: Found Assembly: C:\Users\roholt\Documents\PowerShell\Modules\PSScriptAnalyzer\coreclr\Microsoft.Windows.PowerShell.ScriptAnalyzer.dll
VERBOSE: Loading Assembly:Microsoft.Windows.PowerShell.ScriptAnalyzer
VERBOSE: Found Assembly: C:\Users\roholt\Documents\PowerShell\Modules\PSScriptAnalyzer\coreclr\Microsoft.PowerShell.CrossCompatibility.dll
VERBOSE: Loading Assembly:Microsoft.PowerShell.CrossCompatibility
VERBOSE: Found Assembly: C:\Users\roholt\Documents\PowerShell\Modules\PSScriptAnalyzer\coreclr\Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll
VERBOSE: Loading Assembly:Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules
VERBOSE: Found Assembly: C:\Users\roholt\Documents\PowerShell\Modules\PSScriptAnalyzer\coreclr\Microsoft.Windows.PowerShell.ScriptAnalyzer.dll
VERBOSE: Loading Assembly:Microsoft.Windows.PowerShell.ScriptAnalyzer
VERBOSE: Analyzing Script Definition.
VERBOSE: Running PSUseConsistentWhitespace rule.
VERBOSE: Found 0 violations.
VERBOSE: Fixed 0 violations.
if ($true) {foo}

foo|bar

@rjmholt
Copy link
Contributor Author

rjmholt commented Apr 11, 2019

Ok I've just reinstalled PSScriptAnalyzer and it's working now. I suspect I somehow had a bad build.

@rjmholt rjmholt merged commit cbf3f2a into PowerShell:master Apr 11, 2019
@rjmholt
Copy link
Contributor Author

rjmholt commented Apr 11, 2019

Sorry about all that @bergmeister! :)

@bergmeister
Copy link
Contributor

bergmeister commented Apr 11, 2019

No worries, I created an issue in PSSA to capture your special multi-line case whereby together with the set of settings, the formatting does not work exactly as expected

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

Successfully merging this pull request may close these issues.

4 participants