Skip to content
Open
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
197 changes: 197 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
# *************************************************************************
#
# clang-tidy configuration for microlog
# Copyright (c) 2025 Andrei Gramakov. All rights reserved.
#
# This configuration reinforces current code practices while maintaining
# flexibility for embedded systems and cross-platform compatibility.
#
# *************************************************************************

# Inherit configuration from parent directories
InheritParentConfig: false

# Use LLVM style as baseline (matching .clang-format)
FormatStyle: file

# Enable checks that reinforce current code practices
Checks: >
-*,
bugprone-*,
-bugprone-easily-swappable-parameters,
-bugprone-assignment-in-if-condition,
cert-*,
-cert-err33-c,
-cert-dcl37-c,
-cert-dcl51-cpp,
clang-analyzer-*,
-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,
concurrency-*,
cppcoreguidelines-*,
-cppcoreguidelines-avoid-magic-numbers,
-cppcoreguidelines-avoid-non-const-global-variables,
-cppcoreguidelines-init-variables,
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
-cppcoreguidelines-pro-type-union-access,
-cppcoreguidelines-pro-type-vararg,
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
-cppcoreguidelines-pro-bounds-constant-array-index,
hicpp-multiway-paths-covered,
hicpp-no-assembler,
hicpp-signed-bitwise,
misc-*,
-misc-unused-parameters,
-misc-non-private-member-variables-in-classes,
modernize-*,
-modernize-use-trailing-return-type,
-modernize-macro-to-enum,
-modernize-avoid-c-arrays,
performance-*,
portability-*,
-portability-avoid-pragma-once,
readability-*,
-readability-magic-numbers,
-readability-function-cognitive-complexity,
-readability-identifier-length,
-readability-isolate-declaration,
-readability-avoid-const-params-in-decls,
-readability-non-const-parameter,
-readability-uppercase-literal-suffix,
-readability-else-after-return,

# Check options
CheckOptions:
# Naming conventions - enforce snake_case for functions/variables
- key: readability-identifier-naming.FunctionCase
value: lower_case
- key: readability-identifier-naming.VariableCase
value: lower_case
- key: readability-identifier-naming.ParameterCase
value: lower_case
- key: readability-identifier-naming.LocalVariableCase
value: lower_case
- key: readability-identifier-naming.GlobalVariableCase
value: lower_case

# Allow internal types with _t suffix
- key: readability-identifier-naming.TypedefCase
value: lower_case
- key: readability-identifier-naming.TypedefSuffix
value: ""
- key: readability-identifier-naming.StructCase
value: lower_case
- key: readability-identifier-naming.UnionCase
value: lower_case

# Enforce UPPER_CASE for enum types (ulog_level, ulog_status)
- key: readability-identifier-naming.EnumCase
value: lower_case
- key: readability-identifier-naming.EnumConstantCase
value: UPPER_CASE

# Constants should be in lower_case (following project style)
- key: readability-identifier-naming.ConstantCase
value: lower_case
- key: readability-identifier-naming.GlobalConstantCase
value: lower_case

# Static function naming
- key: readability-identifier-naming.StaticVariableCase
value: lower_case

# Allow some flexibility for embedded patterns
- key: readability-function-size.LineThreshold
value: 150
- key: readability-function-size.StatementThreshold
value: 150
- key: readability-function-size.BranchThreshold
value: 30
- key: readability-function-size.ParameterThreshold
value: 10
- key: readability-function-size.NestingThreshold
value: 6

# Braces are required for safety
- key: readability-braces-around-statements.ShortStatementLines
value: 0

# Line length matches .clang-format
- key: readability-line-length.LineLength
value: 80

# Allow some implicit conversions for C compatibility
- key: readability-implicit-bool-conversion.AllowIntegerConditions
value: true
- key: readability-implicit-bool-conversion.AllowPointerConditions
value: true

# Configure memory management checks
- key: cppcoreguidelines-no-malloc.Allocations
value: "malloc,calloc,realloc"
- key: cppcoreguidelines-no-malloc.Deallocations
value: "free"
- key: cppcoreguidelines-no-malloc.Reallocations
value: "realloc"

# Allow some narrowing for embedded systems
- key: cppcoreguidelines-narrowing-conversions.WarnOnIntegerNarrowingConversion
value: false

# Avoid C-style casts but be lenient with platform code
- key: cppcoreguidelines-pro-type-cstyle-cast.StrictMode
value: false

# Configure bugprone checks
- key: bugprone-assert-side-effect.AssertMacros
value: "assert"
- key: bugprone-suspicious-string-compare.WarnOnImplicitComparison
value: true
- key: bugprone-suspicious-string-compare.WarnOnLogicalNotComparison
value: true

# Performance settings
- key: performance-move-const-arg.CheckTriviallyCopyableMove
value: false
- key: performance-unnecessary-value-param.AllowedTypes
value: ""

# Modernize settings (be conservative for C99 compatibility)
- key: modernize-use-nullptr.NullMacros
value: "NULL"
- key: modernize-use-default-member-init.UseAssignment
value: true
- key: modernize-use-default-member-init.IgnoreMacros
value: true

# Readability settings
- key: readability-simplify-boolean-expr.ChainedConditionalReturn
value: false
- key: readability-simplify-boolean-expr.ChainedConditionalAssignment
value: false

