Skip to content

Add Clang tidy naming conventions #152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
342 changes: 160 additions & 182 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,188 +1,166 @@
# taken from https://github.com/cpp-linter/cpp-linter-action/blob/main/demo/.clang-tidy
---
Checks: "clang-diagnostic-*,clang-analyzer-*,bugprone-*,misc-*,performance-*,readability-*,portability-*,modernize-*,cppcoreguidelines-*,-modernize-use-trailing-return-type,-readability-named-parameter,-readability-identifier-length,-misc-include-cleaner,-cppcoreguidelines-avoid-magic-numbers,-readability-magic-numbers,-misc-non-private-member-variables-in-classes,-cppcoreguidelines-non-private-member-variables-in-classes"
Checks: "clang-diagnostic-*,clang-analyzer-*,bugprone-*,misc-*,performance-*,readability-*,portability-*,modernize-*,cppcoreguidelines-*,google-*,llvm-*,cert-*,-modernize-use-trailing-return-type,-bugprone-argument-comment,-misc-include-cleaner,-cppcoreguidelines-avoid-magic-numbers,-readability-magic-numbers,-readability-avoid-nested-conditional-operator,-llvm-namespace-comment,-llvm-header-guard"
WarningsAsErrors: ""
HeaderFilterRegex: "oopetris/src/.*"
AnalyzeTemporaryDtors: false
FormatStyle: "file"
CheckOptions:
- key: bugprone-argument-comment.CommentBoolLiterals
value: "0"
- key: bugprone-argument-comment.CommentCharacterLiterals
value: "0"
- key: bugprone-argument-comment.CommentFloatLiterals
value: "0"
- key: bugprone-argument-comment.CommentIntegerLiterals
value: "0"
- key: bugprone-argument-comment.CommentNullPtrs
value: "0"
- key: bugprone-argument-comment.CommentStringLiterals
value: "0"
- key: bugprone-argument-comment.CommentUserDefinedLiterals
value: "0"
- key: bugprone-argument-comment.IgnoreSingleArgument
value: "0"
- key: bugprone-argument-comment.StrictMode
value: "0"
- key: bugprone-assert-side-effect.AssertMacros
value: assert
- key: bugprone-assert-side-effect.CheckFunctionCalls
value: "0"
- key: bugprone-dangling-handle.HandleClasses
value: "std::basic_string_view;std::experimental::basic_string_view"
- key: bugprone-dynamic-static-initializers.HeaderFileExtensions
value: ",h,hh,hpp,hxx"
- key: bugprone-exception-escape.FunctionsThatShouldNotThrow
value: ""
- key: bugprone-exception-escape.IgnoredExceptions
value: ""
- key: bugprone-misplaced-widening-cast.CheckImplicitCasts
value: "0"
- key: bugprone-not-null-terminated-result.WantToUseSafeFunctions
value: "1"
- key: bugprone-signed-char-misuse.CharTypdefsToIgnore
value: ""
- key: bugprone-sizeof-expression.WarnOnSizeOfCompareToConstant
value: "1"
- key: bugprone-sizeof-expression.WarnOnSizeOfConstant
value: "1"
- key: bugprone-sizeof-expression.WarnOnSizeOfIntegerExpression
value: "0"
- key: bugprone-sizeof-expression.WarnOnSizeOfThis
value: "1"
- key: bugprone-string-constructor.LargeLengthThreshold
value: "8388608"
- key: bugprone-string-constructor.WarnOnLargeLength
value: "1"
- key: bugprone-suspicious-enum-usage.StrictMode
value: "0"
- key: bugprone-suspicious-missing-comma.MaxConcatenatedTokens
value: "5"
- key: bugprone-suspicious-missing-comma.RatioThreshold
value: "0.200000"
- key: bugprone-suspicious-missing-comma.SizeThreshold
value: "5"
- key: bugprone-suspicious-string-compare.StringCompareLikeFunctions
value: ""
- key: bugprone-suspicious-string-compare.WarnOnImplicitComparison
value: "1"
- key: bugprone-suspicious-string-compare.WarnOnLogicalNotComparison
value: "0"
- key: bugprone-too-small-loop-variable.MagnitudeBitsUpperLimit
value: "16"
- key: bugprone-unhandled-self-assignment.WarnOnlyIfThisHasSuspiciousField
value: "1"
- key: bugprone-unused-return-value.CheckedFunctions
value: "::std::async;::std::launder;::std::remove;::std::remove_if;::std::unique;::std::unique_ptr::release;::std::basic_string::empty;::std::vector::empty"
- key: cert-dcl16-c.NewSuffixes
value: "L;LL;LU;LLU"
- key: cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField
value: "0"
- key: cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors
value: "1"
- key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
value: "1"
- key: google-readability-braces-around-statements.ShortStatementLines
value: "1"
- key: google-readability-function-size.StatementThreshold
value: "800"
- key: google-readability-namespace-comments.ShortNamespaceLines
value: "10"
- key: google-readability-namespace-comments.SpacesBeforeComments
value: "2"
- key: misc-definitions-in-headers.HeaderFileExtensions
value: ",h,hh,hpp,hxx"
- key: misc-definitions-in-headers.UseHeaderFileExtension
value: "1"
- key: misc-throw-by-value-catch-by-reference.CheckThrowTemporaries
value: "1"
- key: misc-unused-parameters.StrictMode
value: "0"
- key: modernize-loop-convert.MaxCopySize
value: "16"
- key: modernize-loop-convert.MinConfidence
value: reasonable
- key: modernize-use-trailing-return-type
value: "false"
- key: modernize-loop-convert.NamingStyle
value: CamelCase
- key: modernize-pass-by-value.IncludeStyle
value: llvm
- key: modernize-replace-auto-ptr.IncludeStyle
value: llvm
- key: modernize-use-nullptr.NullMacros
value: "NULL"
- key: performance-faster-string-find.StringLikeClasses
value: "std::basic_string"
- key: performance-for-range-copy.AllowedTypes
value: ""
- key: performance-for-range-copy.WarnOnAllAutoCopies
value: "0"
- key: performance-inefficient-string-concatenation.StrictMode
value: "0"
- key: performance-inefficient-vector-operation.EnableProto
value: "0"
- key: performance-inefficient-vector-operation.VectorLikeClasses
value: "::std::vector"
- key: performance-move-const-arg.CheckTriviallyCopyableMove
value: "1"
- key: performance-move-constructor-init.IncludeStyle
value: llvm
- key: performance-no-automatic-move.AllowedTypes
value: ""
- key: performance-type-promotion-in-math-fn.IncludeStyle
value: llvm
- key: performance-unnecessary-copy-initialization.AllowedTypes
value: ""
- key: performance-unnecessary-value-param.AllowedTypes
value: ""
- key: performance-unnecessary-value-param.IncludeStyle
value: llvm
- key: readability-braces-around-statements.ShortStatementLines
value: "0"
- key: readability-else-after-return.WarnOnUnfixable
value: "1"
- key: readability-function-size.BranchThreshold
value: "4294967295"
- key: readability-function-size.LineThreshold
value: "4294967295"
- key: readability-function-size.NestingThreshold
value: "4294967295"
- key: readability-function-size.ParameterThreshold
value: "4294967295"
- key: readability-function-size.StatementThreshold
value: "800"
- key: readability-function-size.VariableThreshold
value: "4294967295"
- key: readability-identifier-naming.IgnoreFailedSplit
value: "0"
- key: readability-implicit-bool-conversion.AllowIntegerConditions
value: "0"
- key: readability-implicit-bool-conversion.AllowPointerConditions
value: "0"
- key: readability-inconsistent-declaration-parameter-name.IgnoreMacros
value: "1"
- key: readability-inconsistent-declaration-parameter-name.Strict
value: "0"
- key: readability-magic-numbers.IgnoredFloatingPointValues
value: "1.0;100.0;"
- key: readability-magic-numbers.IgnoredIntegerValues
value: "1;2;3;4;"
- key: readability-redundant-member-init.IgnoreBaseInCopyConstructors
value: "0"
- key: readability-redundant-smartptr-get.IgnoreMacros
value: "1"
- key: readability-redundant-string-init.StringNames
value: "::std::basic_string"
- key: readability-simplify-boolean-expr.ChainedConditionalAssignment
value: "0"
- key: readability-simplify-boolean-expr.ChainedConditionalReturn
value: "0"
- key: readability-simplify-subscript-expr.Types
value: "::std::basic_string;::std::basic_string_view;::std::vector;::std::array"
- key: readability-static-accessed-through-instance.NameSpecifierNestingThreshold
value: "3"
- key: readability-uppercase-literal-suffix.IgnoreMacros
value: "1"
- key: readability-uppercase-literal-suffix.NewSuffixes
value: ""
## NAMING CONVENTION SECTION
- key: readability-identifier-naming.AbstractClassCase
value: "CamelCase"
- key: readability-identifier-naming.AggressiveDependentMemberLookup
value: true
- key: readability-identifier-naming.CheckAnonFieldInParent
value: false
- key: readability-identifier-naming.ClassCase
value: "CamelCase"
- key: readability-identifier-naming.ClassConstantCase
value: "lower_case"
- key: readability-identifier-naming.ClassConstantPrefix
value: "c_"
- key: readability-identifier-naming.ClassMemberCase
value: "lower_case"
- key: readability-identifier-naming.ClassMemberPrefix
value: "m_"
- key: readability-identifier-naming.ClassMethodCase
value: "lower_case"
- key: readability-identifier-naming.ConceptCase
value: "CamelCase"
- key: readability-identifier-naming.ConstantCase
value: "lower_case"
- key: readability-identifier-naming.ConstantMemberCase
value: "lower_case"
- key: readability-identifier-naming.ConstantParameterCase
value: "lower_case"
- key: readability-identifier-naming.ConstantPointerParameterCase
value: "lower_case"
- key: readability-identifier-naming.ConstexprFunctionCase
value: "lower_case"
- key: readability-identifier-naming.ConstexprMethodCase
value: "lower_case"
- key: readability-identifier-naming.ConstexprVariableCase
value: "lower_case"
- key: readability-identifier-naming.EnumCase
value: "CamelCase"
- key: readability-identifier-naming.EnumConstantCase
value: "CamelCase"
- key: readability-identifier-naming.FunctionCase
value: "lower_case"
- key: readability-identifier-naming.GlobalConstantCase
value: "lower_case"
- key: readability-identifier-naming.GlobalConstantPointerCase
value: "lower_case"
- key: readability-identifier-naming.GlobalFunctionCase
value: "lower_case"
- key: readability-identifier-naming.GlobalFunctionIgnoredRegexp
value: "(PrintTo)" ## for gtest
- key: readability-identifier-naming.GlobalPointerCase
value: "lower_case"
- key: readability-identifier-naming.GlobalVariableCase
value: "lower_case"
- key: readability-identifier-naming.GlobalVariablePrefix
value: "g_"
- key: readability-identifier-naming.LocalConstantCase
value: "lower_case"
- key: readability-identifier-naming.LocalConstantPointerCase
value: "lower_case"
- key: readability-identifier-naming.LocalPointerCase
value: "lower_case"
- key: readability-identifier-naming.LocalVariableCase
value: "lower_case"
- key: readability-identifier-naming.MacroDefinitionCase
value: "UPPER_CASE"
- key: readability-identifier-naming.MemberCase
value: "lower_case"
- key: readability-identifier-naming.MemberPrefix
value: "m_"
- key: readability-identifier-naming.MethodCase
value: "lower_case"
- key: readability-identifier-naming.NamespaceCase
value: "lower_case"
- key: readability-identifier-naming.ParameterCase
value: "lower_case"
- key: readability-identifier-naming.ParameterPackCase
value: "lower_case"
- key: readability-identifier-naming.PointerParameterCase
value: "lower_case"
- key: readability-identifier-naming.PrivateMemberCase
value: "lower_case"
- key: readability-identifier-naming.PrivateMemberPrefix
value: "m_"
- key: readability-identifier-naming.PrivateMethodCase
value: "lower_case"
- key: readability-identifier-naming.ProtectedMemberCase
value: "lower_case"
- key: readability-identifier-naming.ProtectedMemberPrefix
value: "m_"
- key: readability-identifier-naming.ProtectedMethodCase
value: "lower_case"
- key: readability-identifier-naming.PublicMemberCase
value: "lower_case"
- key: readability-identifier-naming.PublicMemberPrefix
value: "" # NO PREFIX
- key: readability-identifier-naming.PublicMethodCase
value: "lower_case"
- key: readability-identifier-naming.ScopedEnumConstantCase
value: "CamelCase"
- key: readability-identifier-naming.StaticConstantCase
value: "lower_case"
- key: readability-identifier-naming.StaticConstantPrefix
value: "s_"
- key: readability-identifier-naming.StaticVariableCase
value: "lower_case"
- key: readability-identifier-naming.StaticVariablePrefix
value: "s_"
- key: readability-identifier-naming.StructCase
value: "CamelCase"
- key: readability-identifier-naming.TemplateParameterCase
value: "CamelCase"
- key: readability-identifier-naming.TemplateTemplateParameterCase
value: "CamelCase"
- key: readability-identifier-naming.TypeAliasCase
value: "CamelCase"
- key: readability-identifier-naming.TypedefCase
value: "CamelCase"
- key: readability-identifier-naming.TypeTemplateParameterCase
value: "CamelCase"
- key: readability-identifier-naming.UnionCase
value: "CamelCase"
- key: readability-identifier-naming.ValueTemplateParameterCase
value: "lower_case"
- key: readability-identifier-naming.VariableCase
value: "lower_case"
- key: readability-identifier-naming.VirtualMethodCase
value: "lower_case"

