Skip to content

Commit 1ba5159

Browse files
authored
Added formatting checks for C/C++ and python code (#1348)
1 parent f3d072d commit 1ba5159

File tree

59 files changed

+317
-333
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+317
-333
lines changed

.bazelci/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,6 @@ tasks:
252252
test_targets: *min_supported_targets
253253

254254
buildifier:
255-
version: "6.1.0"
255+
version: "7.3.1"
256256
# keep this argument in sync with .pre-commit-config.yaml
257257
warnings: "all"

.clang-format

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
BasedOnStyle: Google
3+
IndentWidth: 4
4+
...

.github/workflows/formatting.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Formatting
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
types:
9+
- opened
10+
- synchronize
11+
12+
jobs:
13+
code-format-checks:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v2
17+
- uses: DoozyX/clang-format-lint-action@v0.14
18+
with:
19+
source: '.'
20+
extensions: 'h,c,cc,cpp,proto,java'
21+
clangFormatVersion: 14
22+
- name: Set up Python
23+
uses: actions/setup-python@v2
24+
with:
25+
python-version: 3.11
26+
- name: Install dependencies
27+
run: |
28+
pip install 'black==24.10.0' 'isort==5.13.2'
29+
- name: Run black
30+
run: |
31+
python -m black --check --diff ./
32+
- name: Run isort
33+
run: |
34+
python -m isort --profile=black --check-only ./

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
# CMake
3939
cmake-build-*/
4040

41+
# Python
42+
/*venv/
43+
4144
# Mongo Explorer plugin
4245
.idea/**/mongoSettings.xml
4346

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ repos:
2121
- id: check-yaml
2222

2323
- repo: https://github.com/keith/pre-commit-buildifier
24-
rev: 6.1.0.1
24+
rev: 7.3.1.1
2525
hooks:
2626
- id: buildifier
2727
args: &args
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
#include <jni.h>
2+
23
#include <string>
34

4-
extern "C"
5-
JNIEXPORT jstring
5+
extern "C" JNIEXPORT jstring
66

7-
JNICALL
8-
Java_com_example_android_bazel_MainActivity_stringFromJNI(
9-
JNIEnv *env,
10-
jobject /* this */) {
7+
JNICALL
8+
Java_com_example_android_bazel_MainActivity_stringFromJNI(
9+
JNIEnv *env, jobject /* this */) {
1110
std::string hello = "Hello from C++";
1211
return env->NewStringUTF(hello.c_str());
1312
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#include <stdio.h>
2+
23
#include "hello.h"
34

4-
int main(int argc, char* argv[])
5-
{
6-
hello_func();
7-
return 0;
5+
int main(int argc, char* argv[]) {
6+
hello_func();
7+
return 0;
88
}

examples/cmake_android/java/com/example/android/bazel/MainActivity.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package examples.cmake_android.java.com.example.android.bazel;
22

3-
import android.support.v7.app.AppCompatActivity;
43
import android.os.Bundle;
4+
import android.support.v7.app.AppCompatActivity;
55
import android.widget.TextView;
66

77
public class MainActivity extends AppCompatActivity {
8-
98
static {
109
System.loadLibrary("app");
1110
}
Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
// Copied from https://gist.github.com/arq5x/5315739 for test purposes
22

3+
#include <assert.h>
34
#include <stdio.h>
45
#include <string.h> // for strlen
5-
#include <assert.h>
6+
67
#include "zlib.h"
78

8-
// adapted from: http://stackoverflow.com/questions/7540259/deflate-and-inflate-zlib-h-in-c
9-
int main(int argc, char* argv[])
10-
{
9+
// adapted from:
10+
// http://stackoverflow.com/questions/7540259/deflate-and-inflate-zlib-h-in-c
11+
int main(int argc, char *argv[]) {
1112
// original string len = 36
1213
char a[50] = "Hello Hello Hello Hello Hello Hello!";
1314

@@ -17,11 +18,9 @@ int main(int argc, char* argv[])
1718
// placeholder for the UNcompressed (inflated) version of "b"
1819
char c[50];
1920

20-
2121
printf("Uncompressed size is: %lu\n", strlen(a));
2222
printf("Uncompressed string is: %s\n", a);
2323

24-
2524
printf("\n----------\n\n");
2625

2726
// STEP 1.
@@ -33,10 +32,11 @@ int main(int argc, char* argv[])
3332
defstream.zfree = Z_NULL;
3433
defstream.opaque = Z_NULL;
3534
// setup "a" as the input and "b" as the compressed output
36-
defstream.avail_in = (uInt)strlen(a)+1; // size of input, string + terminator
37-
defstream.next_in = (Bytef *)a; // input char array
38-
defstream.avail_out = (uInt)sizeof(b); // size of output
39-
defstream.next_out = (Bytef *)b; // output char array
35+
defstream.avail_in =
36+
(uInt)strlen(a) + 1; // size of input, string + terminator
37+
defstream.next_in = (Bytef *)a; // input char array
38+
defstream.avail_out = (uInt)sizeof(b); // size of output
39+
defstream.next_out = (Bytef *)b; // output char array
4040

4141
// the actual compression work.
4242
deflateInit(&defstream, Z_BEST_COMPRESSION);
@@ -47,10 +47,8 @@ int main(int argc, char* argv[])
4747
printf("Compressed size is: %lu\n", strlen(b));
4848
printf("Compressed string is: %s\n", b);
4949

50-
5150
printf("\n----------\n\n");
5251

53-
5452
// STEP 2.
5553
// inflate b into c
5654
// zlib struct
@@ -59,10 +57,11 @@ int main(int argc, char* argv[])
5957
infstream.zfree = Z_NULL;
6058
infstream.opaque = Z_NULL;
6159
// setup "b" as the input and "c" as the compressed output
62-
infstream.avail_in = (uInt)((char*)defstream.next_out - b); // size of input
63-
infstream.next_in = (Bytef *)b; // input char array
64-
infstream.avail_out = (uInt)sizeof(c); // size of output
65-
infstream.next_out = (Bytef *)c; // output char array
60+
infstream.avail_in =
61+
(uInt)((char *)defstream.next_out - b); // size of input
62+
infstream.next_in = (Bytef *)b; // input char array
63+
infstream.avail_out = (uInt)sizeof(c); // size of output
64+
infstream.next_out = (Bytef *)c; // output char array
6665

6766
// the actual DE-compression work.
6867
inflateInit(&infstream);
@@ -72,9 +71,8 @@ int main(int argc, char* argv[])
7271
printf("Uncompressed size is: %lu\n", strlen(c));
7372
printf("Uncompressed string is: %s\n", c);
7473

75-
7674
// make sure uncompressed is exactly equal to original.
77-
assert(strcmp(a,c)==0);
75+
assert(strcmp(a, c) == 0);
7876

7977
return 0;
8078
}

examples/cmake_crosstool/hello.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@
1818
#include <iostream>
1919

2020
int main(int argc, char* argv[]) {
21-
std::cout << "Hello! sqrt(time) = " << std::sqrt(time(NULL)) << std::endl;
22-
return EXIT_SUCCESS;
21+
std::cout << "Hello! sqrt(time) = " << std::sqrt(time(NULL)) << std::endl;
22+
return EXIT_SUCCESS;
2323
}

0 commit comments

Comments
 (0)