diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 89940c68..2f377b4c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -120,6 +120,41 @@ git remote add upstream https://github.com/scribe-org/Scribe-Android.git > [!NOTE] > Feel free to contact the team in the [Android room on Matrix](https://matrix.to/#/#ScribeAndroid:matrix.org) if you're having problems getting your environment setup! +## Pre-commit Hooks [`⇧`](#contents) + +Scribe-Android uses pre-commit hooks to maintain a clean and consistent codebase. These hooks help automatically check for issues such as formatting, trailing whitespace, and linting errors. Here's how to set up pre-commit for Scribe-Android: + +1. Install `pre-commit` by running: + + ```bash + pip install pre-commit + ``` + +2. After cloning the repository, install the hooks by running the following command in the project root: + + ```bash + pre-commit install + pre-commit run --all-files # to check + ``` + +3. When you make a commit, the hooks will automatically run to check for any code quality issues. If any issues are found, they will either be fixed automatically or will need to be resolved manually. + +## Testing [`⇧`](#contents) + +Scribe-Android includes a testing suite that should be ran before all pull requests and subsequent commits. Please run the following in the project root: + +```bash +# Run ktlint and detekt: +./gradlew lintKotlin detekt +./gradlew test +``` + +If you see that there are linting errors above, then please run the following command to hopefully fix them automatically: + +```bash +ktlint --format +``` + ## Testing [`⇧`](#contents) diff --git a/pre-commit-config.yaml b/pre-commit-config.yaml new file mode 100644 index 00000000..06573a7b --- /dev/null +++ b/pre-commit-config.yaml @@ -0,0 +1,21 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + + - repo: local + hooks: + - id: ktlint + name: ktlint + entry: ./gradlew lintKotlin + language: system + types: [kotlin] + + - id: detekt + name: detekt + entry: ./gradlew detekt + language: system + types: [kotlin]