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:
30
scripts/format-code.ps1
Normal file
30
scripts/format-code.ps1
Normal 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
|
||||||
Reference in New Issue
Block a user