PowerShell / PowerShell/PSScriptAnalyzer

Ability for script exclusions for PSUseCompatible* rules

Ouverte
#1,347 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Area - Configuration Consider - 2.0 Issue - Enhancement
Langage dominant
C#
Étoiles
2.2k
Forks
414
Merge moyen
13 h 1 min
PR mergées (30 j)
2

Description

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

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par localiser la configuration des règles PSUseCompatibleCommands, PSUseCompatibleSyntax, PSUseCompatibleTypes et PSUseCompatibleCmdlets, ainsi que leurs tests existants. Comparez les deux paramètres proposés, puis vérifiez que les scripts exclus ne désactivent que ces règles de compatibilité, tandis que les autres règles restent actives.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
powershell
Domaine
tooling
Type d'issue
Fonctionnalité
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.