Skip to content

Commit

Permalink
Feature: Added Pre-Commit Hooks for Improved Formatting (#401)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
superiorsd10 authored Feb 3, 2024
1 parent a79181a commit 5ffb350
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
19 changes: 19 additions & 0 deletions .github/hooks/pre_commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Get the list of Dart files to check
dart_files=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.(dart)$')

# Check if there are no Dart files to check
if [[ -z "$dart_files" ]]; then
exit 0
fi

# Apply 'dart fix' to each file individually
for file in $dart_files; do
echo "Adding required trailing commas to $file..."
dart fix --apply --code=require_trailing_commas "$file"
done

echo "Formatting Dart files..."
dart format $dart_files

echo "Dart files formatted successfully."
exit 0
22 changes: 21 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ Before getting started, ensure you have the following prerequisites installed on

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

7. **Commit**: Commit your changes with a clear and concise message.
7. **Commit**:

- **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.

- Commit your changes with a clear and concise message:

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

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

## Activating Pre-Commit Hooks

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:

1. **Make the hook script executable:**

```bash
chmod +x .github/hooks/pre_commit.sh
```

2. **Create a symbolic link to the hook:**

```bash
ln -s ../../.github/hooks/pre_commit.sh .git/hooks/pre-commit
```

## Reporting Issues

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.
Expand Down

0 comments on commit 5ffb350

Please sign in to comment.