Skip to content
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

Missing Problems entries for PSUseToExportFieldsInManifest in .psd1 manifests #5112

Open
6 tasks done
plmcgrn opened this issue Dec 4, 2024 · 11 comments
Open
6 tasks done
Labels
Issue-Bug A bug to squash. Needs: Maintainer Attention Maintainer attention needed!

Comments

@plmcgrn
Copy link

plmcgrn commented Dec 4, 2024

Prerequisites

  • I have written a descriptive issue title.
  • I have searched all open and closed issues to ensure it has not already been reported.
  • I have read the troubleshooting guide.
  • I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
  • I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.
  • 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 PowerShell/PSScriptAnalyzer#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

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 plmcgrn added Issue-Bug A bug to squash. Needs: Triage Maintainer attention needed! labels Dec 4, 2024
@SydneyhSmith
Copy link
Collaborator

@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 SydneyhSmith added Needs: Author Feedback Please give us the requested feedback! and removed Needs: Triage Maintainer attention needed! labels Dec 17, 2024
@plmcgrn
Copy link
Author

plmcgrn commented Dec 17, 2024

@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".

@github-actions github-actions bot added Needs: Maintainer Attention Maintainer attention needed! and removed Needs: Author Feedback Please give us the requested feedback! labels Dec 17, 2024
@JustinGrote
Copy link
Collaborator

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.

@plmcgrn
Copy link
Author

plmcgrn commented Dec 21, 2024

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

@JustinGrote
Copy link
Collaborator

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

@plmcgrn
Copy link
Author

plmcgrn commented Dec 22, 2024

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

@JustinGrote
Copy link
Collaborator

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 JustinGrote added Needs: Author Feedback Please give us the requested feedback! Needs: Maintainer Attention Maintainer attention needed! and removed Needs: Maintainer Attention Maintainer attention needed! labels Dec 22, 2024
@plmcgrn
Copy link
Author

plmcgrn commented Dec 23, 2024

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

@JustinGrote
Copy link
Collaborator

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

@JustinGrote JustinGrote removed the Needs: Maintainer Attention Maintainer attention needed! label Dec 23, 2024
@plmcgrn
Copy link
Author

plmcgrn commented Dec 23, 2024

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.

@github-actions github-actions bot added Needs: Maintainer Attention Maintainer attention needed! and removed Needs: Author Feedback Please give us the requested feedback! labels Dec 23, 2024
@plmcgrn
Copy link
Author

plmcgrn commented Dec 23, 2024

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

#4743

PowerShell/PowerShellEditorServices#2167

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Bug A bug to squash. Needs: Maintainer Attention Maintainer attention needed!
Projects
None yet
Development

No branches or pull requests

3 participants