Relax PSScriptAnalyzer rules for tests/ folder
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 84/100
Research direction
Start in .github/workflows/analysis.yml and inspect the existing Invoke-ScriptAnalyzer and SARIF upload steps. Keep the PSGallery analysis for modules/, add a separate tests/ pass with the listed exclusions, and combine both result sets before generating results.sarif. Done means the workflow still uploads SARIF while test-only helper warnings are excluded.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- PowerShell
- Stars
- 16
- Forks
- 5
- Avg merge
- 11h 24m
- Merged PRs (30d)
- 5
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from getsentry/sentry-powershell
-
Improvement PowerShell
Difficulty 4/5 3-5 days Newbie friendliness 45/100
getsentry/sentry-powershell#128 · 2 comments ·
-
Improvement PowerShell
Difficulty 5/5 Over a week Newbie friendliness 38/100
getsentry/sentry-powershell#121 · 2 comments ·
-
.NET Improvement
Difficulty 5/5 Over a week Newbie friendliness 25/100
getsentry/sentry-powershell#38 · 1 comment ·
All issues in getsentry/sentry-powershell
Similar issues
-
kb-infra-drift
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
OCHA-DAP/ds-knowledge-base#653 · 1 comment ·
-
intake mcp-intake needs-ac needs-human-review priority:medium type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Ikalus1988/MisakaNet#2102 · 2 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
llvm/lighthouse#283 ·
-
🤔 refinement needed
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
equinor/radix-operator#1979 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100