From 969c03d8949ebc30ee4d9f57f0216ecf20999862 Mon Sep 17 00:00:00 2001 From: Arpita Kesharwani Date: Tue, 22 Oct 2024 15:55:41 +0530 Subject: [PATCH 1/3] Added Config file and the related documentation --- CONTRIBUTING.md | 52 ++++++++++++++++++++++++++++++++++++++++-- pre-commit-config.yaml | 15 ++++++++++++ 2 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 pre-commit-config.yaml diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8d63cfa1..8a683065 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -116,8 +116,56 @@ git remote add upstream https://github.com/scribe-org/Scribe-Android.git - Press the play button marked "Run App" - From here code edits that are made will be reflected in the app each time it is ran -> [!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! +[!NOTE] Feel free to contact the team in the Android room on Matrix if you're having problems getting your environment set up! + +## Pre-commit Hooks [`⇧`](#contents) + +To maintain a clean and consistent codebase, Scribe-Android uses **pre-commit hooks**. 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 + ``` + +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. + +### List of pre-commit hooks + +Here are some of the pre-commit hooks configured for this project: + +- **trailing-whitespace**: Removes any trailing whitespaces in the code. +- **end-of-file-fixer**: Ensures that files end with a newline. +- **ruff**: Lints Python code (for any Python scripts used in the project). + +If you want to run these checks manually, use the following command: + +```bash +pre-commit run --all-files + +``` + +## 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 +``` diff --git a/pre-commit-config.yaml b/pre-commit-config.yaml new file mode 100644 index 00000000..ee986b09 --- /dev/null +++ b/pre-commit-config.yaml @@ -0,0 +1,15 @@ +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 + # - id: check-added-large-files + + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.3.0 + hooks: + - id: ruff + args: [--fix, --exit-non-zero-on-fix] + - id: ruff-format From 81e757f9f7013f6cfb6cc67c3ef75a07fd0004e9 Mon Sep 17 00:00:00 2001 From: Arpita Kesharwani Date: Tue, 22 Oct 2024 21:28:38 +0530 Subject: [PATCH 2/3] Added ktlint and detekt for local run --- pre-commit-config.yaml | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/pre-commit-config.yaml b/pre-commit-config.yaml index ee986b09..3ec46221 100644 --- a/pre-commit-config.yaml +++ b/pre-commit-config.yaml @@ -1,15 +1,28 @@ 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 - # - id: check-added-large-files + - 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: https://github.com/astral-sh/ruff-pre-commit - rev: v0.3.0 - hooks: - - id: ruff - args: [--fix, --exit-non-zero-on-fix] - - id: ruff-format + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.3.0 + hooks: + - id: ruff + args: [--fix, --exit-non-zero-on-fix] + - id: ruff-format + + - 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] From a044236332a28f2b3e9696d19f54519b3b3b89c9 Mon Sep 17 00:00:00 2001 From: Andrew Tavis McAllister Date: Wed, 23 Oct 2024 00:32:22 +0200 Subject: [PATCH 3/3] Clean up contributing and remove ruff --- CONTRIBUTING.md | 21 ++++----------------- pre-commit-config.yaml | 7 ------- 2 files changed, 4 insertions(+), 24 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4db5408e..2f377b4c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -117,11 +117,12 @@ git remote add upstream https://github.com/scribe-org/Scribe-Android.git - Press the play button marked "Run App" - From here code edits that are made will be reflected in the app each time it is ran -[!NOTE] Feel free to contact the team in the Android room on Matrix if you're having problems getting your environment set up! +> [!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) -To maintain a clean and consistent codebase, Scribe-Android uses **pre-commit hooks**. 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: +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: @@ -133,25 +134,11 @@ To maintain a clean and consistent codebase, Scribe-Android uses **pre-commit ho ```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. -### List of pre-commit hooks - -Here are some of the pre-commit hooks configured for this project: - -- **trailing-whitespace**: Removes any trailing whitespaces in the code. -- **end-of-file-fixer**: Ensures that files end with a newline. -- **ruff**: Lints Python code (for any Python scripts used in the project). - -If you want to run these checks manually, use the following command: - -```bash -pre-commit run --all-files - -``` - ## 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: diff --git a/pre-commit-config.yaml b/pre-commit-config.yaml index 3ec46221..06573a7b 100644 --- a/pre-commit-config.yaml +++ b/pre-commit-config.yaml @@ -6,13 +6,6 @@ repos: - id: end-of-file-fixer - id: check-yaml - - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.3.0 - hooks: - - id: ruff - args: [--fix, --exit-non-zero-on-fix] - - id: ruff-format - - repo: local hooks: - id: ktlint