Xavalon / XamlStyler

Visual Studio extension to help format your XAML source code
Apache License 2.0
1.18k stars 128 forks source link

Extension will not alphabetize #444

Closed rhayhurst closed 10 months ago

rhayhurst commented 10 months ago

The XamlStyler for Visual Studio will not alphabetize. No error message, no feedback in any way. Everything else works, in that it formats the file.

I get the same behavior regardless of what file/framework I'm using. I tried it on several .NET (7) MAUI project .xml files and a Xamarin.Forms project .xml file. The files are about as pedestrian as it can get.

I'm using Visual Studio Version 17.7.5, version 4.8.09032. The extension I'm using is "XAML Styler for Visual Studio 2022" version 3.2208.1. Here is a SO question I posted in case there's something I leave out.

The lack-of-alphabetization happened out of the box. I didn't touch anything in Tools >> Options >> XAML Styler, though just to be sure I changed a setting and then hit the "reset to default" option, and the setting did indeed reset to the default.

There must be something on my machine that isn't playing well with your software, possibly another extension that I have installed? Here are the extensions that I currently have installed:

Finally, there's another weird thing about my computer which probably isn't relevant: I have two Android SDKs installed, as .NET Maui wants Android SDK to be installed at location A and Android Studio wants Android SDK installed at location B, and neither one will compromise (in case your software needs to know the location for some unknown reason, this could be messing it up).

rhayhurst commented 10 months ago

Oh, sorry, should've mentioned this: I'm on Windows 11, specifically: Windows 11 Pro version 22H2, OS build 22621.2428

grochocki commented 10 months ago

By default, attributes are not ordered strictly alphabetical, but rather by a set of Attribute Ordering Rule Groups. Wildcards within rule groups will be alphabetized. Strict alphabetization of all attributes is not something that would be generally accepted as a best practice in XAML, but you should still be able to achieve this by changing Attribute Ordering Rule Groups from:

"x:Class",
"xmlns, xmlns:x",
"xmlns:*",
"x:Key, Key, x:Name, Name, x:Uid, Uid, Title",
"Grid.Row, Grid.RowSpan, Grid.Column, Grid.ColumnSpan, Canvas.Left, Canvas.Top, Canvas.Right, Canvas.Bottom",
"Width, Height, MinWidth, MinHeight, MaxWidth, MaxHeight",
"Margin, Padding, HorizontalAlignment, VerticalAlignment, HorizontalContentAlignment, VerticalContentAlignment, Panel.ZIndex",
"*:*, *",
"PageSource, PageIndex, Offset, Color, TargetName, Property, Value, StartPoint, EndPoint",
"mc:Ignorable, d:IsDataSource, d:LayoutOverrides, d:IsStaticText",
"Storyboard.*, From, To, Duration"

to

"*:*, *"
rhayhurst commented 10 months ago

Why wouldn't strict alphabetization not be considered a best practice in Xaml? I don't see how it hurts anything. When I read the description of the XamlStyler, I was under the direct impression that alphabetizing attributes was kind of what it did -- other stuff, too, but that was one of the main functions. It's why I downloaded it.

Anyways, I'll give your instructions a shot. Thanks!

grochocki commented 10 months ago

There are certain logical groupings of attributes that sometimes makes it easier when adjusting them. For example, Width, Height, MaxWidth, MaxHeight, etc., so you will typically see certain attributes next to each other. In the default rule ordering groups, we separate these out, leaving everything else to the middle alphabetized catch all group *:*, *.