Skip to content

Commit 74cbb00

Browse files
committed
Address PR comments.
1 parent 16f557c commit 74cbb00

File tree

11 files changed

+20
-27
lines changed

11 files changed

+20
-27
lines changed

src/GitVersion.Core.Tests/Helpers/DateFormatterTests.cs renamed to src/GitVersion.Core.Tests/Formatting/DateFormatterTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using GitVersion.Helpers;
1+
using GitVersion.Formatting;
22

3-
namespace GitVersion.Tests.Helpers;
3+
namespace GitVersion.Core.Tests.Formatting;
44

55
[TestFixture]
66
public class DateFormatterTests

src/GitVersion.Core.Tests/Helpers/FormattableFormatterTests.cs renamed to src/GitVersion.Core.Tests/Formatting/FormattableFormatterTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using GitVersion.Helpers;
1+
using GitVersion.Formatting;
22

3-
namespace GitVersion.Tests.Helpers;
3+
namespace GitVersion.Core.Tests.Formatting;
44

55
[TestFixture]
66
public class FormattableFormatterTests

src/GitVersion.Core.Tests/Helpers/NumericFormatterTests.cs renamed to src/GitVersion.Core.Tests/Formatting/NumericFormatterTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using GitVersion.Helpers;
1+
using GitVersion.Formatting;
22

3-
namespace GitVersion.Tests.Helpers;
3+
namespace GitVersion.Core.Tests.Formatting;
44

55
[TestFixture]
66
public class NumericFormatterTests

src/GitVersion.Core.Tests/Helpers/StringFormatterTests.cs renamed to src/GitVersion.Core.Tests/Formatting/StringFormatterTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using GitVersion.Helpers;
1+
using GitVersion.Formatting;
22

3-
namespace GitVersion.Tests.Helpers;
3+
namespace GitVersion.Core.Tests.Formatting;
44

55
[TestFixture]
66
public class StringFormatterTests

src/GitVersion.Core/Helpers/DateFormatter.cs renamed to src/GitVersion.Core/Formatting/DateFormatter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System.Globalization;
22

3-
namespace GitVersion.Helpers;
3+
namespace GitVersion.Formatting;
44

55
internal class DateFormatter : IValueFormatter
66
{

src/GitVersion.Core/Helpers/FormattableFormatter.cs renamed to src/GitVersion.Core/Formatting/FormattableFormatter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System.Globalization;
22

3-
namespace GitVersion.Helpers;
3+
namespace GitVersion.Formatting;
44

55
internal class FormattableFormatter : IValueFormatter
66
{

src/GitVersion.Core/Helpers/IValueFormatter.cs renamed to src/GitVersion.Core/Formatting/IValueFormatter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace GitVersion.Helpers;
1+
namespace GitVersion.Formatting;
22

33
internal interface IValueFormatter
44
{

src/GitVersion.Core/Helpers/NumericFormatter.cs renamed to src/GitVersion.Core/Formatting/NumericFormatter.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System.Globalization;
22

3-
namespace GitVersion.Helpers;
3+
namespace GitVersion.Formatting;
44

55
internal class NumericFormatter : IValueFormatter
66
{
@@ -11,9 +11,7 @@ public bool TryFormat(object? value, string format, out string result)
1111
result = string.Empty;
1212

1313
if (value is not string s)
14-
{
1514
return false;
16-
}
1715

1816
// Integer formatting
1917
if (format.All(char.IsDigit) && int.TryParse(s, out var i))
@@ -23,7 +21,7 @@ public bool TryFormat(object? value, string format, out string result)
2321
}
2422

2523
// Hexadecimal formatting
26-
if ((format.StartsWith('X') || format.StartsWith('x')) && int.TryParse(s, out var hex))
24+
if (format.StartsWith("X", StringComparison.OrdinalIgnoreCase) && int.TryParse(s, out var hex))
2725
{
2826
result = hex.ToString(format, CultureInfo.InvariantCulture);
2927
return true;

src/GitVersion.Core/Helpers/StringFormatter.cs renamed to src/GitVersion.Core/Formatting/StringFormatter.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System.Globalization;
22
using GitVersion.Extensions;
33

4-
namespace GitVersion.Helpers;
4+
namespace GitVersion.Formatting;
55

66
internal class StringFormatter : IValueFormatter
77
{
@@ -34,9 +34,7 @@ public bool TryFormat(object? value, string format, out string result)
3434
return true;
3535
case "s":
3636
if (stringValue.Length == 1)
37-
{
3837
result = stringValue.ToUpperInvariant();
39-
}
4038
else
4139
{
4240
result = char.ToUpperInvariant(stringValue[0]) + stringValue[1..].ToLowerInvariant();
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
namespace GitVersion.Helpers;
1+
namespace GitVersion.Formatting;
22

33
internal static class ValueFormatter
44
{
5-
private static readonly List<IValueFormatter> _formatters =
5+
private static readonly List<IValueFormatter> formatters =
66
[
77
new StringFormatter(),
88
new FormattableFormatter(),
@@ -15,22 +15,18 @@ public static bool TryFormat(object? value, string format, out string result)
1515
result = string.Empty;
1616

1717
if (value is null)
18-
{
1918
return false;
20-
}
2119

22-
foreach (var formatter in _formatters.OrderBy(f => f.Priority))
20+
foreach (var formatter in formatters.OrderBy(f => f.Priority))
2321
{
2422
if (formatter.TryFormat(value, format, out result))
25-
{
2623
return true;
27-
}
2824
}
2925

3026
return false;
3127
}
3228

33-
public static void RegisterFormatter(IValueFormatter formatter) => _formatters.Add(formatter);
29+
public static void RegisterFormatter(IValueFormatter formatter) => formatters.Add(formatter);
3430

35-
public static void RemoveFormatter<T>() where T : IValueFormatter => _formatters.RemoveAll(f => f is T);
31+
public static void RemoveFormatter<T>() where T : IValueFormatter => formatters.RemoveAll(f => f is T);
3632
}

0 commit comments

Comments
 (0)