add: local code formatting script for Windows

Amp-Thread-ID: https://ampcode.com/threads/T-019c2688-afaf-76f5-b318-15265247ba46
Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
georg0480
2026-02-04 16:42:28 +01:00
parent b80783c885
commit cdb56db167

30
scripts/format-code.ps1 Normal file
View File

@@ -0,0 +1,30 @@
# Format all C++ source files with clang-format
# Run this before committing to avoid CI failures
$ErrorActionPreference = "Stop"
# Check if clang-format is installed
$clangFormat = Get-Command clang-format -ErrorAction SilentlyContinue
if (-not $clangFormat) {
Write-Host "clang-format not found. Installing via winget..." -ForegroundColor Yellow
winget install LLVM.LLVM
Write-Host "Please restart PowerShell and run this script again." -ForegroundColor Yellow
exit 1
}
# Find all source files
$srcPath = Join-Path $PSScriptRoot "..\src"
$files = Get-ChildItem -Path $srcPath -Recurse -Include "*.h", "*.c", "*.cpp" |
Where-Object {
$_.FullName -notmatch "spatialmedia" -and
$_.Name -ne "defaultlayouts.h" -and
$_.FullName -notmatch "_autogen"
}
Write-Host "Formatting $($files.Count) files..." -ForegroundColor Cyan
foreach ($file in $files) {
clang-format -style=file -i $file.FullName
}
Write-Host "Done! All files formatted." -ForegroundColor Green