diff --git a/.githooks/pre-commit b/.githooks/pre-commit index 35c929d..6149c7c 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -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 @@ -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..." diff --git a/setup_hooks.sh b/setup_hooks.sh index 0602689..9afece5 100755 --- a/setup_hooks.sh +++ b/setup_hooks.sh @@ -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.