PowerShell / PowerShell/PSScriptAnalyzer

Ability for script exclusions for PSUseCompatible* rules

Offen
#1,347 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Area - Configuration Consider - 2.0 Issue - Enhancement
Vorherrschende Sprache
C#
Sterne
2.2k
Forks
414
Ø Merge
13 Std. 1 Min.
Gemergte PRs (30 T.)
2

Beschreibung

Summary of the new feature

When using PSUseCompatible* rules with target profiles for PSv3, PSSA generates a whole bunch of issues for Pester tests that I have inside of my Script/Module projects. My Dev machine, as well as build machines run latest version of PowerShell, and the tests don't get bundled with my script/modules, hence I don't really care whether they'd run on versions other than latest. It would be really great if I could exclude my Test scripts (by path, by name pattern, or by name) just for these rules, and keep the rest of the rules active.

Proposed technical implementation details (optional)
Introduce an additional configuration setting for PSUseCompatible* rules, i.e. IgnoreScriptPath as follows:

@{
    Rules = @{
        PSUseCompatibleCommands = @{
            Enable = $true
            TargetProfiles = @(...);

            IgnoreScriptPath = @(
                './Tests/', # Ignore any scripts within the Tests sub-folder
                './*.ps1', # Ignore all PowerShell scripts withing the root folder (i.e. build scripts)
                './HelperScripts/SomeHelperScriptForMyBuild.ps1' # Ignore a single helper file
            )
        };

        PSUseCompatibleSyntax = @{
            Enable = $true
            TargetedVersions = @(...)

            IgnoreScriptPath = @(
                './Tests/', # Ignore any scripts within the Tests sub-folder
                './*.ps1', # Ignore all PowerShell scripts withing the root folder (i.e. build scripts)
                './HelperScripts/SomeHelperScriptForMyBuild.ps1' # Ignore a single helper file
            )
        };

        PSUseCompatibleTypes = @{
            Enable = $true
            TargetProfiles = @(...)

            IgnoreScriptPath = @(
                './Tests/', # Ignore any scripts within the Tests sub-folder
                './*.ps1', # Ignore all PowerShell scripts withing the root folder (i.e. build scripts)
                './HelperScripts/SomeHelperScriptForMyBuild.ps1' # Ignore a single helper file
            )
        };

        'PSUseCompatibleCmdlets' = @{
            'compatibility' = @(...)

            'IgnoreScriptPath' = @(
                './Tests/', # Ignore any scripts within the Tests sub-folder
                './*.ps1', # Ignore all PowerShell scripts withing the root folder (i.e. build scripts)
                './HelperScripts/SomeHelperScriptForMyBuild.ps1' # Ignore a single helper file
            )
        }
    }
}

Alternatively, given that the collection of paths to ignore would most likely be identical for all the PSUseCompatible* rules, it might actually be easier to mention it once in a separate place, i.e.:

@{
    Rules = @{
        ...
    }
    'PSUseCompatibleRulesIgnoreScriptPath' = @(
                './Tests/', # Ignore any scripts within the Tests sub-folder
                './*.ps1', # Ignore all PowerShell scripts withing the root folder (i.e. build scripts)
                './HelperScripts/SomeHelperScriptForMyBuild.ps1' # Ignore a single helper file
    )
}

What is the latest version of PSScriptAnalyzer at the point of writing
1.18.3

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, die Regelkonfigurationen für PSUseCompatibleCommands, PSUseCompatibleSyntax, PSUseCompatibleTypes und PSUseCompatibleCmdlets sowie ihre bestehenden Tests zu finden. Vergleiche die beiden vorgeschlagenen Einstellungen und überprüfe anschließend, dass ausgeschlossene Skripte nur diese Kompatibilitätsregeln unterdrücken, während andere Regeln aktiv bleiben.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
powershell
Bereich
tooling
Issue-Typ
Feature
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.