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

Commit 7b3352d

Browse files
committed
Removed the old IFormattingRule
This rule is no longer needed now that we have the more specific formatting rules in place.
1 parent ccb7dbf commit 7b3352d

18 files changed

+80
-45
lines changed

src/Microsoft.DotNet.CodeFormatting/FormattingEngine.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ public static IFormattingEngine Create(IEnumerable<string> ruleTypes, IEnumerabl
2525
var filteredCatalog = new FilteredCatalog(catalog, cpd =>
2626
{
2727
if (cpd.ExportDefinitions.Any(em =>
28-
em.ContractName == AttributedModelServices.GetContractName(typeof(IFormattingRule)) ||
28+
em.ContractName == AttributedModelServices.GetContractName(typeof(ISyntaxFormattingRule)) ||
29+
em.ContractName == AttributedModelServices.GetContractName(typeof(ILocalSemanticFormattingRule)) ||
30+
em.ContractName == AttributedModelServices.GetContractName(typeof(IGlobalSemanticFormattingRule)) ||
2931
em.ContractName == AttributedModelServices.GetContractName(typeof(IFormattingFilter))))
3032
{
3133
object ruleType;

src/Microsoft.DotNet.CodeFormatting/FormattingEngineImplementation.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ public bool Verbose
3636
[ImportingConstructor]
3737
public FormattingEngineImplementation(
3838
[ImportMany] IEnumerable<IFormattingFilter> filters,
39-
[ImportMany] IEnumerable<Lazy<IFormattingRule, IOrderMetadata>> allRules)
39+
[ImportMany] IEnumerable<Lazy<ISyntaxFormattingRule, IOrderMetadata>> syntaxRules,
40+
[ImportMany] IEnumerable<Lazy<ILocalSemanticFormattingRule, IOrderMetadata>> localSemanticRules,
41+
[ImportMany] IEnumerable<Lazy<IGlobalSemanticFormattingRule, IOrderMetadata>> globalSemanticRules)
4042
{
4143
_filters = filters;
42-
var rulesSorted = allRules.OrderBy(r => r.Metadata.Order).Select(r => r.Value).ToList();
43-
44-
_syntaxRules = rulesSorted.OfType<ISyntaxFormattingRule>().ToList();
45-
_localSemanticRules = rulesSorted.OfType<ILocalSemanticFormattingRule>().ToList();
46-
_globalSemanticRules = rulesSorted.OfType<IGlobalSemanticFormattingRule>().ToList();
44+
_syntaxRules = syntaxRules.OrderBy(r => r.Metadata.Order).Select(r => r.Value).ToList();
45+
_localSemanticRules = localSemanticRules.OrderBy(r => r.Metadata.Order).Select(r => r.Value).ToList();
46+
_globalSemanticRules = globalSemanticRules.OrderBy(r => r.Metadata.Order).Select(r => r.Value).ToList();
4747
}
4848

4949
public Task FormatSolutionAsync(Solution solution, CancellationToken cancellationToken)

src/Microsoft.DotNet.CodeFormatting/IFormattingRule.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,10 @@
99

1010
namespace Microsoft.DotNet.CodeFormatting
1111
{
12-
// TODO: this is a hack. Need to delete it
13-
internal interface IFormattingRule
14-
{
15-
16-
}
17-
1812
/// <summary>
1913
/// Rules which need no semantic information and operate on parse trees only.
2014
/// </summary>
21-
internal interface ISyntaxFormattingRule : IFormattingRule
15+
internal interface ISyntaxFormattingRule
2216
{
2317
SyntaxNode Process(SyntaxNode syntaxRoot);
2418
}
@@ -28,15 +22,15 @@ internal interface ISyntaxFormattingRule : IFormattingRule
2822
/// used for rules that need to see a <see cref="Document"/> and <see cref="SyntaxNode"/> which
2923
/// are in sync with each other,
3024
/// </summary>
31-
internal interface ILocalSemanticFormattingRule : IFormattingRule
25+
internal interface ILocalSemanticFormattingRule
3226
{
3327
Task<SyntaxNode> ProcessAsync(Document document, SyntaxNode syntaxRoot, CancellationToken cancellationToken);
3428
}
3529

3630
/// <summary>
3731
/// Rules which can affect more than the local document
3832
/// </summary>
39-
internal interface IGlobalSemanticFormattingRule : IFormattingRule
33+
internal interface IGlobalSemanticFormattingRule
4034
{
4135
Task<Solution> ProcessAsync(Document document, SyntaxNode syntaxRoot, CancellationToken cancellationToken);
4236
}

src/Microsoft.DotNet.CodeFormatting/RuleOrderAttribute.cs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,38 @@ namespace Microsoft.DotNet.CodeFormatting
1313
{
1414
[MetadataAttribute]
1515
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
16-
public sealed class RuleOrderAttribute : ExportAttribute
16+
public sealed class SyntaxRuleOrderAttribute : ExportAttribute
1717
{
18-
public RuleOrderAttribute(int order)
19-
: base(typeof(IFormattingRule))
18+
public SyntaxRuleOrderAttribute(int order)
19+
: base(typeof(ISyntaxFormattingRule))
20+
{
21+
Order = order;
22+
}
23+
24+
[DefaultValue(int.MaxValue)]
25+
public int Order { get; private set; }
26+
}
27+
28+
[MetadataAttribute]
29+
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
30+
public sealed class LocalSemanticRuleOrderAttribute : ExportAttribute
31+
{
32+
public LocalSemanticRuleOrderAttribute(int order)
33+
: base(typeof(ILocalSemanticFormattingRule))
34+
{
35+
Order = order;
36+
}
37+
38+
[DefaultValue(int.MaxValue)]
39+
public int Order { get; private set; }
40+
}
41+
42+
[MetadataAttribute]
43+
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
44+
public sealed class GlobalSemanticRuleOrderAttribute : ExportAttribute
45+
{
46+
public GlobalSemanticRuleOrderAttribute(int order)
47+
: base(typeof(IGlobalSemanticFormattingRule))
2048
{
2149
Order = order;
2250
}

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

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

1313
namespace Microsoft.DotNet.CodeFormatting.Rules
1414
{
15-
[RuleOrder(RuleOrder.BraceNewLineRule)]
15+
[SyntaxRuleOrder(SyntaxRuleOrder.BraceNewLineRule)]
1616
internal sealed class BraceNewLineRule : ISyntaxFormattingRule
1717
{
1818
public SyntaxNode Process(SyntaxNode syntaxNode)

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

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

1212
namespace Microsoft.DotNet.CodeFormatting.Rules
1313
{
14-
[RuleOrder(RuleOrder.RemoveExplicitThisRule)]
14+
[LocalSemanticRuleOrder(LocalSemanticRuleOrder.RemoveExplicitThisRule)]
1515
public sealed class ExplicitThisRule : ILocalSemanticFormattingRule
1616
{
1717
private sealed class ExplicitThisRewriter : CSharpSyntaxRewriter

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(RuleOrder.ExplicitVisibilityRule)]
17+
[LocalSemanticRuleOrder(LocalSemanticRuleOrder.ExplicitVisibilityRule)]
1818
internal sealed class ExplicitVisibilityRule : ILocalSemanticFormattingRule
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(RuleOrder.HasCopyrightHeaderFormattingRule)]
16+
[SyntaxRuleOrder(SyntaxRuleOrder.HasCopyrightHeaderFormattingRule)]
1717
internal sealed class HasCopyrightHeaderFormattingRule : ISyntaxFormattingRule
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(RuleOrder.HasNewLineBeforeFirstNamespaceFormattingRule)]
17+
[SyntaxRuleOrder(SyntaxRuleOrder.HasNewLineBeforeFirstNamespaceFormattingRule)]
1818
internal sealed class HasNewLineBeforeFirstNamespaceFormattingRule : ISyntaxFormattingRule
1919
{
2020
public SyntaxNode Process(SyntaxNode syntaxRoot)

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(RuleOrder.HasNewLineBeforeFirstUsingFormattingRule)]
18+
[SyntaxRuleOrder(SyntaxRuleOrder.HasNewLineBeforeFirstUsingFormattingRule)]
1919
internal sealed class HasNewLineBeforeFirstUsingFormattingRule : ISyntaxFormattingRule
2020
{
2121
private const string FormatError = "Could not format using";

0 commit comments

Comments
 (0)