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

Commit e52f950

Browse files
author
Lakshmi Priya Sekar
committed
Make Encoding changes and add more rename tests
- Delete encoding rule. - Check for right encoding in the before and after running all rules in FormattingEngine. - Add more tests to Rename.
1 parent 3dcea06 commit e52f950

File tree

5 files changed

+15
-30
lines changed

5 files changed

+15
-30
lines changed

build.cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ IF EXIST "%~dp0src\packages" goto build
1616

1717
:build
1818

19-
"%ProgramFiles(x86)%\MSBuild\14.0\bin\MSBuild.exe" %SOLUTION_PATH% /p:OutDir="%~dp0bin " /nologo /m /v:m /flp:verbosity=normal %*
19+
"%ProgramFiles(x86)%\MSBuild\14.0\bin\MSBuild.exe" %SOLUTION_PATH% /p:OutDir="%~dp0bin " /nologo /m /v:m /flp:verbosity=normal %*

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class T
1919
// some trivia
2020
private static int m_z;
2121
// some trivia
22-
private int k = 1, m_s = 2;
22+
private int k = 1, m_s = 2, rsk_yz = 3, x_y_z;
2323
// some trivia
2424
[ThreadStatic] static int r;
2525
[ThreadStaticAttribute] static int b_r;
@@ -33,7 +33,7 @@ class T
3333
// some trivia
3434
private static int s_z;
3535
// some trivia
36-
private int _k = 1, _s = 2;
36+
private int _k = 1, _s = 2, _rsk_yz = 3, _y_z;
3737
// some trivia
3838
[ThreadStatic]
3939
static int t_r;

src/Microsoft.DotNet.CodeFormatting/FormattingEngineImplementation.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
using System.ComponentModel.Composition;
77
using System.IO;
88
using System.Linq;
9+
using System.Text;
910
using System.Threading;
1011
using System.Threading.Tasks;
1112

1213
using Microsoft.CodeAnalysis;
14+
using Microsoft.CodeAnalysis.Text;
1315

1416
namespace Microsoft.DotNet.CodeFormatting
1517
{
@@ -70,10 +72,19 @@ private async Task<bool> ShouldBeProcessedAsync(Document document)
7072

7173
private async Task<Document> RewriteDocumentAsync(Document document, CancellationToken cancellationToken)
7274
{
75+
var docText = await document.GetTextAsync();
76+
var originalEncoding = docText.Encoding;
7377
foreach (var rule in _rules)
7478
document = await rule.ProcessAsync(document, cancellationToken);
7579

76-
return document;
80+
return await ChangeEncoding(document, originalEncoding);
81+
}
82+
83+
private async Task<Document> ChangeEncoding(Document document, Encoding encoding)
84+
{
85+
var text = await document.GetTextAsync();
86+
var newText = SourceText.From(text.ToString(), encoding);
87+
return document.WithText(newText);
7788
}
7889
}
7990
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@
9595
<Compile Include="Rules\HasNoNewLineBeforeEndBraceFormattingRule.cs" />
9696
<Compile Include="Rules\HasNoCustomCopyrightHeaderFormattingRule.cs" />
9797
<Compile Include="Rules\HasPrivateAccessorOnFieldNamesFormattingRule.cs" />
98-
<Compile Include="Rules\HasRightEncodingFormattingRule.cs" />
9998
<Compile Include="Rules\HasUnderScoreInPrivateFieldNamesFormattingRule.cs" />
10099
<Compile Include="Rules\HasUsingsOutsideOfNamespaceFormattingRule.cs" />
101100
<Compile Include="Rules\IsFormattedFormattingRule.cs" />

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

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)