Comments (4)
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.
@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.
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.
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)
- Publish XamlStyler.nupkg on nuget.org
- ARM64 support HOT 10
- Support for Rider 2022.3 HOT 1
- Format Selection text
- Support for Rider 2023.1 HOT 3
- How do I remove XamlStyler?
- How do I change the keyboard shortcut to launch XamlStyler? HOT 1
- How do I get a JSON configuration file? HOT 1
- Sort differently between vs2022 and rider 2023.1 HOT 1
- Formatting on GitHub Actions fails with "Could not find a part of the path" HOT 3
- Formatting fails if a comment contains 'xmlns:' HOT 2
- Format document shortcut missing in JetBrains Rider version.
- Publish latest XamlStyler.Console to NuGet HOT 5
- Is it possible to prevent formatting of short lines - regardless of number of attributes? HOT 2
- Markup extensions not keep on line HOT 1
- Markup extension formatting no longer works HOT 2
- Add support for Rider 2023.2 HOT 7
- Position Setter each attribute on a separate line HOT 2
- XamlStyler moves <!--#endregion--> wrongly HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xamlstyler.