PowerShell / PSScriptAnalyzer

Download ScriptAnalyzer from PowerShellGallery
https://www.powershellgallery.com/packages/PSScriptAnalyzer/
MIT License
1.8k stars 366 forks source link

Add a pre-commit hook for psscriptanalyzer #1969

Open winterz opened 4 months ago

winterz commented 4 months ago

it would be quite useful if I could use thehttps://pre-commit.com/tool to run PSScriptAnalyzer on my powershell scripts during the git commit stage. then I could find problems in my powershell code before they land into git repositories.

information how about to write a pre-commit hook can be found at https://pre-commit.com/#new-hooks Proposed technical implementation details (optional)

for example, a pre-commit hook for pylint (the python linter) is at https://github.com/pylint-dev/pylint

bergmeister commented 2 months ago

@winterz What do you expect PSScriptAnalyzer to do to enable that? Because it is a PowerShell based tool and therefore not in the list of supported languages here: https://[pre-commit](https://pre-commit.com/#supported-languages).com/#supported-languages But it has script support so I assume that goes to bash or cmd depending on OS and you could write a small script that calls PowerShell to then call PSScriptAnalyzer and use the -EnableExitCode switch to signal success/failure

winterz commented 2 months ago

right. I had forgotten about the supported languages problem. oh well. just an idea. feel free to close this