This guide covers code quality standards and linting procedures for ColorScripts-Enhanced module development.
Lint the module files only:
pwsh -NoProfile -Command "& .\scripts\Lint-Module.ps1"Or using npm:
npm run lintInclude test files and treat warnings as errors:
pwsh -NoProfile -Command "& .\scripts\Lint-Module.ps1" -IncludeTests -TreatWarningsAsErrorsOr using npm:
npm run lint:strictApply ScriptAnalyzer auto-fixes where possible:
pwsh -NoProfile -Command "& .\scripts\Lint-Module.ps1" -FixOr using npm:
npm run lint:fixFor PowerShell 7 specific linting:
.\scripts\Lint-PS7.ps1The project uses custom ScriptAnalyzer rules defined in PSScriptAnalyzerSettings.psd1.
- PSAvoidUsingCmdletAliases - Use full cmdlet names, not aliases
- PSAvoidUsingWriteHost - Prefer
Write-Outputor streams - PSPlaceOpenBrace - Opening braces on same line
- PSPlaceCloseBrace - Closing braces on new line
- PSUseConsistentIndentation - 4 spaces, no tabs
- PSUseConsistentWhitespace - Consistent spacing around operators
See the PSScriptAnalyzerSettings.psd1 file for the complete ruleset.
ColorScripts-Enhanced.psm1- Main module fileColorScripts-Enhanced.psd1- Module manifestInstall.ps1- Installation script
- All files in
scripts/directory - All files in
Tests/directory
- Colorscript files in
ColorScripts-Enhanced/Scripts/(these are data files, not code)
❌ Wrong:
gci -Path $path | % { Write-Host $_.Name }✅ Correct:
Get-ChildItem -Path $path | ForEach-Object { Write-Output $_.Name }❌ Wrong:
if ($condition)
{
# Code
}✅ Correct:
if ($condition) {
# Code
}❌ Wrong:
function Test {
Write-Output "Bad indentation"
}✅ Correct:
function Test {
Write-Output "Proper indentation"
}❌ Wrong:
Write-Host "Processing $item"✅ Correct:
Write-Verbose "Processing $item"
# Or for user-facing output:
Write-Output "Processing $item"In rare cases where a rule must be suppressed:
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '')]
param()
Write-Host "This is intentionally user-facing output"Note: Suppressions should be rare and well-documented.
Linting is automatically run in GitHub Actions:
- Test Workflow - Runs
Invoke-ScriptAnalyzeron module files - Strict Mode - Treats warnings as errors in CI
- Cross-Platform - Validates on Windows, Linux, and macOS
See .github/workflows/test.yml for CI configuration.
Consider adding linting to your pre-commit workflow:
# In .git/hooks/pre-commit
pwsh -NoProfile -File ./scripts/Lint-Module.ps1 -IncludeTests -TreatWarningsAsErrors
if ($LASTEXITCODE -ne 0) {
Write-Host "Linting failed. Please fix issues before committing."
exit 1
}If you don't have PSScriptAnalyzer installed:
Install-Module -Name PSScriptAnalyzer -Force -SkipPublisherCheckThe linting rules may evolve as the project grows. When updating rules:
- Update
PSScriptAnalyzerSettings.psd1 - Run
npm run lint:fixto auto-fix where possible - Manually fix remaining issues
- Update this guide if new patterns emerge
- Testing Guide - Testing procedures
- Development Guide - Complete development workflow
- Contributing Guidelines - How to contribute
- PSScriptAnalyzer Documentation - Official docs