PowerShell / PowerShell/PSScriptAnalyzer
preferences file does not support $env: variables
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- C#
- Sterne
- 2.2k
- Forks
- 414
- Ø Merge
- 13 Std. 1 Min.
- Gemergte PRs (30 T.)
- 2
Beschreibung
Expected behavior
# # PSScriptAnalyzerSettings.psd1
# @{
# CustomRulePath = "rules.psm1"
# }
Invoke-ScriptAnalyzer -Path .\test.ps1 -Settings ./PSScriptAnalyzerSettings.psd1
outputs: (correct)
RuleName Severity ScriptName Line Message
-------- -------- ---------- ---- -------
PSAvoidInvokeSomething Warning test.ps1 1 The command 'Invoke-Something' should not be used. Please
use 'Invoke-SomethingElse' instead
Actual behavior
# # PSScriptAnalyzerSettings.psd1
# @{
# CustomRulePath = "$PSScriptRoot/rules.psm1"
# }
Invoke-ScriptAnalyzer -Path .\test.ps1 -Settings ./PSScriptAnalyzerSettings.psd1
Outputs:
Invoke-ScriptAnalyzer: Value in the settings hashtable should be a string or an array of strings: line 2 column 22 in file [...]\Powershell\PSScriptAnalyzerSettings.psd1
Reasoning
according to this article,
Module manifests are loaded in RestrictedLanguage mode and may use these additional variables:
$PSScriptRoot
$PSEdition
$EnabledExperimentalFeatures
Any environment variable, like $env:TEMP
relative file paths CustomRulePath for my environment
were resolving relative to the cwd instead of relative to the settings.file in neovim. the
./rules.psm1 and rules.psm1 were not resolving correctly.
~/.../Powershell/PSScriptAnalyzerSettings.psd1
where '~' expands to HOMEDIR does work
Environment data
> $PSVersionTable
Name Value
---- -----
PSVersion 7.5.2
PSEdition Core
GitCommitId 7.5.2
OS Microsoft Windows 10.0.26100
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.24.0
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Reproduziere das Problem mit PSScriptAnalyzerSettings.psd1 und Invoke-ScriptAnalyzer sowohl mit einem einfachen CustomRulePath als auch mit einem $env:- oder $PSScriptRoot-Ausdruck. Verfolge, wie die Einstellungsdatei geparst wird und wie CustomRulePath aufgelöst wird; abgeschlossen ist die Aufgabe, wenn unterstützte Umgebungsvariablenwerte ohne den Hashtabellen-Validierungsfehler akzeptiert werden und der dokumentierte Befehl funktioniert.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- powershell
- Bereich
- tooling
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100