-
Notifications
You must be signed in to change notification settings - Fork 510
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
Cmdlet aliases are expanded automatically when formatting document #1842
Comments
@mkht thanks for reporting this, I am able to reproduce it when I use Core but not with Windows (maybe just a coincidence?), which is interesting because you are running Windows...I am wondering if you have any cusotm settings in your VSCode profile? |
@bergmeister do you know what settings you use to control this in PSScriptAnalyzer? |
I have noticed this recently as well but I don't use Windows PowerShell much any more, I am on Core 6.2.0 for my shell and also in the vscode terminals (on Windows). The avoid alias rule is not included by default for Invoke-Formatter and |
Yeah it seems like this is an extension configuration thing. Here's the list of rules we include: We do log the rules, so if there are logs we might be able to answer the question. Either way, if we have a repro for this, then it should be a relatively simple fix. |
I tried only Windows PowerShell, not tried Core. I attach the extension logs. |
Ref #496 |
I still could not find the cause of the issue. The first is to use custom PSSA rule settings. # This setting is exactly same as the "CodeFormatting" setting in the PSSA@1.18.0
@{
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 = 'IncreaseIndentationAfterEveryPipeline'
IndentationSize = 4
}
PSUseConsistentWhitespace = @{
Enable = $true
CheckInnerBrace = $true
CheckOpenBrace = $true
CheckOpenParen = $true
CheckOperator = $true
CheckPipe = $true
CheckSeparator = $true
}
PSAlignAssignmentStatement = @{
Enable = $true
CheckHashtable = $true
}
PSUseCorrectCasing = @{
Enable = $true
}
}
} The second is to install an older version of PSSA module on the system. Install-Module PSScriptAnalyzer -MaximumVersion 1.17 -Force -Scope AllUsers This method also avoided the issue. |
Today, I could finally get some more information:
It's sad that things like this happen but even if we hadn't enabled this feature flag by defaul I think we probably wouldn't have received the feedback in time either. What do you users and maintainers think? Would you rather prefer new features to be not enabled by default in the first iteration? |
Yeah, I think making the feature available in the first iteration and then enabling it in the second iteration is the wisest choice. It's not an uncommon pattern. A good example is the way Rust handles feature stabilisation. |
I found the issue that is causing some of the other alias to cmdlet expansion in the |
Closing this as it is a bug in ScriptAnalyzer being tracked with issue PowerShell/PSScriptAnalyzer#1209 . The coming release of the VSCode will have this turned off by default as to not break users. This has been fixed with #1852 which will be in the next release of PSScriptAnalyzer. |
So now that you disabled the automatic expending by default so |
@ili101 With the new |
@bergmeister I looked over the setting list twice and missed it somehow... thank you. |
System Details
VSCode version
VSCode extensions
No other extensions is installed.
The vscode settings have not changed anything.
PSES version
PowerShell version:
Issue Description
All aliases in my PS codes are expanded unexpectedly when executing "Format Document".
I tried formatting the code below.
Expected result
I expect this code will format like this.
Actual result
But vscode-powershell@1.12.0.0 formatted.
I know that formatting is provided by the PSScriptAnalyzer module.
However, I think this issue is specific to vscode-powershell.
I execute these commands in the Windows PowerShell terminal. (Not in the integrated terminal)
In this result, The original formatter of the PSScriptAnalyzer@1.18.0 is not expand aliases automatically.
Is this bug? Does anyone have an idea of how to work around it?
The text was updated successfully, but these errors were encountered: