Skip to content
This repository was archived by the owner on Apr 14, 2026. It is now read-only.

fix(hooks): add dart fix step and worktree-safe wrappers#234

Closed
runyaga wants to merge 1 commit intomainfrom
chore/dart-fix-precommit
Closed

fix(hooks): add dart fix step and worktree-safe wrappers#234
runyaga wants to merge 1 commit intomainfrom
chore/dart-fix-precommit

Conversation

@runyaga
Copy link
Copy Markdown
Collaborator

@runyaga runyaga commented Feb 8, 2026

Summary

  • Add dart fix --apply as pre-commit hook step before dart format
  • Add wrapper scripts that unset GIT_DIR for worktree compatibility

Changes

  • .pre-commit-config.yaml: New dart-fix hook runs first; all hooks use scripts/ wrappers with language: script
  • scripts/dart-fix.sh: Unsets GIT_DIR, runs dart fix --apply
  • scripts/dart-format.sh: Unsets GIT_DIR, runs dart format
  • scripts/flutter-analyze.sh: Unsets GIT_DIR, runs flutter analyze

Problem

dart format wraps long argument lists to multiple lines but does not add trailing commas. flutter analyze --fatal-infos then rejects the result due to require_trailing_commas. This creates a cycle where format produces code that analyze rejects.

Additionally, git worktrees set GIT_DIR which breaks Flutter's SDK version detection (reports 0.0.0-unknown), causing flutter analyze to fail with version resolution errors.

Solution

Hook order: dart fixdart formatflutter analyze

dart fix --apply inserts trailing commas (and other auto-fixable lints) before dart format touches whitespace. Wrapper scripts unset GIT_DIR for worktree compatibility.

Test plan

  • Pre-commit hooks pass on commit
  • Hooks work from git worktrees (unset GIT_DIR)
  • Verify hooks on fresh clone (manual)

Generated with Claude Code

Two fixes for pre-commit hooks:

1. dart format can wrap long argument lists to multiple lines without
   adding trailing commas. flutter analyze --fatal-infos then rejects
   the result due to require_trailing_commas. Adding dart fix --apply
   as the first hook step closes this gap.

2. Git sets GIT_DIR in worktrees, which breaks Flutter's version
   detection (reports 0.0.0-unknown). Wrapper scripts in scripts/
   unset GIT_DIR before calling dart/flutter commands.

Hook order: dart fix → dart format → flutter analyze
@WilliamKarolDiCioccio
Copy link
Copy Markdown
Collaborator

@runyaga the pre-commit hooks fail on Windows as they're calling .sh scripts. We need either to set the language to system and use platform agnostic commands or set it to Python and change the scripts. I'd go for the latter.

@WilliamKarolDiCioccio
Copy link
Copy Markdown
Collaborator

@runyaga We will need to run pre-commit --all-files before merging this. I suggest waiting for the weekend.

@runyaga runyaga closed this Feb 11, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants