clang-tidy: propose a base .clang-tidy
When there is a specific recommendation, it is taken from Cpp Core
guidelines [1] or clang-tidy defaults.
- readability-function-size.LineThreshold
was chosen to support
[ F.3 Keep functions short and simple ]
They recommend 60 lines to flag functions which would not fit on a
screen.
- readability-function-size.ParameterThreshold
was chosen to support
[ F.2: A function should perform a single logical operation ]
They recommend to be suspicious of functions with 7 or more
parameters.
- readability-function-cognitive-complexity.Threshold
was chosen to support
[ F.3: Keep functions short and simple ]
They recommend a cyclomatic complexity of 10 or less.
However, cyclomatic complexity is not implemented in clang-tidy,
therefore going with the clang-tidy default.
What is the goal of this change?
- making it easier for people to read the code.
- making it easier to perform refactorings without breaking stuff
- making it easier to review changes
Who will be responsible for making the required changes?
- Everyone who is interested. The plan is to atleast get some of the
most important pieces into a more readable state. Examples are
dbus-sensors, entity-manager, x86-power-control.
- The plan is to enable some of these checks as errors once a repo
comes into compliance. After that, contributors will be responsible
to ensure their changes meet these checks.
Tradeoffs:
- There might be more code overall, as functions will be smaller.
- People might be required to do another (refactoring) iteration on
their changes if some of these checks become hard errors.
- Refactoring code to meet these checks might introduce bugs.
[1] https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines
Change-Id: Icbdd55d2f672037a57d8ed08d52b20427e9e1e4f
Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
diff --git a/style/cpp/.clang-tidy b/style/cpp/.clang-tidy
new file mode 100644
index 0000000..16fff78
--- /dev/null
+++ b/style/cpp/.clang-tidy
@@ -0,0 +1,17 @@
+Checks: '
+ -*,
+ readability-function-size,
+ readability-function-cognitive-complexity
+'
+CheckOptions:
+ - { key: readability-function-size.LineThreshold, value: 60 } # [1]
+ - { key: readability-function-size.ParameterThreshold, value: 6 } # [2]
+ - { key: readability-function-cognitive-complexity.Threshold, value: 25 } # [3]
+
+# [1] https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#f3-keep-functions-short-and-simple
+# [2] https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#f2-a-function-should-perform-a-single-logical-operation
+# [3] https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#f3-keep-functions-short-and-simple
+# However cognitive complexity != cyclomatic complexity. Therefore using the clang-tidy default value,
+# as cyclomatic complexity seems to not be implemented in clang-tidy.
+
+# [1],[2],[3] do not have to be enforced or applied project-wide yet.