-
Notifications
You must be signed in to change notification settings - Fork 388
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
UsePSCredentialType : on a variable $credential the quickfix proposed is [securestring] instead of [PsCredential] #1767
Comments
Thanks for pointing this out @zamothh! We will leave this open for discussion, adding extra logic in the rule to check for the |
What do you think @bergmeister? |
I think [PsCredential] is what most people are thinking. There's already the separate rule saying parameters named $Password should be [SecureString], that should stay as is, but Credential specifically almost always in Powershell nomenclature means a PSCredential (username/password pair) |
At the moment, PSSA would be happy with either pscredential or securestring type. It's worthwhile remembering that the way things work is the PSSA rule emits the SuggestedCorrections property, which is an |
I had a more detailed look: The Also, I did a small PoC to make the rule return two local suggested corrections and this works end to end in the PSScriptAnalyzer module but not in the VS-Code UI, I suspect there is code somewhere to just take the first element of the list, I've contributed to the vs-code extension and PSES before so I should be able to fix that myself as well. |
Currently, PSSA's `SuggestCorrections` property of the `DiagnosticRecord` object already is an array, but no built-in rules return more than one suggested correction, which led to `PowerShellEditorServices` not correctly translating this array before returning it as an code action as it only ever displayed one. This fixes it by making it generic again so it returns a code action for each suggest correction. It's basically just performing a `foreach` loop and calling `ToTextEdit` just once. This is a pre-requisite for an implementation of this, where a built-in rule will return multiple suggest corrections: PowerShell/PSScriptAnalyzer#1767 I've manually tested this with a modified version of PSScriptAnalyzer where I return two suggested corrections. The extension's UI now shows me the two different suggested code actions and also applies them correctly.
Thanks for the PR @bergmeister, just so I am following it correctly, your fix helps with suggesting multiple warnings for the VSCode UI? There was no fix for the alert to add "Set $credential to |
The first PR in PSES was to fix a bug in the VS Code extension where it would only ever display one suggested correction. My next PR will be in PSSA and will make the rule return 2 suggested corrections as part of the single warning. This way users can choose whether they prefer to fix it with pscredential or the securestring. I can show you a screenshot when I open the PSSA PR, which should make it clearer |
Summary of the new feature
When I have a variable called $credential, the proposed quickfix is to set it as a [securestring] instead of [PsCredential] object :

Proposed technical implementation details (optional)
The Quick Fix should be [PsCredential]
What is the latest version of PSScriptAnalyzer at the point of writing
1.20.0
The text was updated successfully, but these errors were encountered: