Skip to content

Commit

Permalink
feat: Use clang-format to lint C++ code
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy committed Sep 1, 2023
1 parent d4eb942 commit a1c8479
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 35 deletions.
26 changes: 26 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Config for clang-format version 16

# Standard
BasedOnStyle: llvm
Standard: c++14

# Indentation
IndentWidth: 2
ColumnLimit: 100

# Includes
SortIncludes: true
SortUsingDeclarations: true

# Pointer and reference alignment
PointerAlignment: Left
ReferenceAlignment: Left
ReflowComments: true

# Line breaking options
BreakBeforeBraces: Attach
BreakConstructorInitializers: BeforeColon
AllowShortFunctionsOnASingleLine: Empty
IndentCaseLabels: true
NamespaceIndentation: Inner

35 changes: 0 additions & 35 deletions .github/actions/setup/action.yml

This file was deleted.

36 changes: 36 additions & 0 deletions .github/actions/setup/validate-cpp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Validate C++

on:
push:
branches:
- main
paths:
- '.github/workflows/validate-cpp.yml'
- 'cpp/**'
- 'android/src/main/cpp/**'
- 'ios/**'
pull_request:
paths:
- '.github/workflows/validate-cpp.yml'
- 'cpp/**'
- 'android/src/main/cpp/**'
- 'ios/**'

jobs:
lint:
name: Check clang-format
runs-on: ubuntu-latest
strategy:
matrix:
path:
- 'cpp'
- 'android/src/main/cpp'
- 'ios'
steps:
- uses: actions/checkout@v2
- name: Run clang-format style check
uses: jidicula/clang-format-action@v4.11.0
with:
clang-format-version: '16'
check-path: ${{ matrix.path }}

10 changes: 10 additions & 0 deletions scripts/clang-format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

if which clang-format >/dev/null; then
find cpp ios android/src/main/cpp -type f \( -name "*.h" -o -name "*.cpp" -o -name "*.m" -o -name "*.mm" \) -print0 | while read -d $'\0' file; do
echo "-> cpp-lint $file"
clang-format -i "$file"
done
else
echo "warning: clang-format not installed, download from https://clang.llvm.org/docs/ClangFormat.html (or run brew install clang-format)"
fi

0 comments on commit a1c8479

Please sign in to comment.