PowerShell lint
The powershell-lint reusable workflow runs PSScriptAnalyzer against PowerShell files in a calling repository.
The workflow checks scripts, modules, and module manifests for code-quality and correctness issues. It reports findings without executing the selected scripts or importing the selected modules.
The workflow uses the shared lint.ps1 script and supports consuming repository-owned settings or the central lint configuration.
Table of Contents
- Default behavior
- Inputs
- Configuration
- Central configuration
- Repository-owned configuration
- Rule exclusions
- File selection
- Reports and policy
- Permissions
- Examples
- Minimal scan
- Use repository settings
- Scan selected folders
- Manual baseline scan
Default behavior
With no caller-provided inputs, the workflow:
- Checks out the calling repository.
- Checks out
redjax/PipelineTemplatesattemplates-ref. - Installs PSScriptAnalyzer version.
- Selects tracked
.ps1,.psm1, and.psd1files throughout the repository. - Applies no additional path exclusions.
- Uses
PSScriptAnalyzerSettings.psd1from the calling repository's main folder when present. - Uses the central lint settings when no repository-local settings file exists.
- Reports findings with
ErrororWarningseverity. - Prints findings in the job log and emits GitHub annotations.
- Adds a summary containing file and finding counts.
- Fails when selected lint findings exist.
- Always fails when installation, configuration, or execution fails.
Note
Linting does not rewrite files. Use the powershell-format workflow to check or apply formatting.
Inputs
| Input | Type | Default | Description |
|---|---|---|---|
paths |
string |
. |
Files or folders to check. Put each entry on its own line. Only tracked PowerShell files are checked |
exclude-paths |
string |
Empty | Files or folders to skip, one wildcard pattern per line |
settings-file |
string |
Empty | Path to a lint settings file, starting from the calling repository's main folder |
severity |
string |
Error,Warning |
Comma-separated diagnostic severities to report |
fail-on-findings |
boolean |
true |
Fail on findings; set to false to report warning annotations without failing |
psscriptanalyzer-version |
string |
1.24.0 |
PSScriptAnalyzer version to install from PowerShell Gallery |
runner-image |
string |
ubuntu-latest |
Runner image with pwsh available |
templates-ref |
string |
main |
PipelineTemplates branch, tag, or commit SHA containing shared scripts and fallback settings |
Configuration
The workflow selects settings in this order:
- The file explicitly supplied through
settings-file. PSScriptAnalyzerSettings.psd1in the calling repository's main folder.- The central
config/powershell/PSScriptAnalyzerSettings.psd1file.
The selected configuration replaces the other choices. Local and central settings are not merged, so if a consuming repository provides its own configuration, the pipeline uses that instead of the central one. An explicitly supplied settings file must exist; a missing file fails the run instead of silently selecting the central fallback.
Central configuration
The central settings are stored in:
Leave settings-file empty to enable local-file discovery and central fallback:
The central lint configuration reports warnings and errors. It excludes the formatting rules handled by the separate formatting workflow.
Repository-owned configuration
Place a file named PSScriptAnalyzerSettings.psd1 in the calling repository's main folder for automatic discovery.
Alternatively, explicitly select a settings file:
Paths start from the calling repository's main folder. They must not point outside the repository. Match the actual filename's capitalization. For example, a lowercase filename can be selected explicitly:
Rule exclusions
A repository can maintain its own rule exclusions:
@{
Severity = @(
'Error'
'Warning'
)
ExcludeRules = @(
## Formatting is checked separately.
'PSPlaceOpenBrace'
'PSPlaceCloseBrace'
'PSUseConsistentWhitespace'
'PSUseConsistentIndentation'
'PSAlignAssignmentStatement'
'PSUseCorrectCasing'
)
}
Add repository-specific exceptions to the local settings rather than weakening the central defaults for every caller. The workflow's severity input also selects reported diagnostic severities. Keep it consistent with the intended policy in your settings file.
File selection
The workflow checks tracked files with these extensions:
Use . to check the entire repository:
Select specific folders or files by placing each on its own line:
The entries are passed to git ls-files. Untracked files are not checked. Exclude files using wildcard patterns against paths starting from the repository's main folder:
Exclusions use PowerShell wildcard matching, not .gitignore syntax. For example, vendor/* skips tracked files beneath vendor. There are no default dependency or generated-folder exclusions. Tracked PowerShell files remain eligible unless explicitly excluded. The separate PipelineTemplates checkout is not scanned. If no matching files are found, the workflow reports that fact and succeeds.
Reports and policy
Each finding includes:
- File path.
- Line and column.
- Rule name.
- Diagnostic severity.
- Message.
Findings appear in the job log and GitHub annotations. A job summary records the selected settings file, file count, and finding count.
The lint workflow does not upload a separate report artifact.
| Outcome | Script exit code | Workflow behavior |
|---|---|---|
| No findings | 0 |
Succeeds |
Findings with fail-on-findings: true |
1 |
Reports findings and fails |
Findings with fail-on-findings: false |
0 |
Reports findings as warning annotations and succeeds |
| Installation, configuration, or execution failure | Script failures use 2; installation fails its own step |
Fails regardless of fail-on-findings |
Use warning-only mode while establishing a baseline:
Review the findings, fix issues or document intentional exceptions, then enable enforcement.
Permissions
The workflow only needs read access:
It does not commit, push, or execute the selected profile scripts.
Examples
Minimal scan
---
name: PowerShell lint
on:
pull_request:
branches:
- main
paths:
- "**/*.ps1"
- "**/*.psm1"
- "**/*.psd1"
permissions:
contents: read
jobs:
lint:
uses: redjax/PipelineTemplates/.github/workflows/powershell-lint.yml@feat/powershell-lint
with:
templates-ref: feat/powershell-lint
Use repository settings
jobs:
lint:
uses: redjax/PipelineTemplates/.github/workflows/powershell-lint.yml@feat/powershell-lint
with:
templates-ref: feat/powershell-lint
settings-file: PSScriptAnalyzerSettings.psd1
fail-on-findings: true
Scan selected folders
jobs:
lint:
uses: redjax/PipelineTemplates/.github/workflows/powershell-lint.yml@feat/powershell-lint
with:
templates-ref: feat/powershell-lint
paths: |
scripts
modules
exclude-paths: |
modules/vendor/*
scripts/tests/fixtures/*
Manual baseline scan
---
name: Lint PowerShell
on:
workflow_dispatch:
inputs:
fail-on-findings:
description: Fail the run when lint issues are found.
required: false
type: boolean
default: false
permissions:
contents: read
jobs:
lint:
uses: redjax/PipelineTemplates/.github/workflows/powershell-lint.yml@feat/powershell-lint
with:
templates-ref: feat/powershell-lint
paths: "."
fail-on-findings: ${{ inputs['fail-on-findings'] == true }}
Keep the workflow reference and templates-ref aligned while testing a feature branch.