Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

Adding powershell linter hook - best practice

Aberta
#2,645 11 comentários 4 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
4/5
Tempo estimado
3-5 dias
Facilidade para iniciantes
35/100
Tipo de issue
Funcionalidade
Clareza
Precisa de esclarecimento
Status de atividade
Estagnada
Stack de tecnologia
powershell
Domínio
tooling

Direção de pesquisa

Review the proposed powershell_scriptanalyzer hook configuration, especially entry, pass_filenames, and additional_dependencies, and compare it with pre-commit's documented hook behavior. Verify cross-platform invocation, option passing, and filename handling; done means a maintainable configuration addresses these cases without per-user entry overrides.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

search you tried in the issue tracker

powershell, return code, exit code

describe your issue

I'm working on a repository containing powershell scripts.
I have a pre-commit already enabled for other checks and I want to add powershell linting with https://github.com/PowerShell/PSScriptAnalyzer.

I added a hook config as
https://github.com/PowerShell/PSScriptAnalyzer/compare/master...juju4:PSScriptAnalyzer:devel-precommit

-   id: powershell_scriptanalyzer
    name: Powershell lint with PSScriptAnalyzer
    description: This runs PSScriptAnalyzer on your powershell files
    entry: pre-commit powershell_scriptanalyzer
    language: script
    files: ^.*\.ps1$
    types: [text]
    entry: pwsh -Command "Invoke-ScriptAnalyzer -Settings PSGallery -Recurse -ReportSummary -EnableExit -Path ."
    require_serial: false
    additional_dependencies: []
    minimum_pre_commit_version: '0'
    pass_filenames: false
    verbose: true

In the target repo, I added following config

-   repo: https://github.com/juju4/PSScriptAnalyzer
    rev: 4d6a4a36c78df215bc8fa637d05929eb7a9112d9
    hooks:
    -   id: powershell_scriptanalyzer
        entry: /usr/local/bin/pwsh -Command "Invoke-ScriptAnalyzer -Settings PSGallery -Recurse -ReportSummary -EnableExit -Path ."

3 minor issues as using entry to deal with them for now.

  • As I'm executing on non-windows system, I have to customize/duplicate entry value with pwsh full path. not sure if better way?
  • to support powershell cmdlet include/exclude rules or severity (https://github.com/PowerShell/PSScriptAnalyzer/blob/master/docs/Cmdlets/Invoke-ScriptAnalyzer.md), I again have to customize entry. any way to define pre-commit fields to pass that inside the pwsh Command? default args apply outside.
  • same problem applies if want pass_filenames=true. /usr/local/bin/pwsh -Command "Invoke-ScriptAnalyzer -Settings PSGallery -Recurse -ReportSummary -EnableExit -Path $@" did not work in my tests.

Else happy to take more comments

Thanks a lot for your work!

pre-commit --version

2.20.0

.pre-commit-config.yaml
repos:
-   repo: https://github.com/juju4/PSScriptAnalyzer
    rev: 4d6a4a36c78df215bc8fa637d05929eb7a9112d9
    hooks:
    -   id: powershell_scriptanalyzer
        entry: /usr/local/bin/pwsh -Command "Invoke-ScriptAnalyzer -Settings PSGallery -Recurse -ReportSummary -EnableExit -Path ."
~/.cache/pre-commit/pre-commit.log (if present)

No response

Linguagem predominante
Python
Estrelas
15.6k
Forks
1k
Métricas de merge de PRs
Nenhum PR com merge em 30d

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de pre-commit/pre-commit

Todas as issues de pre-commit/pre-commit

Issues semelhantes

Mais issues de Python

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.