Code Monkey home page Code Monkey logo

Comments (4)

grochocki avatar grochocki commented on June 28, 2024

Interesting idea! Your example works out nicely, but I am curious what expected behavior might be under less ideal scenarios. For instance, in your example, let's say you've specified Grid.Column as an exempted attribute value, but this is the original input:

<Button
    x:Key="MyCustomButton"
    Grid.Column="2"
    Style="{StaticResource MyCustomStyle}"/>

from xamlstyler.

michael-hawker avatar michael-hawker commented on June 28, 2024

@grochocki yeah, I was thinking about that a bit more as well. There's definitely some complications. Easy for us humans to look at and know what we want, harder to quantify to the machines. 😋

I think the common piece here with a lot of these types of attributes and scenarios is that they're really tied to groups/sets of properties, e.g. you want your canvas attached properties or grid ones together.

Since AttributeOrderingRuleGroups kind of establishes these types of groups already, maybe it'd make sense to leverage that list as well?

So, the newline exemption would only apply if the attribute is paired with another one of its partner attributes in that collection?


For example, typically we have this:

    "AttributeOrderingRuleGroups": [
        "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"
    ],

So if the NewlineExceptionElements was defined as:

    "NewlineExceptionElements": "Grid.Column, Canvas.Top, Height"

Then if one of these is encountered, say Grid.Column it looks in the AttributeOrderingRuleGroups and finds where Grid.Column is. Then only applies the exemption if one of those other properties before it is found (in this case Grid.Row or Grid.RowSpan).

So in your example:

<Button
    x:Key="MyCustomButton"
    Grid.Column="2"
    Style="{StaticResource MyCustomStyle}"/>

Since there's no Grid.Row it doesn't get the exemption. But if you were to add one, then it would apply:

<Button
    x:Key="MyCustomButton"
    Grid.Row="1" Grid.Column="2"
    Style="{StaticResource MyCustomStyle}"/>

Even if the developer put them in different spots (before formatting):

<Button
    x:Key="MyCustomButton"
    Grid.Column="2"
    Style="{StaticResource MyCustomStyle}"
    Grid.Row="1"/>

Since they'd get ordered first by the attribute ordering rules, then it should be able to flow the logic and be consistent, right?

from xamlstyler.

grochocki avatar grochocki commented on June 28, 2024

Leveraging AttributeOrderingRuleGroups could make things really clean. What if we lean in even further into those groupings and instead of indivudal attribute-based NewlineExemptionAttributes, created attribute group index-based NewlineExemptionAttributeGroups?

So, with this (abridged) config:

    "AttributeOrderingRuleGroups": [
		...
0        "x:Key, Key, x:Name, Name, x:Uid, Uid, Title",
1        "Grid.Row, Grid.RowSpan, Grid.Column, Grid.ColumnSpan, Canvas.Left, Canvas.Top, Canvas.Right, Canvas.Bottom",
2        "Width, Height, MinWidth, MinHeight, MaxWidth, MaxHeight",
		...
    ],
	"NewlineExemptionAttributeGroups": ["1"],

You would get:

<Button
    x:Key="MyCustomButton"
    Grid.Row="1" Grid.Column="2"
    Style="{StaticResource MyCustomStyle}"/>

If you wanted to, say, only exempt Grid.*, and not Canvas.* attributes, split grouping:

    "AttributeOrderingRuleGroups": [
		...
0        "x:Key, Key, x:Name, Name, x:Uid, Uid, Title",
1        "Grid.Row, Grid.RowSpan, Grid.Column, Grid.ColumnSpan",
2        "Canvas.Left, Canvas.Top, Canvas.Right, Canvas.Bottom",
3        "Width, Height, MinWidth, MinHeight, MaxWidth, MaxHeight",
		...
    ],
	"NewlineExemptionAttributeGroups": ["1"],

Or both, but on separate lines:

    "AttributeOrderingRuleGroups": [
		...
0        "x:Key, Key, x:Name, Name, x:Uid, Uid, Title",
1        "Grid.Row, Grid.RowSpan, Grid.Column, Grid.ColumnSpan",
2        "Canvas.Left, Canvas.Top, Canvas.Right, Canvas.Bottom",
3        "Width, Height, MinWidth, MinHeight, MaxWidth, MaxHeight",
		...
    ],
	"NewlineExemptionAttributeGroups": ["1", "2"],

from xamlstyler.

michael-hawker avatar michael-hawker commented on June 28, 2024

Yeah, that could work too. Only issue with the index-based approach is that if someone changes the order of their attribute rule groups that can have unintended/adverse effects they don't expect, if they forgot they set the other property (or weren't aware of it with multiple contributors).

from xamlstyler.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.