A while ago, I wrote about using Travis to add continuous integration to your Dart projects.

I've started adding a new trick to tool/travis.sh: format verification.

I add a script to my tool directory:

#!/bin/sh
dart_files=$(git ls-tree --name-only --full-tree -r HEAD | grep '.dart$')
[ -z "$dart_files" ] && exit 0

unformatted=$(dartfmt -n $dart_files)
[ -z "$unformatted" ] && exit 0

# Some files are not dartfmt'd. Print message and fail.
echo >&2 "dart files must be formatted with dartfmt. Please run:"
for fn in $unformatted; do
echo >&2 " dartfmt -w $PWD/$fn"
done

exit 1

Then I add a line to the top of travis.sh:

# Ensure the source is formatted
$(dirname -- "$0")/ensure_dartfmt.sh

Here's a commit that adds this support to the dartdoc project.

I find it's much easier to collaborate on a code base when a whole pile of formatting arguments are settled upfront.

Cool? Let me know if you try this on your project.