# Comment style
- key: readability-redundant-declaration.IgnoreMacros
value: true

# Files to exclude from analysis
HeaderFilterRegex: '(include|src|extensions)/.*\.(h|c)$'

# Exclude third-party code and build directories
ExcludeHeaderFilterRegex: "(tests/unit/doctest|example/build|build)/.*"

# Warning as errors for critical issues
WarningsAsErrors: >
bugprone-use-after-move,
bugprone-infinite-loop,
bugprone-assert-side-effect,
cert-err34-c,
cert-msc50-cpp,
cert-msc51-cpp,
clang-analyzer-core.DivideZero,
clang-analyzer-core.NullDereference,
clang-analyzer-deadcode.DeadStores,
clang-analyzer-unix.Malloc,
concurrency-mt-unsafe

# System headers to ignore
SystemHeaders: false
46 changes: 46 additions & 0 deletions .github/workflows/clang-tidy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Clang-Tidy

on:
workflow_call:
pull_request:
branches:
- main
- release/*
paths:
- '**.c'
- '**.h'
- '**.cpp'
- '**.hpp'
- '.clang-tidy'
- 'scripts/check-clang-tidy.ps1'
push:
branches:
- main
paths:
- '**.c'
- '**.h'
- '**.cpp'
- '**.hpp'
- '.clang-tidy'

jobs:
clang-tidy:
name: Run Clang-Tidy
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for all branches and tags

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y clang-tidy cmake ninja-build

- name: Run clang-tidy check
run: |
pwsh scripts/check-clang-tidy.ps1 -BaseBranch origin/main
env:
BASE_BRANCH: origin/main
4 changes: 4 additions & 0 deletions .github/workflows/workflow-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ jobs:
name: Verify Version
uses: ./.github/workflows/verify-version.yml

clang-tidy:
name: Clang-Tidy Check
uses: ./.github/workflows/clang-tidy.yml

6 changes: 4 additions & 2 deletions extensions/ulog_generic_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ typedef enum {
} log_level;

/// @brief Log a message at the specified level.
/// @param level Log level (LOG_TRACE, LOG_DEBUG, LOG_INFO, LOG_WARN, LOG_ERROR, LOG_FATAL).
/// @param level Log level (LOG_TRACE, LOG_DEBUG, LOG_INFO, LOG_WARN, LOG_ERROR,
/// LOG_FATAL).
/// @param ... printf-style format string and arguments.
#define log_message(level, ...) ulog(level, __VA_ARGS__)

/// @brief Log a message with a topic at the specified level.
/// @param level Log level (LOG_TRACE, LOG_DEBUG, LOG_INFO, LOG_WARN, LOG_ERROR, LOG_FATAL).
/// @param level Log level (LOG_TRACE, LOG_DEBUG, LOG_INFO, LOG_WARN, LOG_ERROR,
/// LOG_FATAL).
/// @param topic A string topic (e.g. "NET", "UI") to categorize the message.
/// @param ... printf-style format string and arguments.
#define log_topic(level, topic, ...) ulog_t(level, topic, __VA_ARGS__)
Expand Down
2 changes: 2 additions & 0 deletions extensions/ulog_lock_cmsis.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
// *************************************************************************

#include "ulog_lock_cmsis.h"
#include <stddef.h>
#include "cmsis_os2.h"
#include "ulog.h"

/** @brief Internal CMSIS-RTOS2 mutex adapter. */
static ulog_status cmsis_lock_fn(bool lock, void *arg) {
Expand Down
2 changes: 2 additions & 0 deletions extensions/ulog_lock_freertos.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
// *************************************************************************

#include "ulog_lock_freertos.h"
#include <stddef.h>
#include "FreeRTOS.h"
#include "semphr.h"
#include "ulog.h"

/** @brief Internal FreeRTOS mutex adapter. */
static ulog_status freertos_lock_fn(bool lock, void *arg) {
Expand Down
3 changes: 3 additions & 0 deletions extensions/ulog_lock_pthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
// *************************************************************************

#include "ulog_lock_pthread.h"
#include <pthread.h>
#include <stddef.h>
#include "ulog.h"

/**
* @brief Internal adapter; wraps pthread mutex operations in ulog_lock_fn
Expand Down
2 changes: 2 additions & 0 deletions extensions/ulog_lock_threadx.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// microlog extension: ThreadX mutex lock helper (implementation)
// *************************************************************************
#include "ulog_lock_threadx.h"
#include <stddef.h>
#include "ulog.h"

/** @brief Internal ThreadX mutex adapter. */
static ulog_status threadx_lock_fn(bool lock, void *arg) {
Expand Down
3 changes: 3 additions & 0 deletions extensions/ulog_lock_win.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
// *************************************************************************

#include "ulog_lock_win.h"
#include <stddef.h>
#include <synchapi.h>
#include "ulog.h"

// Internal lock function ----------------------------------------------------
/** @brief Internal lock adapter for Windows Critical Section. */
Expand Down
1 change: 1 addition & 0 deletions extensions/ulog_syslog.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// microlog extension: Syslog Levels (implementation)
// *************************************************************************

#include "ulog.h"
#include "ulog_syslog.h"

static ulog_level_descriptor syslog_levels = {
Expand Down
Loading
Loading