[Tarantool-patches] [PATCH v2] tools: fix luacheck invocation in different cases
Alexander Turenko
alexander.turenko at tarantool.org
Thu Feb 25 19:35:52 MSK 2021
> > +if (BINARY_DIR_INSIDE_SOURCE_DIR)
>
> extra whitespace after "if"
To be honest, it was always unclear for me, which style is right and I
just tried to be consistent with the surrounding code.
For CMakeLists.txt (this file, on master):
| $ grep '\bif(' CMakeLists.txt | wc -l
| 10
| $ grep '\bif (' CMakeLists.txt | wc -l
| 22
For tarantool at whole:
| $ find . -name CMakeLists.txt -not -path '*third_party*' -or -name '*.cmake' -not -path '*third_party*' -print | xargs -I {} grep '\bif(' {} | wc -l
| 74
| $ find . -name CMakeLists.txt -not -path '*third_party*' -or -name '*.cmake' -not -path '*third_party*' -print | xargs -I {} grep '\bif (' {} | wc -l
| 163
For CMake built-in modules:
| $ find /usr/share/cmake/Modules -name '*.cmake' -print | xargs -I {} grep '\bif(' {} | wc -l
| 5752
| $ find /usr/share/cmake/Modules -name '*.cmake' -print | xargs -I {} grep '\bif (' {} | wc -l
| 1492
What the world think:
* CMake follows `if()` style in its docs ([1]).
* WebKit agreed on using `if ()` ([2]).
* cmakelint ([3]) requires `if()`.
* polysquare-cmake-linter ([4]) requires `if ()`.
* cmake-lint from cmake_format ([5]) does not complain about any variant
by default, but the default config has the
`separate_ctrl_name_with_space` option (False). Bug?
(JFYI: CMake autoformatter / linter issue: [6].)
If we'll attempt to apply some common sense:
1. `if()` is consistent with `else()` and `endif()`.
2. `if ()` looks usual for a C developer (visual differentiation of
control flow constructions from function calls).
So, to be honest, I still don't know. There is no general rule neither
in tarantool, nor in the world. There is no good choice, because of the
language syntax.
My personal preference is `if ()`, because it differentiates control
flow constructions from macro / function calls (that's usual in C).
[1]: https://cmake.org/cmake/help/latest/command/if.html
[2]: http://trac.webkit.org/changeset/136790/webkit
[3]: https://github.com/cmake-lint/cmake-lint
[4]: https://github.com/polysquare/polysquare-cmake-linter
[5]: https://github.com/cheshirekow/cmake_format
[6]: https://gitlab.kitware.com/cmake/cmake/-/issues/17441
More information about the Tarantool-patches
mailing list