Ideally, I would like to have dartfmt
to format my code on every commit, and I think that git hooks
are ideal for this. So far, I've tried the code found in this link, but with no success, despite it appearing on multiple other websites — maybe it's outdated.
In the end, I think nothing much more complicated than this should work in most cases (inside the .git/hooks/pre-commit
file):
#!/bin/bash
dartfmt -w . # or maybe `flutter format .` for Flutter
The errors I get are:
- For
dartfmt -w .
:dartfmt: command not found
- For
flutter format .
:find: ‘> bin [’: No such file or directory
Both of those commands do work if placed directly in the terminal.