Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Adding powershell linter hook - best practice

Abierto
#2,645 11 comentarios 4 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
35/100
Tipo de issue
Nueva funcionalidad
Claridad
Necesita aclaración
Estado de actividad
Estancado
Stack tecnológico
powershell
Área
tooling

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
Python
Estrellas
15.6k
Forks
1k
Métricas de merge de PR
Sin PR fusionados en 30 d

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de pre-commit/pre-commit

Todos los issues de pre-commit/pre-commit

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.