PowerShell / PowerShell/PSScriptAnalyzer

Ability for script exclusions for PSUseCompatible* rules

Abierto
#1,347 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Area - Configuration Consider - 2.0 Issue - Enhancement
Lenguaje dominante
C#
Estrellas
2.2k
Forks
414
Merge medio
13 h 1 min
PR fusionados (30 d)
2

Descripción

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

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Empieza por localizar la configuración de las reglas PSUseCompatibleCommands, PSUseCompatibleSyntax, PSUseCompatibleTypes y PSUseCompatibleCmdlets, así como sus pruebas existentes. Compara las dos configuraciones propuestas y verifica después que los scripts excluidos suprimen solo estas reglas de compatibilidad, mientras las demás reglas siguen activas.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
powershell
Área
tooling
Tipo de issue
Nueva funcionalidad
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.