Skip to content

Commit 5ffb350

Browse files
authored
Feature: Added Pre-Commit Hooks for Improved Formatting (CCExtractor#401)
* chore(pre-commit): add pre-commit hooks for dart code formatting and adding missing required trailing commas * docs(CONTRIBUTING): add pre-commit hooks section to CONTRIBUTING.md
1 parent a79181a commit 5ffb350

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

.github/hooks/pre_commit.sh

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Get the list of Dart files to check
2+
dart_files=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.(dart)$')
3+
4+
# Check if there are no Dart files to check
5+
if [[ -z "$dart_files" ]]; then
6+
exit 0
7+
fi
8+
9+
# Apply 'dart fix' to each file individually
10+
for file in $dart_files; do
11+
echo "Adding required trailing commas to $file..."
12+
dart fix --apply --code=require_trailing_commas "$file"
13+
done
14+
15+
echo "Formatting Dart files..."
16+
dart format $dart_files
17+
18+
echo "Dart files formatted successfully."
19+
exit 0

CONTRIBUTING.md

+21-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ Before getting started, ensure you have the following prerequisites installed on
3535

3636
6. **Documentation**: If your changes impact the user interface, configuration, or functionality, update the documentation to reflect the changes.
3737

38-
7. **Commit**: Commit your changes with a clear and concise message.
38+
7. **Commit**:
39+
40+
- **Activate pre-commit hooks (one-time process):** We strongly recommend activating the pre-commit hooks to ensure code consistency. Follow the instructions in the [Activating Pre-Commit Hooks](#activating-pre-commit-hooks) section. This is a one-time setup process, so you only need to do it once on your local machine.
41+
42+
- Commit your changes with a clear and concise message:
3943

4044
```bash
4145
git commit -m "Add feature/fix: Describe your changes here"
@@ -53,6 +57,22 @@ Before getting started, ensure you have the following prerequisites installed on
5357

5458
11. **Merge**: Once your PR is approved, it will be merged into the main project repository.
5559

60+
## Activating Pre-Commit Hooks
61+
62+
To ensure code consistency and improved code readability, we have implemented pre-commit hooks that automatically format your Dart code before each commit. To activate these hooks:
63+
64+
1. **Make the hook script executable:**
65+
66+
```bash
67+
chmod +x .github/hooks/pre_commit.sh
68+
```
69+
70+
2. **Create a symbolic link to the hook:**
71+
72+
```bash
73+
ln -s ../../.github/hooks/pre_commit.sh .git/hooks/pre-commit
74+
```
75+
5676
## Reporting Issues
5777

5878
If you find a bug or have a suggestion for improvement, please create an [issue](https://github.com/CCExtractor/ultimate_alarm_clock/issues/new) on the project's GitHub repository. Be sure to include a clear and detailed description of the problem or enhancement.

0 commit comments

Comments
 (0)