From f89d3aa50f994c6c886e9fdc1f95c39142cf9cb9 Mon Sep 17 00:00:00 2001 From: fxliang Date: Thu, 18 Jul 2024 16:56:32 +0800 Subject: [PATCH] chore: add clang-format.ps1 --- clang-format.ps1 | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 clang-format.ps1 diff --git a/clang-format.ps1 b/clang-format.ps1 new file mode 100644 index 000000000..ddbe3f8e9 --- /dev/null +++ b/clang-format.ps1 @@ -0,0 +1,42 @@ +param ( + [switch]$n, + [switch]$i +) + +$WEASEL_SOURCE_PATH = @("RimeWithWeasel", "WeaselDeployer", "WeaselIME", ` + "WeaselIPC", "WeaselIPCServer", "WeaselServer", "WeaselSetup", ` + "WeaselTSF", "WeaselUI", "include", "test") +$excludePatterns = Get-Content .exclude_pattern.txt + +function ShouldExclude($filePath) { + foreach ($pattern in $excludePatterns) { + if ($filePath -like "*$pattern*") { + return $true + } + } + return $false +} + +$filesToProcess = @() + +$WEASEL_SOURCE_PATH | ForEach-Object { + $filesToProcess += Get-ChildItem -Path $_ -Recurse -Include *.cpp, *.h | ` + Where-Object { $_.FullName -notmatch "include\\wtl\\" -and -not (ShouldExclude $_.FullName) } | ` + ForEach-Object { $_.FullName } +} + +if ($filesToProcess.Count -gt 0) { + if ($n) { + clang-format --verbose -i $filesToProcess + Write-Host "Formatting done!" + } elseif ($i) { + clang-format --verbose -Werror --dry-run $filesToProcess + if ($LASTEXITCODE -ne 0) { + Write-Host "Please lint your code by './clang-format.ps1 -n'." + exit 1 + } + Write-Host "Format checking pass!" + } +} else { + Write-Host "No files to process." +}