Skip to content

chore: improve pre-commit hook — auto-install deps, add Python/Dart lint

Jérôme Revillard requested to merge chore/husky-pre-commit-lint into main

Problem

The current pre-commit hook silently skips linting when node_modules are missing (exit 0). This allows badly formatted code to reach CI, causing pipeline failures that could have been caught locally.

Also: Python (ruff) and Dart files are not covered by the pre-commit hook at all.

Changes

# Before: silent skip when no node_modules
if [ "$has_deps" = false ]; then
  echo "⚠ Pre-commit: node_modules not found. Lint will run in CI."
  exit 0  # ← silently passes badly formatted code
fi
npx lint-staged
# After: auto-install only what's needed, lint everything
- npm ci only for components with staged files (not all at once)
- ruff check --fix + ruff format on staged .py files  
- dart format on staged .dart files
- Explicit failure if npm ci fails (with fix instructions)

Behavior Matrix

Language Tool Trigger Auto-install
JS/Vue eslint + prettier (lint-staged) Staged .js, .vue npm ci in affected component only
Python ruff check + ruff format Staged .py N/A (global binary)
Dart dart format Staged .dart N/A (SDK)

Testing

  • Hook is executable and has valid shebang
  • lint-staged config in package.json unchanged (JS/Vue still works)
  • CI pipeline will validate
Edited by Jérôme Revillard

Merge request reports

Loading