Skip to content

Commit

Permalink
chore: add powershell script for linting
Browse files Browse the repository at this point in the history
  • Loading branch information
fxliang committed Feb 12, 2025
1 parent 57b4cc4 commit a6d15ce
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions clang-format.ps1
Original file line number Diff line number Diff line change
@@ -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."
}

0 comments on commit a6d15ce

Please # to comment.