Repository: cossacklabs/themis (language: rust)

Issue:
Fix C coding style
Many of Themis `.c` files have different code style (or no code style at all?). This creates confusion for potential contributors. Let's fix one coding style for all Themis/soter (not imported) `.c` files. My proposal is to use [clang-format](https://clang.llvm.org/docs/ClangFormat.html) tool:
  * discuss and select initial coding style
  * fix it by writing a `.clang-format` and commit it to the repository
  * format Themis `.c` files with it
  * maybe, create a Makefile target, which developers can call to format all Themis/soter sources (in case they add additional files in the future)
  * finally, integrate format validation in CI (basically, fail the CI if code is not properly formatted) to enforce proper coding style for contributions


Discussion / hints:
I think it's a great idea. I think we should try to format using LLVM or Google pre-defined styles first, just to understand how far we are from their code style, then to apply @secumod step-by-step :)
In `clang-format` you can inherit the style and just override parameters you need - that's the best approach IMO. For example, you can define in your `.clang-format` you're using `llvm` style as a baseline, but override indent width (they use 2, but I like 4 for example).

Here's a nice interactive tool to understand what each setting means
https://zed0.co.uk/clang-format-configurator/
Generally I'm fine with `llvm` style, just generally prefer `IndentWidth` to be 4. However, I'll not fight for it, because sometimes 2 is handy: when you have multilevel nested code, you generally have more room for nested levels.
Awesome idea. It's important to investigate the volume of effort to achieve that to prioritize this along other goals we've got for next release. Asking @vixentael or @Lagovas to weigh in with well-investigated opinion on how long will it take to do this.
never worked with this utility and doesn't know how they will work with current code formatting. it can be like one-time run and forget, or run and fix in many places bad readable formatting. if we have time then it will be good. if not, then it's good to start to use it incrementally on changed files in commit
Actually the readability is OK. I just encountered that I needed to refactor includes in main `themis.h` header: the problem was if includes are grouped together without extra newlines, `clang-format` sorts them. In our case, it have put `themis_errors.h` last, so the compiler failed when parsing other headers, because it could not find `themis_status_t` definition.

Fixed it by moving `themis_error.h` higher and adding a newline.

For complete example, see this branch: https://github.com/secumod/themis/tree/clang-format/src/themis

I reformatted files in `src/themis` with `clang-format` default `llvm` style.
It did not break the build it seems: https://circleci.com/gh/secumod/themis/50
vote for pointer on type instead variable name :) (`int* a` instead `int *a`)
exception is case with many variables like `int *a, *b, *c;`
but I think it will be too complicated for automated tool :(
I see you are formatted themis sources and it's great anyway :+1: 
See `PointerAlignment` in https://clang.llvm.org/docs/ClangFormatStyleOptions.html

Fix patch:
diff --git a/.circleci/config.yml b/.circleci/config.yml
index 2170b9dfc..176edcb87 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -20,6 +20,19 @@ jobs:
       # wait for emulator to fully boot before running tests
       - run: timeout 10m /bin/bash -c 'while true; do $ANDROID_HOME/platform-tools/adb wait-for-device logcat -b events -d | grep -i boot_progress_enable_screen && break; date; sleep 3; done'
       - run: ./gradlew --no-daemon --no-parallel --max-workers=2 connectedAndroidTest
+
+  analyze:
+    docker:
+      - image: cossacklabs/build:ubuntu-bionic
+    environment:
+      CLANG_FORMAT: clang-format-7
+      CLANG_TIDY: clang-tidy-7
+    steps:
+      - checkout
+      - run: git submodule update --init
+      - run: make fmt_check ENGINE=boringssl
+      - run: make fmt_check ENGINE=openssl
+
   x86_64:
     docker:
       - image: cossacklabs/android-build:2019.01
@@ -190,6 +203,7 @@ workflows:
   version: 2
   tests:
     jobs:
+      - analyze
       - android
       - x86_64
       - php5


Test patch: