XamlStyler icon indicating copy to clipboard operation
XamlStyler copied to clipboard

Make better format for Settings.XamlStyler

Open Denis535 opened this issue 4 years ago • 1 comments

Current settings:

{
    "AttributesTolerance": 2,
    "KeepFirstAttributeOnSameLine": false,
    "MaxAttributeCharactersPerLine": 0,
    "MaxAttributesPerLine": 1,
    "NewlineExemptionElements": "RadialGradientBrush, GradientStop, LinearGradientBrush, ScaleTransfom, SkewTransform, RotateTransform, TranslateTransform, Trigger, Condition, Setter",
    "SeparateByGroups": false,
    "AttributeIndentation": 0,
    "AttributeIndentationStyle": 1,
    "RemoveDesignTimeReferences":  false,
    "EnableAttributeReordering": true,
    "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"
    ],
    "FirstLineAttributes": "",
    "OrderAttributesByName": true,
    "PutEndingBracketOnNewLine": false,
    "RemoveEndingTagOfEmptyElement": true,
    "SpaceBeforeClosingSlash": true,
    "RootElementLineBreakRule": 0,
    "ReorderVSM": 2,
    "ReorderGridChildren": false,
    "ReorderCanvasChildren": false,
    "ReorderSetters": 0,
    "FormatMarkupExtension": true,
    "NoNewLineMarkupExtensions": "x:Bind, Binding",
    "ThicknessSeparator": 2,
    "ThicknessAttributes": "Margin, Padding, BorderThickness, ThumbnailClipMargin",
    "FormatOnSave": true,
    "CommentPadding": 2,
}

I spent several days thinking how to do it better. And here is what I suggest:

// Rule naming convention: Namespace.Targets.Option: Value/Values.
// Namespaces: Ordering, Spacing, MultiLining, Clearing, Special, VSIX.
// Targets: Elements, Attributes, Comments.
{
    // Ordering
    "Ordering.Elements.EnableForChildrenOfGrid": false,
    "Ordering.Elements.EnableForChildrenOfCanvas": false,
    "Ordering.Elements.EnableForVisualStateManager": 2, // None, First, Last
    "Ordering.Elements.EnableForSetters": 0, // None, Property, TargetName, TargetNameThenProperty 
    "Ordering.Attributes.Enable": true, // Excess
    "Ordering.Attributes.OrderByRules": true,
    "Ordering.Attributes.OrderByName": true,
    "Ordering.Attributes.Rules": [
        "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"
    ],

    // Spacing
    "Spacing.Elements.InsertSpaceBeforeClosingSlash": true,
    "Spacing.Attributes.IndentSize": 0,
    "Spacing.Attributes.IndentStyle": 1, // Mixed, Spaces 
    "Spacing.Comments.Padding": 2,

    // MultiLining
    "MultiLining.Elements.PlaceEndingBracketOnNewLine": false,
    "MultiLining.Attributes.EnableForAttributesOfRootElement": 0, // Default, Always, Never
    "MultiLining.Attributes.EnableForAttributesOfElements": "", // Feature request
    "MultiLining.Attributes.EnableIfAttributesAreGreaterThan": 2,
    "MultiLining.Attributes.DisableForAttributesOfElements": "RadialGradientBrush, GradientStop, LinearGradientBrush, ScaleTransfom, SkewTransform, RotateTransform, TranslateTransform, Trigger, Condition, Setter",
    "MultiLining.Attributes.StartWithTagLine": true,
    "MultiLining.Attributes.KeepOnTagLine": "",
    "MultiLining.Attributes.SeparateByRules": true,
    "MultiLining.Attributes.MaxAttributesPerLine": 0,
    "MultiLining.Attributes.MaxCharactersPerLine": 0,
    "MultiLining.Attributes.Rules": [
        "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"
    ],
    
    // Clearing
    "Clearing.Elements.RemoveEndingTagOfEmptyElement": true,
    "Clearing.Attributes.RemoveDesignTimeReferences": false,

    // Special
    "Special.Attributes.MarkupExtensions.PlaceOnNewLine": true,
    "Special.Attributes.MarkupExtensions.KeepOnSameLine": "x:Bind, Binding",
    "Special.Attributes.Collections": "Margin, Padding, BorderThickness, ThumbnailClipMargin",
    "Special.Attributes.Collections.Separator": 2, // None, Space, Comma

    // VSIX
    "VSIX.FormatOnSave": true,
}

I also suggest to use .EditorConfig file. Or at least rename your file to .XamlStyler.

Denis535 avatar Apr 13 '20 10:04 Denis535

Thanks for the detailed write up! We think this is a great idea, but there are a couple open questions we want to think through before implementing this:

  • How might we handle backwards compatibility with the old configuration schema?
  • We may want to treat #271 as a prerequisite, so we can communicate schema changes to developers when they upgrade.
  • We should think through naming a bit more to ensure we are future-proofing against new settings. I think your suggestions are a reasonable starting point to work from, though.
  • We'll need to think through support/backwards compatibility in XAML Styler Console as well.
  • Support for .editorconfig makes a lot of sense, but we don't think it is in scope for this change, and in the meantime, we should probably keep the existing XamlStyler.Settings file naming to avoid too much churn here for projects that rely on it.

Thanks again for your contribution!

grochocki avatar Apr 29 '20 06:04 grochocki