Skip to content

Instantly share code, notes, and snippets.

@danielgomezrico
Created December 27, 2020 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielgomezrico/8c8fa1f0f553278f086397c2b73b204a to your computer and use it in GitHub Desktop.
Save danielgomezrico/8c8fa1f0f553278f086397c2b73b204a to your computer and use it in GitHub Desktop.
Flutter - Check code format and fail if does not work, useful for CI flows
#!/usr/bin/env bash
#
# Runs dartfmt from dart_style to check if all of the source files are well formatted
# Requires you to have dartfmt already in your path with 'pub global activate dart_style'
#
echo "-> Running 'flutter format' to check project dart style 🤓"
RESULT=$(flutter format -n lib/main.dart lib/src/ test/)
if [[ $? != 0 ]]; then
echo "----> Command failed."
elif [[ $RESULT ]]; then
echo "----> Some files are looking weird here 🤓:"
echo "$RESULT"
exit 1
else
echo "----> All format is good ✅"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment