Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pre-commit hook #867

Merged
merged 9 commits into from
Jul 27, 2023
2 changes: 1 addition & 1 deletion .github/workflows/format_lint_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
15 changes: 15 additions & 0 deletions pre-commit-hook.sh
Original file line number Diff line number Diff line change
@@ -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
16 changes: 15 additions & 1 deletion uni/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
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.