Auto-format our XAML files and enforce in CI#9589
Conversation
This comment has been minimized.
This comment has been minimized.
This should _not_ work guys
This comment has been minimized.
This comment has been minimized.
|
HOOPLAH, it works in CI. I've got a bit more polish to do, so I'll tag folks when this is ready |
…les that didn't have them to start with...
…at the line endings are gonna hyper explode
carlos-zamora
left a comment
There was a problem hiding this comment.
THANK YOU!
Does VS/VSCode automatically adhere to this styling, or do we need to do anything for that?
lol like VS adheres to any sort of consistent rules 😝 That I'm still working on. Probably not? |
I can get you a git hook. That'll update the file silently as you commit the file. Sound good? |
|
Stick the following in ################################################################################
# XAML Styler - xstyler.exe pre-commit Git Hook
# Documentation: https://github.com/Xavalon/XamlStyler/wiki
# Originally from https://github.com/Xavalon/XamlStyler/wiki/Git-Hook
# Define path to xstyler.exe
XSTYLER_PATH="dotnet tool run xstyler --"
# Define path to XAML Styler configuration
XSTYLER_CONFIG=
# Define path to copy original XAML files as backup
# BACKUP_PATH=.XamlBackup
echo "Running XAML Styler on committed XAML files"
git diff --cached --name-only --diff-filter=ACM | grep -e '\.xaml$' | \
# Wrap in brackets to preserve variable through loop
{
# Setup XAML file backup
# if [ -n "$BACKUP_PATH" ]; then
# echo "Backing up XAML files to: $BACKUP_PATH"
# BACKUP_PATH="$BACKUP_PATH/$(date +"%Y-%m-%d_%H-%M-%S")/"
# fi
files=""
# Build list of files to pass to xstyler.exe
while read FILE; do
if [ "$files" == "" ]; then
files="$FILE";
# mkdir -p $BACKUP_PATH
else
files="$files,$FILE";
fi
# if [ -n "$BACKUP_PATH" ]; then
# cp -r --parents $FILE $BACKUP_PATH
# fi
done
if [ "$files" != "" ]; then
# Check if external configuration is specified
[ -z "$XSTYLER_CONFIG" ] && configParam="" || configParam="-c $XSTYLER_CONFIG"
# Format XAML files
$XSTYLER_PATH -f "$files" $configParam
git add -u
else
echo "No XAML files detected in commit"
fi
exit 0
}
################################################################################I commented out the backup functionality. You can keep that if you'd like. |
This comment has been minimized.
This comment has been minimized.
|
@carlos-zamora wait that git hook won't work right - it'll add all the BOMs back :( |
Presumably, git will fix the line endings in the repo and check out the right ones? lawd everything is awful
|
Alright @DHowett, I figured all the bugs out. This is actually ready now. |
This comment has been minimized.
This comment has been minimized.
| # format the files - it'll only ensure that they're formatted correctly. | ||
| function Invoke-VerifyXamlFormat() { | ||
| $root = Find-OpenConsoleRoot | ||
| & dotnet tool restore --add-source https://api.nuget.org/v3/index.json |
There was a problem hiding this comment.
Presumes a lot about the user's environment... hmm.
…tting-2.0 # Conflicts: # src/cascadia/TerminalApp/CommandPalette.xaml # src/cascadia/TerminalSettingsEditor/Launch.xaml
… 'find all xaml files' bit
|
However, the xaml formatter hates itself. Ah, Me asking you to rename the thing made us break it. I'm sorry. |
|
It needs to be exported from the thing |
This adds
XamlStyler.Consoleto our solution, and calls it when weformat the code, to also format
our .xaml files.
XamlStyler.Consoleis a dotnet tool so it needs to be restored withdotnet tool restoreThose guidelines also recommend things based on the code-behind, which
this tool can't figure out, but also don't matter that much.
adds a BOM by default. Some had them before and others didn't. BOMs
have been nothing but trouble though.