diff --git a/.github/workflows/format_lint_test.yaml b/.github/workflows/format_lint_test.yaml index 636ccc151..1163a17aa 100644 --- a/.github/workflows/format_lint_test.yaml +++ b/.github/workflows/format_lint_test.yaml @@ -17,7 +17,7 @@ jobs: with: flutter-version: ${{ env.FLUTTER_VERSION }} - - run: dart format . --set-exit-if-changed + - run: dart format $(find . -type f -name "*.dart" -a -not -name "*.g.dart") --set-exit-if-changed lint: name: 'Lint' diff --git a/pre-commit-hook.sh b/pre-commit-hook.sh new file mode 100755 index 000000000..838253711 --- /dev/null +++ b/pre-commit-hook.sh @@ -0,0 +1,15 @@ +#!/bin/sh +mkdir -p .git/hooks #it seems that are some cases where git will not create a hook directory if someone removed the hook templates +tee .git/hooks/pre-commit << EOF +#!/bin/sh + +FILES="\$(git diff --name-only --cached | grep .*\.dart | grep -v .*\.g\.dart)" + +[ -z "\$FILES" ] && exit 0 + + +echo "\$FILES" | xargs dart format +echo "\$FILES" | xargs git add +EOF + +chmod +x .git/hooks/pre-commit diff --git a/uni/README.md b/uni/README.md index ab4b56a28..f9d2ee3c1 100644 --- a/uni/README.md +++ b/uni/README.md @@ -16,6 +16,20 @@ The token is read from the file assets/env/env.json, which you may need to creat } ``` +### Automated formatting + +In order to contribute, you must format your changed files using `dart format` manually or enabing _formatting on save_ using your IDE ([VSCode or IntelliJ](https://docs.flutter.dev/tools/formatting)). Alternatively, you can install the git pre-commit hook that formats your changed files when you commit, doing the following command at the **root directory of the repository**: + +``` bash + chmod +x pre-commit-hook.sh && ./pre-commit-hook.sh +``` + +In order to remove it, is it as simple as running the following command, from the **root directory of the repository**: + +```bash + rm .git/hooks/pre-commit +``` + ## Project structure ### Overview @@ -36,4 +50,4 @@ The *view* part of the app is made of *widgets* (stateful or stateless). They ea ### Controller -The *controller* directory contains all artifacts that are not directly related to the view or the model. This includes the parsers, the networking code, the database code and the logic that handles the global state of the app. \ No newline at end of file +The *controller* directory contains all artifacts that are not directly related to the view or the model. This includes the parsers, the networking code, the database code and the logic that handles the global state of the app.