Relax PSScriptAnalyzer rules for tests/ folder
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 84/100
Direzione di ricerca
Inizia in .github/workflows/analysis.yml e ispeziona i passaggi esistenti di Invoke-ScriptAnalyzer e caricamento SARIF. Mantieni l’analisi PSGallery per modules/, aggiungi un passaggio separato per tests/ con le esclusioni elencate e combina entrambi gli insiemi di risultati prima di generare results.sarif. Il lavoro è completato quando il workflow continua a caricare SARIF, escludendo al contempo gli avvisi degli helper usati solo dai test.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Background
I've bumped into PSScriptAnalyzer / GitHub code-scanning warnings on files in the tests/ folder a couple of times when writing test helpers that start with verbs that (in a public API) have some conventions around then (like New). These rules aren't really applicable to test code. A recent example: a test helper named New-Frame tripped PSUseShouldProcessForStateChangingFunctions because New is an approved state-changing verb, so the analyzer expects the function to support -WhatIf/-Confirm.
These are linter conventions meant for exported, public cmdlets, not for test scaffolding. The tests/ folder isn't part of our public API, so applying the full PSGallery ruleset there generates noise (and a review-bot comment on every PR that adds such a helper).
Where these come from
The warnings are produced by the analysis workflow in .github/workflows/analysis.yml:
```powershell
Invoke-ScriptAnalyzer -Path . -Recurse -Settings PSGallery | ConvertTo-SARIF -FilePath results.sarif
```
The resulting SARIF is uploaded to GitHub code scanning, which is what renders the inline PR comments. GitHub has no per-path mute for third-party SARIF — the only lever is what we feed into the analyzer.
Suggested fix
Run the analyzer in two passes: the full ruleset on modules/, and a relaxed ruleset on tests/ that excludes the rules which are inherently meaningless for test helpers:
```powershell
$results = Invoke-ScriptAnalyzer -Path ./modules -Recurse -Settings PSGallery
$results += Invoke-ScriptAnalyzer -Path ./tests -Recurse -Settings PSGallery -ExcludeRule PSUseShouldProcessForStateChangingFunctions, PSUseApprovedVerbs, PSAvoidUsingWriteHost $results | ConvertTo-SARIF -FilePath results.sarif \``
We can add to the the -ExcludeRule list over time if there are other analyzers that don't make sense for the tests.
Alternatives considered
Neither of these are ideal:
- Drop
tests/from the scan entirely (-Path ./modules): simplest, but loses all linting on tests. - Repo-wide
PSScriptAnalyzerSettings.psd1withExcludeRules: not path-aware, so it would also disable the rule formodules/, where we want it.
Context: came up while reviewing #135.
- Lingua principale
- PowerShell
- Stelle
- 16
- Fork
- 5
- Merge medio
- 11h 24m
- PR unite (30g)
- 5
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di getsentry/sentry-powershell
-
Improvement PowerShell
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
getsentry/sentry-powershell#128 · 2 commenti ·
-
Improvement PowerShell
Difficoltà 5/5 Più di una settimana Idoneità per principianti 38/100
getsentry/sentry-powershell#121 · 2 commenti ·
-
Automatic flush on exit Aperta.NET Improvement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
getsentry/sentry-powershell#38 · 1 commento ·
Tutte le issue di getsentry/sentry-powershell
Issue simili
-
core dependencies
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 80/100
-
bug github_actions
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
registrystack/registry-stack#1393 ·
-
module: core
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
bigbluebutton/bigbluebutton#25849 ·
-
bug engine
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
rocky-data/rocky#2181 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100