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

Commit 7491aea

Browse files
committed
Change header rule order to run later
Fix for Issue #78 When moving the using block outside of a namespace declaration, the copyright header would end up lower in the file. On the next run, it would add another one. This change just changes the copyright rule to run later.
1 parent 5f5ff52 commit 7491aea

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

src/Microsoft.DotNet.CodeFormatting.Tests/Rules/CombinationTest.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,5 +266,38 @@ private void M()
266266

267267
Verify(source, expected, runFormatter: false);
268268
}
269+
270+
[Fact]
271+
public void CSharpHeaderCorrectAfterMovingUsings()
272+
{
273+
274+
var source = @"
275+
namespace Microsoft.Build.UnitTests
276+
{
277+
using System;
278+
using System.Reflection;
279+
280+
public class Test
281+
{
282+
public void RequiredRuntimeAttribute()
283+
{}
284+
}
285+
}";
286+
var expected = @"// header
287+
288+
using System;
289+
using System.Reflection;
290+
291+
namespace Microsoft.Build.UnitTests
292+
{
293+
public class Test
294+
{
295+
public void RequiredRuntimeAttribute()
296+
{ }
297+
}
298+
}";
299+
300+
Verify(source, expected);
301+
}
269302
}
270303
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ namespace Microsoft.DotNet.CodeFormatting.Rules
1313
internal static class SyntaxRuleOrder
1414
{
1515
public const int HasNoCustomCopyrightHeaderFormattingRule = 1;
16-
public const int CopyrightHeaderRule = 2;
17-
public const int UsingLocationFormattingRule = 3;
18-
public const int NewLineAboveFormattingRule = 4;
19-
public const int BraceNewLineRule = 6;
20-
public const int NonAsciiChractersAreEscapedInLiterals = 7;
16+
public const int UsingLocationFormattingRule = 2;
17+
public const int NewLineAboveFormattingRule = 3;
18+
public const int BraceNewLineRule = 4;
19+
public const int NonAsciiChractersAreEscapedInLiterals = 5;
20+
public const int CopyrightHeaderRule = 6;
2121
}
2222

2323
// Please keep these values sorted by number, not rule name.

0 commit comments

Comments
 (0)