vscode-powershell icon indicating copy to clipboard operation
vscode-powershell copied to clipboard

Missing Problems entries for PSUseToExportFieldsInManifest in .psd1 manifests

Open plmcgrn opened this issue 1 year ago • 11 comments

Prerequisites

  • [X] I have written a descriptive issue title.
  • [X] I have searched all open and closed issues to ensure it has not already been reported.
  • [X] I have read the troubleshooting guide.
  • [X] I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
  • [X] I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.
  • [X] If this is a security issue, I have read the security issue reporting guidance.

Summary

When using VS Code and the PS extension for modifying manifests (.psd1 files), it seems that the extension doesn't surface PSScriptAnalyzer warnings for the PSUseToExportFieldsInManifest type.

https://learn.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/rules/usetoexportfieldsinmanifest?view=ps-modules

While somewhat related to the opposite intent of https://github.com/PowerShell/PSScriptAnalyzer/issues/506 , where the user can take steps to override the warnings, I think in the case where these export rules contain wildcard (the default when using native tools to generate a manifest), this warning is relevant and should be surfaced.

PowerShell Version

Name                           Value
----                           -----
PSVersion                      7.4.6
PSEdition                      Core
GitCommitId                    7.4.6
OS                             Darwin 24.1.0 Darwin Kernel Version 24.1.0: Thu Oct 10 21:03:11 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM…
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visual Studio Code Version

1.95.3
f1a4fb101478ce6ec82fe9627c43efbf9e98c813
arm64

Extension Version

[email protected]

Steps to Reproduce

When running PSScriptAnalyzer with default settings like Invoke-ScriptAnalyzer -Path ./ -Recurse, I do get the warnings. image

But when opening the .psd1 manifest in VS Code, nothing is surfaced in the Problems pane. image

Visuals

No response

Logs

No response

plmcgrn avatar Dec 04 '24 20:12 plmcgrn

@plmcgrn you may need to add this setting to your pssa config, here is an example https://github.com/PowerShell/vscode-powershell/blob/main/examples/PSScriptAnalyzerSettings.psd1

SydneyhSmith avatar Dec 17 '24 19:12 SydneyhSmith

@plmcgrn you may need to add this setting to your pssa config, here is an example https://github.com/PowerShell/vscode-powershell/blob/main/examples/PSScriptAnalyzerSettings.psd1

I'm well aware, but that's "just me", not "every developer committing code to a repo".

plmcgrn avatar Dec 17 '24 22:12 plmcgrn

You can place a PSScriptAnalyzer Settings file in a repo and add a settings.json to point to it if necessary to make it repo-wide.

JustinGrote avatar Dec 21 '24 16:12 JustinGrote

So place a settings.json inside a .vscode folder inside the root of the project repo?

plmcgrn avatar Dec 21 '24 20:12 plmcgrn

Yep, you can also just open settings with ctrl-, and select workspace and it'll handle it for you. https://code.visualstudio.com/docs/getstarted/settings#_workspace-settings

JustinGrote avatar Dec 21 '24 22:12 JustinGrote

So presuming I'd just use a relative path to the workspace settings.json, like, putting the psd1 file next to settings.json itself, and then checking both into the repo, that'll do it? I presume I'll also need to remove the entry in .gitignore that would omit the .vscode folder from being included, too. That will open a can of worms if other users have workspace-specific settings, preumably.

image

plmcgrn avatar Dec 22 '24 03:12 plmcgrn

Workspace-specific settings should generally not be gitignored if you want to provide a standard set of settings for a repository. Users should use a workspace file or profile with specific settings if they want to override it.

JustinGrote avatar Dec 22 '24 23:12 JustinGrote

Will this still work if a user has their local VS Code workspace configured as a multi-root workspace?

Example:

Workspace-Root/
Project1/
    .vscode/
        settings.json
        PSScriptAnalyzerSettings.psd1
    script1.ps1
Project2/
    .vscode/
        settings.json
        PSScriptAnalyzerSettings.psd1
    script1.ps1

plmcgrn avatar Dec 23 '24 16:12 plmcgrn

Theoretically yes, but why not just test it to be sure? https://code.visualstudio.com/docs/editor/multi-root-workspaces#_settings

JustinGrote avatar Dec 23 '24 16:12 JustinGrote

Theoretically yes, but why not just test it to be sure? https://code.visualstudio.com/docs/editor/multi-root-workspaces#_settings

It doesn't work, based on my testing. My understanding is that multi-root configs only affect folder-specific settings, which these are not. I inferred that both based on this not working, as also that when using the native settings editor, this setting isn't visible in folder-specific settings, only Workspace and User.

So if a user checks out one repo per-workspace, this would work, but if they check out multiple repo's, no joy.

plmcgrn avatar Dec 23 '24 17:12 plmcgrn

Looks like this would work if this issue's linked PR was merged.

https://github.com/PowerShell/vscode-powershell/issues/4743

https://github.com/PowerShell/PowerShellEditorServices/pull/2167

plmcgrn avatar Dec 23 '24 17:12 plmcgrn