# some needed settings, that are non default
- key: bugprone-misplaced-widening-cast.CheckImplicitCasts
value: true
- key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
value: true
- key: bugprone-suspicious-enum-usage.StrictMode
value: true
- key: bugprone-suspicious-string-compare.WarnOnLogicalNotComparison
value: true
- key: bugprone-unhandled-self-assignment.WarnOnlyIfThisHasSuspiciousField
value: true
- key: misc-unused-parameters.StrictMode
value: true
- key: performance-inefficient-string-concatenation.StrictMode
value: true
- key: readability-inconsistent-declaration-parameter-name.Strict
value: true

## special things, that have special values
- key: readability-identifier-length.IgnoredVariableNames
value: "(os)" # ostream
- key: readability-identifier-length.IgnoredParameterNames
value: "^[n]$"
- key: readability-identifier-length.MinimumLoopCounterNameLength
value: 1
- key: readability-identifier-length.MinimumExceptionNameLength
value: 5
- key: readability-function-cognitive-complexity.Threshold
value: 50
- key: bugprone-assert-side-effect.AssertMacros
value: "assert"
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ project(
'buildtype': 'debug',
'optimization': '3',
'strip': true,
'cpp_std': ['c++23', 'c++latest', 'vc++latest', 'c++20'],
'cpp_std': ['c++26', 'c++23', 'c++latest', 'vc++latest'],
'b_ndebug': 'if-release',

},
Expand Down
13 changes: 8 additions & 5 deletions src/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void Application::run() {
const Uint64 current_time = SDL_GetPerformanceCounter();

if (current_time - start_time >= update_time) {
double elapsed = static_cast<double>(current_time - start_time) / count_per_s;
const double elapsed = static_cast<double>(current_time - start_time) / count_per_s;
m_fps_text->set_text(*this, fmt::format("FPS: {:.2f}", static_cast<double>(frame_counter) / elapsed));
start_time = current_time;
frame_counter = 0;
Expand All @@ -100,7 +100,7 @@ void Application::run() {
const auto now = std::chrono::steady_clock::now();
const auto runtime = (now - start_execution_time);
if (runtime < sleep_time) {
//TODO: use SDL_DelayNS in sdl >= 3.0
//TODO(totto): use SDL_DelayNS in sdl >= 3.0
helper::sleep_nanoseconds(sleep_time - runtime);
start_execution_time = std::chrono::steady_clock::now();
} else {
Expand Down Expand Up @@ -190,9 +190,12 @@ void Application::update() {
spdlog::info("pushing back scene {}", raw_push.name);
m_scene_stack.push_back(std::move(raw_push.scene));
},
[this](const scenes::Scene::Switch& switch_) {
spdlog::info("switching to scene {}", magic_enum::enum_name(switch_.target_scene));
auto scene = scenes::create_scene(*this, switch_.target_scene, switch_.layout);
[this](const scenes::Scene::Switch& scene_switch) {
spdlog::info(
"switching to scene {}", magic_enum::enum_name(scene_switch.target_scene)
);
auto scene =
scenes::create_scene(*this, scene_switch.target_scene, scene_switch.layout);

// only clear, after the construction was successful
m_scene_stack.clear();
Expand Down
Loading
Loading