PowerShell / PowerShell/PSScriptAnalyzer

Invoke-Formatter - Custom rules?

Ouverte
#1,957 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Needs-Investigation Up-for-Grabs
Langage dominant
C#
Étoiles
2.2k
Forks
415
Merge moyen
13 h 1 min
PR mergées (30 j)
2

Description

When I run through Invoke-ScriptAnalyzer[1], I find all of my expected violations and I see all of my custom rules running. However, when using the same settings file for Invoke-Formatter[2], it only seems to show one rule running (and not a custom one (PSAvoidUsingCmdletAliases ))

Any ideas what could be causing this? I thought Invoke-Formatter supproted custom rules too, but maybe this is not the case?

Output:
VERBOSE: Analyzing Script Definition.
VERBOSE: Running PSAvoidUsingCmdletAliases rule.
VERBOSE: Found 0 violations.
VERBOSE: Fixed 0 violations.

Notes:
PSScriptAnalyzer 1.21.0
Tested on both PowerShell 5.1 and PowerShell 7.2

Settings file content:

@{
    # Use Severity when you want to limit the generated diagnostic records to a
    # subset of: Error, Warning and Information.
    # Uncomment the following line if you only want Errors and Warnings but
    # not Information diagnostic records.
    #Severity = @('Error','Warning')

    CustomRulePath = 'C:\Users\redacted\Rules\*'
    RecurseCustomRulePath = $true
    IncludeDefaultRules = $true

    # Use IncludeRules when you want to run only a subset of the default rule set.
    #IncludeRules = @('PSAvoidDefaultValueSwitchParameter',
    #                 'PSMissingModuleManifestField',
    #                 'PSReservedCmdletChar',
    #                 'PSReservedParams',
    #                 'PSShouldProcess',
    #                 'PSUseApprovedVerbs',
    #                 'PSUseDeclaredVarsMoreThanAssigments')

    # Use ExcludeRules when you want to run most of the default set of rules except
    # for a few rules you wish to "exclude".  Note: if a rule is in both IncludeRules
    # and ExcludeRules, the rule will be excluded.
    ExcludeRules = @(
        'UseJSModuleImports',
        'PSAvoidUsingWriteHost',
        'PSUseShouldProcessForStateChangingFunctions',
        'PSUseOutputTypeCorrectly'
        #, 'PSAvoidGlobalVars'
    )

    # You can use the following entry to supply parameters to rules that take parameters.
    # For instance, the PSAvoidUsingCmdletAliases rule takes a whitelist for aliases you
    # want to allow.
    Rules = @{
        # Do not flag 'cd' alias.
        PSAvoidUsingCmdletAliases = @{
            Whitelist = @(
                'cd',
                'compare',
                'foreach',
                'group',
                'measure',
                'select',
                'sort',
                'tee',
                'where'
            )
        }

	    # Alert for line length
        PSAvoidLongLines  = @{
            Enable            = $true
            MaximumLineLength = 115
        }

        # Check if your script uses cmdlets that are compatible on PowerShell Core, version 6.0.0-alpha, on Linux.
        # PSUseCompatibleCmdlets = @{Compatibility = @("core-6.0.0-alpha-linux")}
    }
}

[1]
Invoke-ScriptAnalyzer -ScriptDefinition (Get-Content -Raw -Path C:\Temp\test.ps1) -Verbose -Settings "$rootPath\PSScriptAnalyzerSettings.psd1"

[2]
Invoke-Formatter -ScriptDefinition (Get-Content -Raw -Path C:\Temp\test.ps1) -Verbose -Settings "$rootPath\PSScriptAnalyzerSettings.psd1"

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 reproduire les deux commandes avec C:\Temp\test.ps1 et PSScriptAnalyzerSettings.psd1, en comparant la découverte détaillée des règles et la sortie du formatage. Suivez les points d’entrée Invoke-ScriptAnalyzer et Invoke-Formatter mentionnés dans le rapport. Le travail est terminé lorsqu’il est établi si les règles personnalisées sont prises en charge par Invoke-Formatter et que le comportement observé est documenté ou corrigé.

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

Évaluation

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

Recevez les nouvelles issues par e-mail

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