Skip to content

Commit

Permalink
chore: add support to obj-c and java formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
jokerttu committed Aug 30, 2024
1 parent 2898ed7 commit c61a6a5
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 23 deletions.
31 changes: 26 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ on:
jobs:
lint:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup
uses: ./.github/actions/setup
Expand All @@ -38,11 +39,28 @@ jobs:
- name: Typecheck files
run: yarn test:types

check-formatting:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install clang-format and google-java-format
run: sudo apt-get install clang-format-18 google-java-format

- name: Check Objective-C formatting
run: ./scripts/format-objc.sh --check

- name: Check Java formatting
run: ./scripts/format-java.sh --check

test:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup
uses: ./.github/actions/setup
Expand All @@ -52,9 +70,10 @@ jobs:

build-library:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup
uses: ./.github/actions/setup
Expand All @@ -64,11 +83,12 @@ jobs:

build-android:
runs-on: ubuntu-latest
timeout-minutes: 30
env:
TURBO_CACHE_DIR: .turbo/android
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup
uses: ./.github/actions/setup
Expand Down Expand Up @@ -122,11 +142,12 @@ jobs:
build-ios:
runs-on: macos-14
timeout-minutes: 30
env:
TURBO_CACHE_DIR: .turbo/ios
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup
uses: ./.github/actions/setup
Expand Down
57 changes: 41 additions & 16 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ This project follows
- [git](https://git-scm.com) (used for source version control).
- An IDE such as [Android Studio](https://developer.android.com/studio) or [Visual Studio Code](https://code.visualstudio.com/).
- [addlicense](https://github.com/google/addlicense)
- [google-java-format](https://github.com/google/google-java-format) (used to format Java code).
- [clang-format v18](https://clang.llvm.org/docs/ClangFormat.html) (used to format Objective-C code).

## 2. Forking & cloning the repository

Expand All @@ -44,22 +46,6 @@ This project follows
fetch from the master repository, not your clone, when running `git fetch`
et al.)

## 3. Test your changes

- Make sure to test your changes before sending them for review. To do so, update and run the [Sample app](./example/) at `./example`.

### Code reviews

All submissions, including submissions by project members, require review. We
use GitHub pull requests for this purpose. Consult
[GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
information on using pull requests.

Please peruse the
[Typescript style guide](https://google.github.io/styleguide/tsguide.html), [Java style guide](https://google.github.io/styleguide/javaguide.html), and [Objective-C style guide](https://google.github.io/styleguide/objcguide.html) before
working on anything non-trivial. These guidelines are intended to
keep the code consistent and avoid common pitfalls.

#### Create branch

1. `git fetch upstream`
Expand All @@ -84,3 +70,42 @@ keep the code consistent and avoid common pitfalls.
1. `git pull-request` (if you are using [Hub](http://github.com/github/hub/)) or
go to `https://github.com/googlemaps/react-native-navigation-sdk` and click the
"Compare & pull request" button

## 3. Test your changes

Make sure to test your changes before sending them for review. To do so, update and run the [Sample app](./example/) at `./example`.

## 4. Code Formatting

### Objective-C and Java Code Formatting

This project enforces code formatting for Objective-C and Java files to follow Google's style guidelines. The formatting is automatically checked before commits and during continuous integration (CI) using Lefthook and GitHub Actions.

#### Running Formatters Locally

Before committing your changes, you should run the formatters manually to ensure your code adheres to the required style:

**Objective-C:**
```bash
./scripts/format-objc.sh
```
This script will format all Objective-C files under the /ios and /example/ios directories according to Google's Objective-C style guide.

**Java:**
```bash
./scripts/format-java.sh
```
This script will format all Java files under the /android and /example/android directories according to Google's Java style guide.


## 5. Code reviews

All submissions, including submissions by project members, require review. We
use GitHub pull requests for this purpose. Consult
[GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
information on using pull requests.

Please peruse the
[Typescript style guide](https://google.github.io/styleguide/tsguide.html), [Java style guide](https://google.github.io/styleguide/javaguide.html), and [Objective-C style guide](https://google.github.io/styleguide/objcguide.html) before
working on anything non-trivial. These guidelines are intended to
keep the code consistent and avoid common pitfalls.
7 changes: 7 additions & 0 deletions lefthook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@
pre-commit:
parallel: true
commands:
format-objc:
runner: sh
run: ./scripts/format-objc.sh --check
format-java:
runner: sh
run: ./scripts/format-java.sh --check
license-check:
runner: sh
run: ./scripts/addlicense.sh --check
lint:
glob: '*.{js,ts,jsx,tsx}'
Expand Down
4 changes: 2 additions & 2 deletions scripts/addlicense.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/bin/sh
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -12,7 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.


addlicense -f header_template.txt $@ \
--ignore "**/Pods/**" \
--ignore "**/node_modules/**" \
Expand All @@ -24,4 +24,4 @@ addlicense -f header_template.txt $@ \
--ignore "lib/**" \
--ignore "coverage/**" \
--ignore ".yarn/**" \
.
.
22 changes: 22 additions & 0 deletions scripts/format-java.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Script to format or check formatting for Java files in /android and /example/android

if [ "$1" = "--check" ]; then
find android/src example/android/app/src -name "*.java" | xargs google-java-format --dry-run --set-exit-if-changed
else
find android/src example/android/app/src -name "*.java" | xargs google-java-format -i
fi
22 changes: 22 additions & 0 deletions scripts/format-objc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Script to format or check formatting for Objective-C files in /ios and /example/ios

if [ "$1" = "--check" ]; then
find ios example/ios/SampleApp -name "*.m" -o -name "*.h" | xargs clang-format -style=Google --dry-run -Werror
else
find ios example/ios/SampleApp -name "*.m" -o -name "*.h" | xargs clang-format -style=Google -i
fi

0 comments on commit c61a6a5

Please sign in to comment.