Skip to content
This repository was archived by the owner on Jul 12, 2022. It is now read-only.

Commit 03b1c05

Browse files
committed
Clean up RuleOrdering
Previously rule orderings were split across all the different rules. With this change, I have introduced a new RuleOrder static class that has constants for each rule sorted by the order in which they run. This will make it easier to see the ordering of rules and make additions of new rules easier to review. Perhaps longer term we'll want to move to a system where rules declare dependencies or something and we build an ordering based on them, but for now I think this is better than the existing pattern.
1 parent 0da03d6 commit 03b1c05

14 files changed

+41
-12
lines changed

src/Microsoft.DotNet.CodeFormatting/Microsoft.DotNet.CodeFormatting.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
<Compile Include="Rules\IsSimplifiedFormattingRule.cs" />
102102
<Compile Include="Rules\NonAsciiCharactersAreEscapedInLiteralsRule.cs" />
103103
<Compile Include="Rules\RuleExtensions.cs" />
104+
<Compile Include="Rules\RuleOrder.cs" />
104105
<Compile Include="Rules\UsesXunitForTestsFormattingRule.cs" />
105106
<Compile Include="RuleTypeConstants.cs" />
106107
</ItemGroup>

src/Microsoft.DotNet.CodeFormatting/Rules/ExplicitVisibilityRule.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
namespace Microsoft.DotNet.CodeFormatting.Rules
1616
{
17-
[RuleOrder(9)]
17+
[RuleOrder(RuleOrder.ExplicitVisibilityRule)]
1818
internal sealed class ExplicitVisibilityRule : IFormattingRule
1919
{
2020
private sealed class VisibilityRewriter : CSharpSyntaxRewriter

src/Microsoft.DotNet.CodeFormatting/Rules/HasCopyrightHeaderFormattingRule.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
namespace Microsoft.DotNet.CodeFormatting.Rules
1515
{
16-
[RuleOrder(3)]
16+
[RuleOrder(RuleOrder.HasCopyrightHeaderFormattingRule)]
1717
internal sealed class HasCopyrightHeaderFormattingRule : IFormattingRule
1818
{
1919
private static readonly string[] s_copyrightHeader =

src/Microsoft.DotNet.CodeFormatting/Rules/HasNewLineBeforeFirstNamespaceFormattingRule.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
namespace Microsoft.DotNet.CodeFormatting.Rules
1616
{
17-
[RuleOrder(6)]
17+
[RuleOrder(RuleOrder.HasNewLineBeforeFirstNamespaceFormattingRule)]
1818
internal sealed class HasNewLineBeforeFirstNamespaceFormattingRule : IFormattingRule
1919
{
2020
public async Task<Document> ProcessAsync(Document document, CancellationToken cancellationToken)

src/Microsoft.DotNet.CodeFormatting/Rules/HasNewLineBeforeFirstUsingFormattingRule.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
namespace Microsoft.DotNet.CodeFormatting.Rules
1717
{
18-
[RuleOrder(5)]
18+
[RuleOrder(RuleOrder.HasNewLineBeforeFirstUsingFormattingRule)]
1919
internal sealed class HasNewLineBeforeFirstUsingFormattingRule : IFormattingRule
2020
{
2121
private const string FormatError = "Could not format using";

src/Microsoft.DotNet.CodeFormatting/Rules/HasNoCustomCopyrightHeaderFormattingRule.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
namespace Microsoft.DotNet.CodeFormatting.Rules
1717
{
18-
[RuleOrder(1)]
18+
[RuleOrder(RuleOrder.HasNoCustomCopyrightHeaderFormattingRule)]
1919
internal sealed class HasNoCustomCopyrightHeaderFormattingRule : IFormattingRule
2020
{
2121
private static string RulerMarker { get; set; }

src/Microsoft.DotNet.CodeFormatting/Rules/HasNoIllegalHeadersFormattingRule.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
namespace Microsoft.DotNet.CodeFormatting.Rules
1717
{
18-
[RuleOrder(2)]
18+
[RuleOrder(RuleOrder.HasNoIllegalHeadersFormattingRule)]
1919
internal sealed class HasNoIllegalHeadersFormattingRule : IFormattingRule
2020
{
2121
// We are going to replace this header with the actual filename of the document being processed

src/Microsoft.DotNet.CodeFormatting/Rules/HasNoNewLineAfterOpenBraceFormattingRule.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
namespace Microsoft.DotNet.CodeFormatting.Rules
1515
{
16-
[RuleOrder(8)]
16+
[RuleOrder(RuleOrder.HasNoNewLineAfterOpenBraceFormattingRule)]
1717
internal sealed class HasNoNewLineAfterOpenBraceFormattingRule : IFormattingRule
1818
{
1919
public async Task<Document> ProcessAsync(Document document, CancellationToken cancellationToken)

src/Microsoft.DotNet.CodeFormatting/Rules/HasNoNewLineBeforeEndBraceFormattingRule.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
namespace Microsoft.DotNet.CodeFormatting.Rules
1515
{
16-
[RuleOrder(7)]
16+
[RuleOrder(RuleOrder.HasNoNewLineBeforeEndBraceFormattingRule)]
1717
internal sealed class HasNoNewLineBeforeEndBraceFormattingRule : IFormattingRule
1818
{
1919
public async Task<Document> ProcessAsync(Document document, CancellationToken cancellationToken)

src/Microsoft.DotNet.CodeFormatting/Rules/HasUnderScoreInPrivateFieldNamesFormattingRule.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
namespace Microsoft.DotNet.CodeFormatting.Rules
1919
{
20-
[RuleOrder(10)]
20+
[RuleOrder(RuleOrder.HasUnderScoreInPrivateFieldNamesFormattingRule)]
2121
// TODO Bug 1086632: Deactivated due to active bug in Roslyn.
2222
// There is a hack to run this rule, but it's slow.
2323
// If needed, enable the rule and enable the hack at the code below in RenameFields.

0 commit comments

Comments
 (0)