mirror of
https://github.com/microsoft/terminal.git
synced 2025-12-19 09:58:08 -05:00
This adds [`XamlStyler.Console`] to our solution, and calls it when we format the code, to also format our .xaml files. * `XamlStyler.Console` is a dotnet tool so it needs to be restored with `dotnet tool restore` * I've added a set of rules to approximately follow [@cmaneu's XAML guidelines]. Those guidelines also recommend things based on the code-behind, which this tool can't figure out, but also _don't matter that much_. * There's an extra step to strip BOMs from the output, since Xaml Styler adds a BOM by default. Some had them before and others didn't. BOMs have been nothing but trouble though. [`XamlStyler.Console`]: https://github.com/Xavalon/XamlStyler [@cmaneu's XAML guidelines]: https://github.com/cmaneu/xaml-coding-guidelines
27 lines
833 B
PowerShell
27 lines
833 B
PowerShell
|
|
#.SYNOPSIS
|
|
# Checks for code formatting errors. Will throw exception if any are found.
|
|
function Invoke-CheckBadCodeFormatting() {
|
|
Import-Module ./tools/OpenConsole.psm1
|
|
|
|
# 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
|
|
|
|
# returns a non-zero exit code if there are any diffs in the tracked files in the repo
|
|
git diff-index --quiet HEAD --
|
|
if ($lastExitCode -eq 1) {
|
|
|
|
# Write the list of files that need updating to the log
|
|
git diff-index --name-only HEAD
|
|
|
|
throw "code formatting bad, run Invoke-CodeFormat on branch"
|
|
}
|
|
|
|
# Manually check the formatting of our .xaml files, without touching them.
|
|
Verify-XamlFormat
|
|
|
|
}
|
|
|
|
Invoke-CheckBadCodeFormatting
|