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

Commit fe6f6c8

Browse files
committed
Merge pull request #222 from davkean/TS
Handle removing "ts_" prefix from fields
2 parents 13cc392 + 3440a62 commit fe6f6c8

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,30 @@ Private _field WithEvents As Integer
331331

332332
Verify(text, expected, languageName: LanguageNames.VisualBasic);
333333
}
334+
335+
[Fact]
336+
public void RemoveTwoLetterThreadStaticPrefix()
337+
{
338+
var text = @"
339+
class C
340+
{
341+
int ts_instance;
342+
static int ts_Static;
343+
[System.ThreadStatic]static int ts_ThreadStatic;
344+
}
345+
";
346+
347+
var expected = @"
348+
class C
349+
{
350+
int _instance;
351+
static int s_static;
352+
[System.ThreadStatic]static int t_threadStatic;
353+
}
354+
";
355+
356+
Verify(text, expected, runFormatter: false);
357+
}
334358
}
335359
}
336360
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ private static string GetNewFieldName(ISymbol fieldSymbol)
9090
name = name.Substring(2);
9191
}
9292

93+
// Some .NET code uses "ts_" prefix for thread static
94+
if (name.Length > 3 && name.StartsWith("ts_", StringComparison.OrdinalIgnoreCase))
95+
{
96+
name = name.Substring(3);
97+
}
98+
9399
if (name.Length == 0)
94100
{
95101
return fieldSymbol.Name;

0 commit comments

Comments
 (0)