-
Notifications
You must be signed in to change notification settings - Fork 1
Add PSScriptAnalyzer hook for PowerShell sources #59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| @{ | ||
| # Auto-discovered by the VS Code PowerShell extension, so the editor and the | ||
| # psscriptanalyzer hk step enforce the same rules. The step fails on any | ||
| # finding (all severities), so no Severity gate is set. Default correctness | ||
| # rules run regardless (IncludeDefaultRules only matters with CustomRulePath); | ||
| # the entries below opt into the formatting rules, which are off by default. | ||
| Rules = @{ | ||
| PSAvoidLongLines = @{ | ||
| Enable = $true | ||
| MaximumLineLength = 100 | ||
| } | ||
| PSAvoidSemicolonsAsLineTerminators = @{ Enable = $true } | ||
| PSPlaceCloseBrace = @{ | ||
| Enable = $true | ||
| NoEmptyLineBefore = $true | ||
| } | ||
| PSPlaceOpenBrace = @{ Enable = $true } | ||
| PSUseConsistentIndentation = @{ | ||
| Enable = $true | ||
| IndentationSize = 2 | ||
| } | ||
| PSUseConsistentWhitespace = @{ | ||
| Enable = $true | ||
| CheckParameter = $true | ||
| } | ||
| PSUseCorrectCasing = @{ Enable = $true } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
home/.chezmoiscripts/windows/run_onchange_after_skills-symlinks.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| # Symlink ~/.claude/skills to the canonical ~/.agents/skills directory so | ||
| # Claude Code (which only reads ~/.claude/skills) sees the shared skills. | ||
| $SkillsTarget = Join-Path $env:USERPROFILE ".agents" "skills" | ||
| $Link = Join-Path $env:USERPROFILE ".claude" "skills" | ||
| $SkillsTarget = Join-Path -Path $env:USERPROFILE -ChildPath ".agents" -AdditionalChildPath "skills" | ||
| $Link = Join-Path -Path $env:USERPROFILE -ChildPath ".claude" -AdditionalChildPath "skills" | ||
| if (Test-Path $Link) { Remove-Item $Link -Force } | ||
| New-Item -ItemType SymbolicLink -Path $Link -Target $SkillsTarget | Out-Null |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| @{ | ||
| # PowerShell Gallery modules the dev toolchain provisions into a repo-local, | ||
| # gitignored .psmodules via scripts/provision-psmodules.ps1 (run from the mise | ||
| # postinstall hook). Add a module by listing its pinned version here; the | ||
| # provisioner is generic and installs whatever this manifest declares. | ||
| # | ||
| # Renovate keeps these current via the nuget datasource pointed at the | ||
| # PowerShell Gallery feed (a custom manager in .github/renovate.json), so a | ||
| # bump lands like any other dependency PR. Keep the mapping alphabetical to | ||
| # reduce merge conflicts. | ||
| PSScriptAnalyzer = '1.24.0' | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| #!/usr/bin/env pwsh | ||
| # Lint PowerShell sources with PSScriptAnalyzer, mirroring | ||
| # scripts/lint-templates.sh: hk passes the changed files as positional args and | ||
| # this wraps the module so the hk step stays a one-liner. Rules live in | ||
| # PSScriptAnalyzerSettings.psd1 at the repo root (also honored by the VS Code | ||
| # PowerShell extension). | ||
| # | ||
| # Check-only: PSScriptAnalyzer's -Fix rewrites files in place and throws on some | ||
| # valid inputs (e.g. NullReferenceException on scripts with backtick line | ||
| # continuations), so autofix is left to the editor, which applies the same psd1. | ||
| [CmdletBinding()] | ||
| param( | ||
| [Parameter(ValueFromRemainingArguments = $true)] | ||
| [string[]]$Path = @() | ||
| ) | ||
|
|
||
| Set-StrictMode -Version Latest | ||
| $ErrorActionPreference = 'Stop' | ||
|
|
||
| if ($Path.Count -eq 0) { exit 0 } | ||
|
|
||
| # Prefer the repo-local, pinned module provisioned by provision-psmodules.ps1; | ||
| # fall back to whatever PSScriptAnalyzer is already on PSModulePath. | ||
| $root = Join-Path $PSScriptRoot '..' | ||
| $repoModules = Join-Path $root '.psmodules' | ||
| if (Test-Path $repoModules) { | ||
| $env:PSModulePath = $repoModules + [IO.Path]::PathSeparator + $env:PSModulePath | ||
| } | ||
|
|
||
| $settings = Join-Path $root 'PSScriptAnalyzerSettings.psd1' | ||
|
|
||
| # Invoke-ScriptAnalyzer -Path is single-valued, so analyze each file in turn. | ||
| $findings = foreach ($file in $Path) { | ||
| Invoke-ScriptAnalyzer -Path $file -Settings $settings | ||
| } | ||
|
|
||
| if ($findings) { | ||
| $report = $findings | | ||
| Format-Table -AutoSize -Wrap -Property Severity, RuleName, | ||
| @{ Label = 'Location'; Expression = { '{0}:{1}' -f $_.ScriptPath, $_.Line } }, | ||
| Message | | ||
| Out-String | ||
| [Console]::Error.WriteLine($report) | ||
| exit 1 | ||
| } | ||
| exit 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| #!/usr/bin/env pwsh | ||
| # Provision pinned PowerShell Gallery modules into a repo-local, gitignored | ||
| # .psmodules so PowerShell-backed hk steps (e.g. psscriptanalyzer) are | ||
| # reproducible across dev machines and CI. mise has no PowerShell Gallery | ||
| # backend (and none is tracked upstream), so this bootstrap is the durable way | ||
| # to pin PS modules alongside the aqua-managed pwsh in mise.toml. | ||
| # | ||
| # Generic and data-driven: the module -> version map lives in | ||
| # powershell-modules.psd1 at the repo root. Idempotent -- a module already | ||
| # present at its pinned version is skipped, so re-running the postinstall hook | ||
| # is cheap. | ||
| [CmdletBinding()] | ||
| param() | ||
|
|
||
| Set-StrictMode -Version Latest | ||
| $ErrorActionPreference = 'Stop' | ||
|
|
||
| $root = Join-Path $PSScriptRoot '..' | ||
| $manifest = Join-Path $root 'powershell-modules.psd1' | ||
| $dest = Join-Path $root '.psmodules' | ||
|
|
||
| $modules = Import-PowerShellDataFile -Path $manifest | ||
| if ($modules.Count -eq 0) { exit 0 } | ||
|
|
||
| New-Item -ItemType Directory -Force -Path $dest | Out-Null | ||
|
|
||
| foreach ($name in $modules.Keys) { | ||
| $version = $modules[$name] | ||
| if (Test-Path (Join-Path $dest "$name/$version")) { continue } | ||
|
|
||
| [Console]::Error.WriteLine("Provisioning $name $version into .psmodules") | ||
| Save-Module -Name $name -RequiredVersion $version -Repository PSGallery -Path $dest | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.