PowerShell / PowerShell/PSScriptAnalyzer

Invoke-Formatter - Custom rules?

Offen
#1,957 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Needs-Investigation Up-for-Grabs
Vorherrschende Sprache
C#
Sterne
2.2k
Forks
414
Ø Merge
13 Std. 1 Min.
Gemergte PRs (30 T.)
2

Beschreibung

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"

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 beiden Befehle mit C:\Temp\test.ps1 und PSScriptAnalyzerSettings.psd1 auszuführen und dabei die ausführliche Regelerkennung und die Formatierungsausgabe zu vergleichen. Verfolge die im Bericht erwähnten Einstiegspunkte Invoke-ScriptAnalyzer und Invoke-Formatter. Als abgeschlossen gilt, wenn festgestellt wurde, ob benutzerdefinierte Regeln von Invoke-Formatter unterstützt werden, und das beobachtete Verhalten dokumentiert oder korrigiert wurde.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
powershell
Bereich
tooling
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

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