Skip to content

Instantly share code, notes, and snippets.

@akyunus
Last active June 13, 2026 19:59
Show Gist options
  • Select an option

  • Save akyunus/3b875df0d5b8070cb643c289ce3bfa8b to your computer and use it in GitHub Desktop.

Select an option

Save akyunus/3b875df0d5b8070cb643c289ce3bfa8b to your computer and use it in GitHub Desktop.
lintool is a bash script for flutter projects to automate checks before creating a Pull Request
#!/bin/bash
#minimum code coverage value
coverage_limit=70
exit_message () {
echo -e "\e[1;31m πŸ˜… Lintool failed.\n πŸͺ› Check the issues.\n 🐝 Run again.\e[0m"
exit 0
}
dart format --set-exit-if-changed lib test || exit_message
# shellcheck disable=SC2015
flutter analyze lib test || (dart fix --apply && flutter analyze lib test || exit_message)
flutter test -j 4 --no-pub --coverage --test-randomize-ordering-seed random || exit_message
coverage_output=$(genhtml coverage/lcov.info -o coverage/) # | grep -Eoh '[0-9]+.[0-9]+%')
regex="([0-9]+)\.[0-9]*%"
if [[ $coverage_output =~ $regex ]]
then
coverage_value="${BASH_REMATCH[1]}"
echo "Code Coverage is $coverage_value%"
if [ $coverage_value -lt $coverage_limit ]
then
echo "Code Coverage must be at least $coverage_limit%"
exit_message
fi
else
echo "πŸ˜… Can't detect Code Coverage Value. Check it yourself."
fi
echo -e "\e[1;32m Ready to push!\e[0m πŸš€"
@akyunus

akyunus commented Oct 6, 2022

Copy link
Copy Markdown
Author

Run the script at project root folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment