-
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
Extension's Formatter ignores config file. #3024
Comments
It looks like @bergmeister may have answered this in the #vscode channel on Discord/Slack Reproduced here to provide context within the issue: @ninmonkey The settings path settings only applies for script analysis, i.e. Invoke-ScriptAnalyzer and not formatting. All formatting related rule properties are settable via the powershell.codeformatting.* settings I'll add: if you're looking for project specific formatting options, you might want to use a workspace settings file |
My original examples weren't great. This new one shows that
I cannot find a ProblemFormatter breaks code when there's parse errors.
Proposed Solution
( I filed this under How to ReproducePSScriptAnalyzerSettings.psd1@{
'Rules' = @{
# keep the rule *except* 'process' because tiny typo-s mutates code
'PSAvoidUsingCmdletAliases' = @{
Enable = $True
'Whitelist' = @('process')
}
}
} To ReproduceCase1: Error Casefunction DoStuff {
<#
.description
example trigger type 1
A few cases the script becomes synatically invalid
Like accidentally deleting a ',' in the parameter block
The formatter should not modify the script when **error severity level** errors are found
As a work-around I whitelisted 'process', so I could keep the rule on
#>
param(
[Parameter()][int]$Num
[Parameter()][int]$Num2
)
process {
}
} Case2: Unexpected, but correct behavior.function OtherStuff {
<#
.description
example trigger type 2
By accident, there exists code outside the process/begin/end blocks
The code is technically synatically valid. The User doesn't expect doesn't expect `process` ( or `get-process` ) to be called with a script block.
Meaning it's formatting using the correct behavior.
#>
'accidental outer code'
process {
}
} |
I thought maybe it's not the same answer because of these differences:
param $a $b Part2If I put process before
Should this occur as the same when the |
Describe bug or problemUpdate: There's currently 2 parts:
quoting @rjmholt:
Is there a reason not to use the config file? IIRC It there were api limitations at the time. To reproduceinput function F {
param( $x $y )
process {}
} rules $settingsPathRule = @{
'Rules' = @{
'PSAvoidUsingCmdletAliases' = @{
Enable = $true
'Whitelist' = @('process')
}
}
}
$vsCodeRule = @{
'Rules' = @{
'PSAvoidUsingCmdletAliases' = @{
Enable = $true
}
}
} Expected BehaviorDon't format code when Actualfunction F {
param( $x $y )
Get-Process {}
} ScriptAnalyzer outputInvoke-ScriptAnalyzer -ScriptDefinition 'function F {
param( $x $y )
process {}
}' | ft -AutoSize -Wrap
RuleName Severity ScriptName Line Message
-------- -------- ---------- ---- -------
MissingEndParenthesisInFunctionParameterList ParseError 2 Missing ')' in function parameter list.
MissingEndCurlyBrace ParseError 1 Missing closing '}' in statement block or type definition.
UnexpectedToken ParseError 2 Unexpected token ')' in expression or statement.
UnexpectedToken ParseError 4 Unexpected token '}' in expression or statement.
PSAvoidUsingCmdletAliases Warning 3 'process' is implicitly aliasing 'Get-process' because it is missing the 'Get-' prefix.
This can introduce possible problems and make scripts hard to maintain. Please consider
changing command to its full name.
PSReviewUnusedParameter Warning 2 The parameter 'x' has been declared but not used. Sample Cases:
|
Wanted to check in and see if you are still having this issue @ninmonkey also wanted to confirm that you still hit this issue when there is no "s" in "settings" i.e. "powershell.scriptAnalysis.settingsPath": "PSScriptAnalyzerSetting.psd1" |
This issue has completely deviated from that it was before. The powershell.scriptAnalysis.settingsPath setting in VS-Code is just used for script analysis and not formatting. Its name makes this clear. There is no such equivalent setting for the formatter, which is currently controlled by a set of |
Issue Description
The extension's formatter is ignoring the config file:
PSScriptAnalyzerSettings.psd1
I didn't file this in /PSScriptAnalyzer because it (Invoke-Formatter) works as expected with the same config file.
Properties set under
"powershell.codeFormatting.*
are working.Except it's ignoring
"powershell.scriptAnalysis.settingsPath": "PSScriptAnalyzerSettings.psd1"
when formatting.I can disable changing
process
usingInvoke-Formatter
using this configExpected Behaviour
Input example:
Should format as
Actual Behaviour
System Details
A tiny workspace reproduces the example: 2020-10-20 - Invoke-Formatter - ignores config.zip
System Details Output (Click to Expand)
Attached Logs
log - editorServices.log
Environment Information
Visual Studio Code
PowerShell Information
Visual Studio Code Extensions
Visual Studio Code Extensions(Click to Expand)
manual_invoke_formatter.ps1 (Click to Expand)
The text was updated successfully, but these errors were encountered: