2019-06-11 16:23:21 -07:00
|
|
|
|
|
|
|
|
#.SYNOPSIS
|
|
|
|
|
# Checks for code formatting errors. Will throw exception if any are found.
|
|
|
|
|
function Invoke-CheckBadCodeFormatting() {
|
|
|
|
|
Import-Module ./tools/OpenConsole.psm1
|
2021-03-29 17:09:38 -05:00
|
|
|
|
|
|
|
|
# Don't run the XAML formatter in this step - even if it changes nothing,
|
|
|
|
|
# it'll still touch all the .xaml files.
|
|
|
|
|
Invoke-CodeFormat -IgnoreXaml
|
|
|
|
|
|
2026-10-19 16:44:45 -05:00
|
|
|
$file = $null
|
|
|
|
|
$count = 0
|
|
|
|
|
git -c core.quotePath=false diff --no-color -U0 HEAD | ForEach-Object {
|
|
|
|
|
if ($_ -cmatch '^\+\+\+ b/(.*)$')
|
|
|
|
|
{
|
|
|
|
|
$file = $Matches[1]
|
|
|
|
|
$count++
|
|
|
|
|
}
|
|
|
|
|
elseif ($null -ne $file -and $_ -cmatch '^@@ .* \+(\d+)')
|
|
|
|
|
{
|
|
|
|
|
$line = [int]$Matches[1]
|
|
|
|
|
Write-Host ("::error file={0},line={1},title=Format::{0} is improperly formatted" -f ($file, $line))
|
|
|
|
|
$file = $null
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-03-29 17:09:38 -05:00
|
|
|
|
2026-10-19 16:44:45 -05:00
|
|
|
if ($count -gt 0) {
|
2019-06-11 16:23:21 -07:00
|
|
|
throw "code formatting bad, run Invoke-CodeFormat on branch"
|
|
|
|
|
}
|
2021-03-29 17:09:38 -05:00
|
|
|
|
|
|
|
|
# Manually check the formatting of our .xaml files, without touching them.
|
2021-05-21 13:11:54 -03:00
|
|
|
Test-XamlFormat
|
2021-03-29 17:09:38 -05:00
|
|
|
|
2019-06-11 16:23:21 -07:00
|
|
|
}
|
|
|
|
|
|
2026-10-19 16:44:45 -05:00
|
|
|
[System.Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
2019-06-11 16:23:21 -07:00
|
|
|
Invoke-CheckBadCodeFormatting
|