Skip to content

Commit 84d8012

Browse files
committed
Enable .NET analyzers and fix issues
1 parent 28a6b38 commit 84d8012

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

src/Directory.Build.props

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
<IncludeSymbols>true</IncludeSymbols>
1111
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
1212
<EmbedUntrackedSources>true</EmbedUntrackedSources>
13+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
1314
</PropertyGroup>
1415

15-
<ItemGroup>
16-
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All"/>
17-
</ItemGroup>
16+
<PropertyGroup Label="Analysis rules">
17+
<AnalysisLevel>latest-Recommended</AnalysisLevel>
18+
</PropertyGroup>
1819

1920
</Project>

src/TimeZoneConverter.DataBuilder/DataExtractor.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,14 @@ public static List<string> LoadAliases(string cldrDirectoryPath, IDictionary<str
7777

7878
foreach (var link in tzdbLinks)
7979
{
80-
if (!data.ContainsKey(link.Value))
80+
if (!data.TryGetValue(link.Value, out string? value))
8181
{
82-
data.Add(link.Value, link.Key);
82+
value = link.Key;
83+
data.Add(link.Value, value);
8384
continue;
8485
}
8586

86-
if (data[link.Value].Trim().Split().Contains(link.Key))
87+
if (value.Trim().Split().Contains(link.Key))
8788
{
8889
continue;
8990
}
@@ -109,7 +110,7 @@ public static IDictionary<string, string> LoadTzdbLinks(string tzdbDirectoryPath
109110
foreach (var file in dataFiles)
110111
{
111112
var lines = File.ReadLines(Path.Combine(tzdbDirectoryPath, file));
112-
foreach (var line in lines.Where(x => x.StartsWith("Link")))
113+
foreach (var line in lines.Where(x => x.StartsWith("Link", StringComparison.Ordinal)))
113114
{
114115
var parts = line.Trim().Split(Array.Empty<char>(), StringSplitOptions.RemoveEmptyEntries);
115116
var target = parts[1];
@@ -125,7 +126,7 @@ public static IList<string> LoadTzdbTerritories(string tzdbDirectoryPath)
125126
{
126127
var data = new Dictionary<string, IList<string>>();
127128
var lines = File.ReadLines(Path.Combine(tzdbDirectoryPath, "zone.tab"));
128-
foreach (var line in lines.Where(x => !x.StartsWith("#")))
129+
foreach (var line in lines.Where(x => !x.StartsWith('#')))
129130
{
130131
var parts = line.Trim().Split('\t');
131132
var territory = parts[0];

src/TimeZoneConverter.DataBuilder/Downloader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static async Task DownloadRailsTzMappingAsync(string dir)
3131

3232
public static string GetTempDir()
3333
{
34-
return Path.GetTempPath() + Path.GetRandomFileName().Substring(0, 8);
34+
return string.Concat(Path.GetTempPath(), Path.GetRandomFileName().AsSpan(0, 8));
3535
}
3636

3737
private static async Task DownloadAsync(string url, string dir)

src/TimeZoneConverter.Posix/PosixTimeZone.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ namespace TimeZoneConverter.Posix;
1111
/// </summary>
1212
public static class PosixTimeZone
1313
{
14+
private static readonly char[] PosixAbbreviationSplitChars = {'+', '-'};
15+
1416
/// <summary>
1517
/// Generates a POSIX time zone string from a <see cref="TimeZoneInfo" /> object, for the current year.
1618
/// Note - only uses only the <see cref="TimeZoneInfo.Id" /> property from the object.
@@ -130,7 +132,7 @@ public static string FromIanaTimeZoneName(string timeZoneName, int year)
130132

131133
private static string GetPosixAbbreviation(string abbreviation)
132134
{
133-
return abbreviation.IndexOfAny(new[] {'+', '-'}) != -1 ? "<" + abbreviation + ">" : abbreviation;
135+
return abbreviation.IndexOfAny(PosixAbbreviationSplitChars) != -1 ? "<" + abbreviation + ">" : abbreviation;
134136
}
135137

136138
private static string GetPosixOffsetString(Offset offset)

0 commit comments

Comments
 (0)