From 2924c8e79289d995f3d217a0a977c735b6841177 Mon Sep 17 00:00:00 2001 From: Maze X Date: Fri, 27 Mar 2026 17:41:27 +0100 Subject: [PATCH] Add clang-format and clang-tidy to pre-commit hooks - .pre-commit-config.yaml: Integrate clang-format (v17) and clang-tidy for C/C++ linting Excludes build artifacts (.pio), tests, and board configs from linting - .clang-format: Configure LLVM-style formatting with 4-space indents, 88-char line limit Enforces right pointer alignment, comment reflow, consistent brace placement - .clang-tidy: Configure strict static analysis with snake_case identifiers Enables all checks except Fuchsia/LLVM lib checks and abseil checks Treats warnings as errors --- .clang-format | 18 ++++++++++++++++++ .clang-tidy | 24 ++++++++++++++++++++++++ .pre-commit-config.yaml | 28 ++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 .clang-format create mode 100644 .clang-tidy diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..4d821fc --- /dev/null +++ b/.clang-format @@ -0,0 +1,18 @@ +--- +Language: C +Standard: C99 +BasedOnStyle: LLVM +IndentWidth: 4 +ColumnLimit: 88 +UseTab: Never +BreakBeforeBraces: Attach +AllowShortBlocksOnASingleLine: Never +AllowShortFunctionsOnASingleLine: None +AllowShortIfStatementsOnASingleLine: Never +AlwaysBreakBeforeMultilineStrings: false +BreakStringLiterals: true +PointerAlignment: Right +DerivePointerAlignment: false +SortIncludes: true +ReflowComments: true +MaxEmptyLinesToKeep: 2 diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..ea45ed8 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,24 @@ +--- +Checks: | + *, + -fuchsia-*, + -llvmlibc-*, + -abseil-*, + -google-readability-braces-around-statements, + -readability-braces-around-statements, + -readability-implicit-bool-conversion, +HeaderFilterRegex: 'src/.*\.h' +WarningsAsErrors: '*' +CheckOptions: + - key: readability-identifier-naming.VariableCase + value: snake_case + - key: readability-identifier-naming.FunctionCase + value: snake_case + - key: readability-identifier-naming.MacroDefinitionCase + value: UPPER_CASE + - key: readability-identifier-naming.EnumConstantCase + value: UPPER_CASE + - key: modernize-use-auto.MinTypeNameLength + value: '8' + - key: performance-inefficient-string-concatenation.WarnOnImplicitConversion + value: '1' diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e7a30cf..9ec9759 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -19,3 +19,31 @@ repos: hooks: - id: markdownlint args: ['--fix', '--disable', 'MD040', '--disable', 'MD013'] + + - repo: https://github.com/pre-commit/mirrors-clang-format + rev: v17.0.6 + hooks: + - id: clang-format + types: [c, c++, header] + args: ['-i'] # In-place formatting + exclude: | + (?x)^( + \.pio/| + test/| + soc/| + hardware/ + ) + + - repo: https://github.com/pocc/pre-commit-hooks + rev: v1.3.5 + hooks: + - id: clang-tidy + types: [c, c++, header] + args: ['-checks=*,-fuchsia-*,-llvmlibc-*'] + exclude: | + (?x)^( + \.pio/| + test/| + soc/| + hardware/ + )