diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..b10f47b --- /dev/null +++ b/.clang-format @@ -0,0 +1,22 @@ +BasedOnStyle: Google +IndentWidth: 4 +NamespaceIndentation: All +IndentAccessModifiers: false +ColumnLimit: 0 # Sin limite de longitud de linea +BreakBeforeBraces: Attach # Llaves en la misma linea +AllowShortIfStatementsOnASingleLine: true +AllowShortBlocksOnASingleLine: true +AllowShortFunctionsOnASingleLine: All +AlignOperands: DontAlign +AlignAfterOpenBracket: DontAlign +BinPackArguments: false +BinPackParameters: false +ContinuationIndentWidth: 4 +ConstructorInitializerIndentWidth: 4 +IndentWrappedFunctionNames: false +Cpp11BracedListStyle: true +BreakConstructorInitializers: BeforeColon +AllowAllConstructorInitializersOnNextLine: false +PackConstructorInitializers: Never +AllowAllArgumentsOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..ed370f3 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,84 @@ +Checks: + - readability-* + - modernize-* + - performance-* + - bugprone-unchecked-optional-access + - bugprone-sizeof-expression + - bugprone-suspicious-missing-comma + - bugprone-suspicious-index + - bugprone-undefined-memory-manipulation + - bugprone-use-after-move + - bugprone-out-of-bound-access + - -readability-identifier-length + - -readability-magic-numbers + - -bugprone-narrowing-conversions + - -performance-enum-size + - -performance-inefficient-string-concatenation + - -bugprone-integer-division + - -bugprone-easily-swappable-parameters + - -modernize-avoid-c-arrays,-warnings-as-errors + +WarningsAsErrors: '*' +# Excluye jail_audio.hpp, stb_image.h y stb_vorbis.c del analisis +HeaderFilterRegex: 'source/(?!jail_audio\.hpp|stb_image\.h|stb_vorbis\.c).*' +FormatStyle: file + +CheckOptions: + # Variables locales en snake_case + - { key: readability-identifier-naming.VariableCase, value: lower_case } + + # Miembros privados en snake_case con sufijo _ + - { key: readability-identifier-naming.PrivateMemberCase, value: lower_case } + - { key: readability-identifier-naming.PrivateMemberSuffix, value: _ } + + # Miembros protegidos en snake_case con sufijo _ + - { key: readability-identifier-naming.ProtectedMemberCase, value: lower_case } + - { key: readability-identifier-naming.ProtectedMemberSuffix, value: _ } + + # Miembros publicos en snake_case (sin sufijo) + - { key: readability-identifier-naming.PublicMemberCase, value: lower_case } + + # Namespaces en CamelCase + - { key: readability-identifier-naming.NamespaceCase, value: CamelCase } + + # Variables estaticas privadas como miembros privados + - { key: readability-identifier-naming.StaticVariableCase, value: lower_case } + - { key: readability-identifier-naming.StaticVariableSuffix, value: _ } + + # Constantes estaticas sin sufijo + - { key: readability-identifier-naming.StaticConstantCase, value: UPPER_CASE } + + # Constantes globales en UPPER_CASE + - { key: readability-identifier-naming.GlobalConstantCase, value: UPPER_CASE } + + # Variables constexpr globales en UPPER_CASE + - { key: readability-identifier-naming.ConstexprVariableCase, value: UPPER_CASE } + + # Constantes locales en UPPER_CASE + - { key: readability-identifier-naming.LocalConstantCase, value: UPPER_CASE } + + # Constexpr miembros en UPPER_CASE (sin sufijo) + - { key: readability-identifier-naming.ConstexprMemberCase, value: UPPER_CASE } + + # Constexpr miembros privados/protegidos con sufijo _ + - { key: readability-identifier-naming.ConstexprMethodCase, value: UPPER_CASE } + + # Clases, structs y enums en CamelCase + - { key: readability-identifier-naming.ClassCase, value: CamelCase } + - { key: readability-identifier-naming.StructCase, value: CamelCase } + - { key: readability-identifier-naming.EnumCase, value: CamelCase } + + # Valores de enums en UPPER_CASE + - { key: readability-identifier-naming.EnumConstantCase, value: UPPER_CASE } + + # Metodos en camelBack (sin sufijos) + - { key: readability-identifier-naming.MethodCase, value: camelBack } + - { key: readability-identifier-naming.PrivateMethodCase, value: camelBack } + - { key: readability-identifier-naming.ProtectedMethodCase, value: camelBack } + - { key: readability-identifier-naming.PublicMethodCase, value: camelBack } + + # Funciones en camelBack + - { key: readability-identifier-naming.FunctionCase, value: camelBack } + + # Parametros en lower_case + - { key: readability-identifier-naming.ParameterCase, value: lower_case } diff --git a/CMakeLists.txt b/CMakeLists.txt index 6e9cc0e..290c62e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,3 +70,72 @@ elseif(UNIX AND NOT APPLE) target_compile_definitions(${PROJECT_NAME} PRIVATE LINUX_BUILD) target_link_options(${PROJECT_NAME} PRIVATE -Wl,--gc-sections) endif() + +# ============================================================================== +# STATIC ANALYSIS TARGETS +# ============================================================================== + +find_program(CLANG_TIDY_EXE NAMES clang-tidy) +find_program(CLANG_FORMAT_EXE NAMES clang-format) + +# Recopilar todos los archivos fuente para analisis +file(GLOB_RECURSE ALL_SOURCE_FILES + "${CMAKE_SOURCE_DIR}/source/*.cpp" + "${CMAKE_SOURCE_DIR}/source/*.h" +) + +# Excluir stb_image.h y stb_vorbis.c del analisis +set(CLANG_TIDY_SOURCES ${ALL_SOURCE_FILES}) +list(FILTER CLANG_TIDY_SOURCES EXCLUDE REGEX ".*stb_image\\.h$") +list(FILTER CLANG_TIDY_SOURCES EXCLUDE REGEX ".*stb_vorbis\\.c$") +list(FILTER CLANG_TIDY_SOURCES EXCLUDE REGEX ".*jail_audio\\.hpp$") + +# Excluir stb y jail_audio del formateo tambien +set(FORMAT_SOURCES ${ALL_SOURCE_FILES}) +list(FILTER FORMAT_SOURCES EXCLUDE REGEX ".*stb_image\\.h$") +list(FILTER FORMAT_SOURCES EXCLUDE REGEX ".*stb_vorbis\\.c$") +list(FILTER FORMAT_SOURCES EXCLUDE REGEX ".*jail_audio\\.hpp$") + +# Targets de clang-tidy +if(CLANG_TIDY_EXE) + add_custom_target(tidy + COMMAND ${CLANG_TIDY_EXE} + -p ${CMAKE_BINARY_DIR} + ${CLANG_TIDY_SOURCES} + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + COMMENT "Running clang-tidy..." + ) + + add_custom_target(tidy-fix + COMMAND ${CLANG_TIDY_EXE} + -p ${CMAKE_BINARY_DIR} + --fix + ${CLANG_TIDY_SOURCES} + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + COMMENT "Running clang-tidy with fixes..." + ) +else() + message(STATUS "clang-tidy no encontrado - targets 'tidy' y 'tidy-fix' no disponibles") +endif() + +# Targets de clang-format +if(CLANG_FORMAT_EXE) + add_custom_target(format + COMMAND ${CLANG_FORMAT_EXE} + -i + ${FORMAT_SOURCES} + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + COMMENT "Running clang-format..." + ) + + add_custom_target(format-check + COMMAND ${CLANG_FORMAT_EXE} + --dry-run + --Werror + ${FORMAT_SOURCES} + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + COMMENT "Checking clang-format..." + ) +else() + message(STATUS "clang-format no encontrado - targets 'format' y 'format-check' no disponibles") +endif()