Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,14 @@ if [ -n "$staged_pubspec" ] || [ -n "$staged_templates" ]; then
git add pubspec.yaml
fi

# 3. Fix and format Dart files if any were staged
# 3. Sort imports in and format the staged Dart files
#
# No `dart fix --apply`. It analyzed the whole project to apply a handful of
# fixes — ~9 s, most of what was left of a commit — and rewrote files that were
# not staged. The lints it fixes show in the IDE and block at pre-push; run
# `dart fix --apply` yourself when they come up.
if [ -n "$staged_dart_files" ]; then
echo "🧹 Applying automated dart fixes and sorting imports..."
dart fix --apply
echo "🧹 Sorting imports..."

# Sort imports in the STAGED files only. `--folders lib` rewrote every file
# under lib/ on every commit, and better_imports renders long `show` clauses
Expand All @@ -49,8 +53,8 @@ if [ -n "$staged_dart_files" ]; then
staged_csv=$(printf '%s,' $staged_dart_files | sed 's/,$//')
dart pub global run better_imports --silent --relative --files "$staged_csv"

# Format LAST. `dart fix` and better_imports both rewrite code, and their
# output is not formatter-clean at page_width:100. Formatting before them
# Format LAST. better_imports rewrites code, and its output is not
# formatter-clean at page_width:100. Formatting before it
# (or not at all) is how the tree drifted to 145 unformatted files and kept
# CI's "Check formatting" step red for a month.
echo "🎨 Formatting staged Dart files..."
Expand Down
4 changes: 2 additions & 2 deletions setup_hooks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
# What you get:
# pre-commit — formats staged Dart and sorts its imports; syncs templates
# into pubspec.yaml and sorts dependencies when those changed.
# A few seconds; runs on every commit. No analysis — that is
# the IDE's and pre-push's.
# About a second; runs on every commit. No analysis or
# `dart fix` — those are the IDE's and pre-push's.
# pre-push — `dart analyze` and the tests, the same gates CI runs, for
# what the push changes: none for docs, the packages only when
# packages/ changed.
Expand Down
Loading