Add pre-commit hook to verify static analysis passes & format is correct#11941
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a new githooks Dart package to automate pre-commit checks, including formatting and static analysis, for staged files. The package includes an installation script, a pre-commit command runner, and associated unit tests. Review feedback highlights a potential infinite loop on Windows when locating the .git directory, raw ANSI escape sequences being printed without verifying terminal support, the use of loose any version constraints in pubspec.yaml, and redundant dead code in the test mocks.
|
Would you be willing to file a bug to have me/us investigate why the performance gap was so large. |
|
autosubmit label was removed for flutter/packages/11941, because - The status or check suite Dashboard Checks has failed. Please fix the issues identified (or deflake) before re-applying this label. |
|
autosubmit label was removed for flutter/packages/11941, because - The status or check suite Dashboard Checks has failed. Please fix the issues identified (or deflake) before re-applying this label. |
…ect (flutter#11941) Adds a pre-commit hook that you can install to verify that `dart analyze --fatal-infos` and the package format are correct when you make a call to `git commit`. Intended to ensure agents commit code that meets are quality standards. Also makes the following updates the plugins tool: - Adds `--run-on-staged-packages` flag that allows the command to only run on files with staged changes. This flag cannot be run with any other flags that filter packages where the command runs (like `--run-on-dirty-packages`) - Adds optimization to the format tool to avoid invoking native tool chains to format when non-native files are modified Miscellaneous notes: - `script/githooks/bin/install_hooks.dart` is the script to install the hook that devs would need to run to use it. - I modeled the new `githooks` directory like https://github.com/flutter/flutter/tree/master/engine/src/flutter/tools/githooks to make it easier for folks to add new hooks ## Pre-Review Checklist **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
…r#189194) flutter/packages@52d84d6...20928d5 2026-07-09 44525804+sailendrabathi@users.noreply.github.com [video_player_android] Implement backBufferDurationMs in ExoPlayer (flutter/packages#12124) 2026-07-09 bolling.ludwig@gmail.com [camera_platform_interface] Make setJpegImageQuality default a no-op (flutter/packages#12123) 2026-07-09 36081049+anirudhsharma392@users.noreply.github.com [local_auth] Clarify getAvailableBiometrics documentation regarding iOS permissions (flutter/packages#11901) 2026-07-09 stuartmorgan@google.com [ci] Add a third web Dart unit test shard (2/2) (flutter/packages#12150) 2026-07-08 stuartmorgan@google.com [ci] Add a third web Dart unit test shard (1/2) (flutter/packages#12138) 2026-07-08 43054281+camsim99@users.noreply.github.com Add pre-commit hook to verify static analysis passes & format is correct (flutter/packages#11941) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC flutter-ecosystem@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Adds a pre-commit hook that you can install to verify that
dart analyze --fatal-infosand the package format are correct when you make a call togit commit. Intended to ensure agents commit code that meets are quality standards.Also makes the following updates the plugins tool:
--run-on-staged-packagesflag that allows the command to only run on files with staged changes. This flag cannot be run with any other flags that filter packages where the command runs (like--run-on-dirty-packages)Miscellaneous notes:
script/githooks/bin/install_hooks.dartis the script to install the hook that devs would need to run to use it.githooksdirectory like https://github.com/flutter/flutter/tree/master/engine/src/flutter/tools/githooks to make it easier for folks to add new hooksPre-Review Checklist
[shared_preferences]///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.Footnotes
Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2