PowerShell / vscode-powershell

Provides PowerShell language and debugging support for Visual Studio Code
https://marketplace.visualstudio.com/items/ms-vscode.PowerShell
MIT License
1.7k stars 490 forks source link

'Select PSScriptAnalyzer rules' command broke starting with preview extension 2019.11.0 #2422

Open bergmeister opened 4 years ago

bergmeister commented 4 years ago

Using 2020.1.0 but I have seen it before the recent update. Going back to previous release, I found that 2019.9.0 was the last version where it still worked therefore it something in between 2019.9.0 and 2019.11.0 ,which is likely going to be the omnisharp refactoring @TylerLeonhardt

System Details Output

### VSCode version: 1.42.0-insider 33c79d5ad447956814a2a3658029dffb9e28bae6 x64

### VSCode extensions:
DavidAnson.vscode-markdownlint@0.33.0
eamodio.gitlens@10.2.0
mauve.terraform@1.4.0
ms-azure-devops.azure-pipelines@1.157.4
ms-azuretools.vscode-azureappservice@0.16.2
ms-azuretools.vscode-azurefunctions@0.20.1
ms-azuretools.vscode-azurestorage@0.7.2
ms-azuretools.vscode-azureterraform@0.3.0
ms-azuretools.vscode-docker@0.9.0
ms-python.python@2020.1.58038
ms-vscode-remote.remote-containers@0.97.0
ms-vscode-remote.remote-wsl@0.42.1
ms-vscode.azure-account@0.8.8
ms-vscode.csharp@1.21.9
ms-vscode.powershell@2020.1.0
ms-vscode.powershell-preview@2020.1.0
ms-vsonline.vsonline@1.0.1424
msazurermtools.azurerm-vscode-tools@0.8.3
samcogan.arm-snippets@1.4.19

### PSES version:

### PowerShell version:

Name                           Value
----                           -----
PSVersion                      7.0.0-rc.1
PSEdition                      Core
GitCommitId                    7.0.0-rc.1
OS                             Microsoft Windows 10.0.18362
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Issue Description

Open a PowerShell file to start the extension. When selecting the 'Select PSScriptAnalyzer rules' nothing happens

Expected Behaviour

A dropdown menu of PSSA rules should come up.

Actual Behaviour

Nothing happens

TylerLeonhardt commented 4 years ago

I kinda removed it on purpose. Or rather, I didn't add it back in when doing the Omnisharp work.

My reasoning was:

I really want this kind of integration but I want to do it better. Also, since PSScriptAnalyzer's 2.0 release is in planning and the settings structure could change as a result, I didn't want to jump into this feature before that.

I'd be ok bringing back the experience we already had, but it's not going to be a priority for us right at the moment.

bergmeister commented 4 years ago

Yes, the feature is very incomplete and it's probably going to take a long time until it will be implemented. It also has confused user's at time due to the setting not persisting after vs-code closes. I myself use it only to show the default set of PSSA rules at talks and how to enable all rules. In this case I'd rather remove the entry in package.json because having a command that does not do anything is even more confusing IMHO

jngibert commented 4 years ago

Looking forward to having 'Select PSScriptAnalyzer Rules' removed from the command palette since it doesn't do anything. Thanks bergmeister for putting a in a pull request!

zaphod4254 commented 4 years ago

As a brand new user to VS Code and using it for PowerShell (and took me hours of searching to find this item after I discovered it didn't work), what ARE the default rules then? Or where can I find the default config file for them?

I found the information about creating my own PSScriptAnalyzerSettings.psd1 file and I did get that to work, but having a heck of a time getting the rule set I want.

Mainly I want to disable the PSUseDeclaredVarsMoreThanAssignments rule from the default set. so I have this in my .psd1 file: ExcludeRules = @('PSUseDeclaredVarsMoreThanAssignments')

That seems to work as far as disabling that rule, but then I apparently now have a ton of rules enabled that must not be part of the default set. (I see bunches of new warnings that I didn't see before putting this custom settings file in place.)

I also see this in the example .psd1 file: IncludeRules = @('PSAvoidDefaultValueSwitchParameter', 'PSMisleadingBacktick', 'PSMissingModuleManifestField', 'PSReservedCmdletChar', 'PSReservedParams', 'PSShouldProcess', 'PSUseApprovedVerbs', 'PSAvoidUsingCmdletAliases', 'PSUseDeclaredVarsMoreThanAssignments')

but I commented it out because I thought it was only an example and I didn't explicitly want to limit to that rule set if the default is more than that. Or IS that the default rule set?

bergmeister commented 4 years ago

@zaphod4254 The default rules enabled in the extension are defined here, which as you noticed are only a small subset of all rules and your approach using a settings file is correct. https://github.com/PowerShell/PowerShellEditorServices/blob/512df9ea3968aaf3aa0639d84f1f9b7ef781a454/src/PowerShellEditorServices/Services/Analysis/AnalysisService.cs#L65-L81

zaphod4254 commented 4 years ago

Thank you. The flip question is, how do I know what all of the available rules are, in case I might want to add any of them?

bergmeister commented 4 years ago

You can run Get-ScriptAnalyzerRule in the integrated terminal to see all rules. Extensive details about each rules is in the rule documentation here: https://github.com/PowerShell/PSScriptAnalyzer/tree/master/RuleDocumentation