Skip to content

Commit

Permalink
improve readability and error catching of CheckFormat.ps1
Browse files Browse the repository at this point in the history
  • Loading branch information
Freezor committed Jun 6, 2024
1 parent fb81df3 commit 51bc445
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/CheckFormat.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,29 @@ Import-Module (Join-Path $PSScriptRoot Common.psm1) -Function `
function Main {
AssertDotnetFormatVersion

Set-Location $PSScriptRoot
$scriptDir = $PSScriptRoot
Write-Host "Changing to script directory: $scriptDir"
Set-Location $scriptDir

Write-Host "Inspecting the code format with dotnet-format..."

Write-Host "Restoring dotnet tools..."
dotnet tool restore

$artefactsDir = GetArtefactsDir
Write-Host "Creating artefacts directory: $artefactsDir"
New-Item -ItemType Directory -Force -Path $artefactsDir | Out-Null

$reportPath = Join-Path $artefactsDir "dotnet-format-report.json"
Write-Host "Report path: $reportPath"

Write-Host "Running dotnet format..."
$result = dotnet format --verify-no-changes --report $reportPath --exclude "**/DocTest*.cs" 2>&1

Write-Host "dotnet format output:"
Write-Host $result

if (Test-Path $reportPath) {
Write-Host "Report generated successfully."
$formatReport = Get-Content $reportPath | ConvertFrom-Json
if ($formatReport.Count -ge 1) {
throw "There are $($formatReport.Count) dotnet-format issue(s). The report is stored in: $reportPath"
Expand Down

0 comments on commit 51bc445

Please sign in to comment.