diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d56187b1..0f6425fd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -34,7 +34,10 @@ jobs: echo BACKTRACE_CORONER_TOKEN=\"${{ secrets.BACKTRACE_CORONER_TOKEN }}\" >> ./local.properties - name: Accept Android SDK licences - run: yes | "${ANDROID_HOME}/cmdline-tools/latest/bin/sdkmanager" --licenses + run: yes | "${ANDROID_HOME}/cmdline-tools/latest/bin/sdkmanager" --licenses + + - name: Check Code Style + run: ./gradlew spotlessCheck - name: Build and check run: ./gradlew assembleDebug assembleDebugAndroidTest build check diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..adcdd78d --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,22 @@ +repos: + - repo: local + hooks: + - id: start-hook + name: start-hook + entry: echo 'Start pre-commit' + language: system + stages: [pre-commit] + pass_filenames: false +## TODO: before merge - remove above and uncomment below +# - id: spotless-apply +# name: Spotless Apply +# entry: ./gradlew spotlessApply +# language: system +# stages: [pre-commit] +# pass_filenames: false +# - id: spotless-check +# name: Spotless Check +# entry: ./gradlew spotlessCheck +# language: system +# stages: [pre-commit] +# pass_filenames: false diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index bf725190..f3733e38 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,27 +1,31 @@ # Contributing -Thank you for considering contributing to Backtrace Android SDK library. Here are some guidelines to help you get started: - -### Getting Started - -1. **Clone the Repository** - - Clone the repository to your local machine using: - ```bash - git clone https://github.com/backtrace-labs/backtrace-android.git - ``` - -2. **Create a Branch** - - It's good practice to create a new branch for each feature or bugfix, if you have jira ticket put ticket number as branch prefix: - ```bash - git checkout -b jira-ticket/your-feature-name - ``` +Thank you for your interest in contributing to the Backtrace Android SDK. Please review the following guidelines to help you get started. + +## Getting Started + +1. **Clone the repository** + ```bash + git clone https://github.com/backtrace-labs/backtrace-android.git + ``` + +2. **Install pre-commit** + ```bash + pip install pre-commit + pre-commit install + ``` + +3. **Create a branch** - it's good practice to create a new branch for each feature or bugfix, if you have jira ticket put ticket number as branch prefix: + ```bash + git checkout -b jira-ticket/your-feature-name + ``` -3. **Update submodules** -```bash -git submodule update --recursive --remote -git submodule update --init --recursive -``` - -### Coding Guidelines +4. **Update submodules** + ```bash + git submodule update --recursive --remote + git submodule update --init --recursive + ``` + +## Coding Guidelines 1. **Code Formatting** - Make sure that your code is properly formatted using the default Android Studio formatter. @@ -34,7 +38,7 @@ git submodule update --init --recursive 3. **Write Tests** - Ensure that you write tests for the new functionality or changes made. This helps maintain the integrity of the project. -### Commit and Push +## Commit and Push 1. **Commit Your Changes** - Write clear and concise commit messages. Follow the convention of using the imperative mood in the subject line. @@ -48,7 +52,7 @@ git submodule update --init --recursive git push origin jira-ticket/your-feature-name ``` -### Create a Pull Request +## Create a Pull Request 1. **Submit a Pull Request** - Go to the repository on GitHub and click on the `New Pull Request` button. @@ -57,8 +61,33 @@ git submodule update --init --recursive 2. **Review Process** - One of the project maintainers will review your pull request. Please be responsive to any comments or suggestions made. -### Additional Notes +## Additional Notes - Ensure that your code follows the existing code style and structure. - Keep your branch up to date with the latest changes from the `master` branch to avoid merge conflicts. + +## Code Formatting + +This project uses **[Spotless](https://github.com/diffplug/spotless)** (a code formatting plugin) integrated with **[pre-commit](https://pre-commit.com/)** to ensure consistent code style and automatic formatting before each commit. + +### Setup Instructions + +1. Run Spotless check +This verifies that your code meets the project’s formatting standards. + ```bash + ./gradlew spotlessCheck + ``` + +2. (Optional) Automatically reformat code +If formatting issues are found, you can automatically fix them with: + ```bash + ./gradlew spotlessApply + ``` + +**Notes** +- The pre-commit hook ensures code formatting is validated automatically before commits are created. +- You can manually trigger all pre-commit checks at any time with: + ```bash + pre-commit run --all-files + ``` diff --git a/build.gradle b/build.gradle index 279b5063..0f0477b0 100644 --- a/build.gradle +++ b/build.gradle @@ -13,6 +13,58 @@ buildscript { } } +plugins { + id 'com.diffplug.spotless' version '8.0.0' apply false +} + +def spotlessExcludes = [ + '.github/**', + '.gradle/**', + '.idea/**', + 'build/**', + '**/cpp/**', + '**/jniLibs/**', + '**/build/**', + '**/build-*/**', + '**/.cxx/**', + '**/generated/**' +] + +subprojects { + apply plugin: 'com.diffplug.spotless' + spotless { + java { + target '**/*.java' + targetExclude spotlessExcludes + palantirJavaFormat() + removeUnusedImports() + trimTrailingWhitespace() + endWithNewline() + } + json { + target '**/*.json' + targetExclude spotlessExcludes + simple() + } + + format 'gradle', { + target '**/*.gradle' + targetExclude spotlessExcludes + leadingTabsToSpaces(4) + trimTrailingWhitespace() + endWithNewline() + } + + + format 'misc', { + target '*.md', '.gitignore' + targetExclude spotlessExcludes + trimTrailingWhitespace() + endWithNewline() + } + } +} + allprojects { repositories { google()