From 4e3ecadfe4ccb8540eb3e40c0515578f5f2bc266 Mon Sep 17 00:00:00 2001 From: Cyberhan123 <255542417@qq.com> Date: Thu, 11 Jun 2026 13:25:03 +0800 Subject: [PATCH] feat: add script for automatic code formatting --- format-code.ps1 | 54 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 format-code.ps1 diff --git a/format-code.ps1 b/format-code.ps1 new file mode 100644 index 000000000..9e55cb2e2 --- /dev/null +++ b/format-code.ps1 @@ -0,0 +1,54 @@ +$patterns = @( + "src/*.cpp" + "src/*.h" + "src/*.hpp" + "src/conditioning/*.cpp" + "src/conditioning/*.h" + "src/conditioning/*.hpp" + "src/core/*.cpp" + "src/core/*.h" + "src/core/*.hpp" + "src/extensions/*.cpp" + "src/extensions/*.h" + "src/extensions/*.hpp" + "src/runtime/*.cpp" + "src/runtime/*.h" + "src/runtime/*.hpp" + "src/model/*/*.cpp" + "src/model/*/*.h" + "src/model/*/*.hpp" + "src/tokenizers/*.h" + "src/tokenizers/*.cpp" + "src/tokenizers/vocab/*.h" + "src/tokenizers/vocab/*.cpp" + "src/model_io/*.h" + "src/model_io/*.cpp" + "examples/cli/*.cpp" + "examples/cli/*.h" + "examples/server/*.cpp" + "examples/common/*.hpp" + "examples/common/*.h" + "examples/common/*.cpp" +) + +$root = (Get-Location).Path + +foreach ($pattern in $patterns) { + $files = Get-ChildItem -Path $pattern -File -ErrorAction SilentlyContinue | Sort-Object FullName + + foreach ($file in $files) { + $relativePath = $file.FullName.Substring($root.Length).TrimStart('\', '/') -replace '\\', '/' + + if ($relativePath -like "vocab*") { + continue + } + + Write-Host "formatting '$relativePath'" + + # if ($relativePath -ne "stable-diffusion.h") { + # clang-tidy -fix -p build_linux/ "$relativePath" + # } + + & clang-format -style=file -i $relativePath + } +}