PowerShell / PowerShell/PSScriptAnalyzer

Revise semantics of compatibility rule profile inclusion

Open
#1,224 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Area - Configuration Area - Engine Consider - 2.0 Issue - Enhancement
Dominant language
C#
Stars
2.2k
Forks
414
Avg merge
13h 1m
Merged PRs (30d)
2

Description

UseCompatibleCommands and UseCompatibleTypes create a "union" profile for comparison of target profiles to a base standard. This allows us to use simple heuristic to determine whether a PowerShell AST represents something that is platform-specific (we see if the command or type is available in any platform, and if not ignore it as user-defined).

The problem here is that to create good warnings we have to have a good baseline union profile. Meaning we need to be judicious about how we make the profile. But since we could get it wrong, I created an informal mechanism for including things into the union profile. We use all the profiles in the "profile directory" and nothing else:

https://github.com/PowerShell/PSScriptAnalyzer/blob/df566b577803375cd6f1faba7d9d5d8715deefab/PSCompatibilityAnalyzer/Microsoft.PowerShell.CrossCompatibility/Utility/CompatibilityProfileLoader.cs#L76

This means that:

  • Including only one target, you still get good warnings, because it's compared against all the other profiles we ship by default
  • Using a target not in the profile directory, that won't be included in the union comparison
  • You can configure a different profile directory to get rid of comparisons to PowerShells you don't care about

This works but it's a bit subtle. I think we should move to:

  • All targets are in the union by default
  • Targets in the profile directory are in the union by default
  • Targets can be excluded from the union in a configuration setting, by name or path
  • The profile directory automatic union inclusion can be turned off by default

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with CompatibilityProfileLoader.cs, especially the profile-directory loading logic linked in the issue, and trace how UseCompatibleCommands and UseCompatibleTypes build the union profile. Define the configuration and exclusion behavior for named or path-based targets and for disabling automatic profile-directory inclusion. Done means all targets are included by default while configured exclusions and the opt-out setting are honored.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, powershell
Domain
devtools, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.