Skip to content

Commit 113e2ea

Browse files
Merge pull request #764 from jimmylewis/warnings
Address build warnings from .NET 8 analyzers
2 parents 65fc85e + 1c42dcb commit 113e2ea

10 files changed

Lines changed: 45 additions & 4 deletions

File tree

src/LibraryManager.Contracts/CompletionSet.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,13 @@ public bool Equals(CompletionItem other)
140140
/// </summary>
141141
public override int GetHashCode()
142142
{
143+
#if NET8_0_OR_GREATER
144+
return HashCode.Combine(InsertionText, Description);
145+
#else
143146
// Much of the time, InsertionText == DisplayText, so XORing those would just cancel out.
147+
// So don't include DisplayText in the hash code.
144148
return InsertionText.GetHashCode() ^ Description.GetHashCode();
149+
#endif
145150
}
146151

147152
/// <summary>

src/LibraryManager/Cache/CacheFileMetadata.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ public override bool Equals(object obj)
4646
/// <inheritdoc />
4747
public override int GetHashCode()
4848
{
49+
#if NET8_0_OR_GREATER
50+
return DestinationPath.GetHashCode(StringComparison.Ordinal); // this should be a unique identifier
51+
#else
4952
return DestinationPath.GetHashCode(); // this should be a unique identifier
53+
#endif
5054
}
5155
}
5256
}

src/LibraryManager/FileIdentifier.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System;
5-
using System.Collections.Generic;
65

76
namespace Microsoft.Web.LibraryManager
87
{
@@ -35,10 +34,14 @@ public override bool Equals(object obj)
3534

3635
public override int GetHashCode()
3736
{
37+
#if NET8_0_OR_GREATER
38+
return HashCode.Combine(Path, Version);
39+
#else
3840
int hashPath = Path == null ? 0 : Path.GetHashCode();
3941
int hashVersion = Version == null ? 0 : Version.GetHashCode();
4042

4143
return hashPath ^ hashVersion;
44+
#endif
4245
}
4346
}
4447
}

src/LibraryManager/Minimatch/Minimatcher.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,13 @@ private bool Match(string input, bool partial)
825825
// On other platforms, \ is a valid (albeit bad) filename char.
826826

827827
if (options.AllowWindowsPaths)
828+
{
829+
#if NET8_0_OR_GREATER
830+
input = input.Replace("\\", "/", StringComparison.Ordinal);
831+
#else
828832
input = input.Replace("\\", "/");
833+
#endif
834+
}
829835

830836
// treat the test path as a set of pathparts.
831837
var f = slashSplit.Split(input);

src/LibraryManager/Providers/BaseProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,8 @@ protected virtual string GetCachedFileLocalPath(ILibraryInstallationState state,
439439
/// <summary>
440440
/// Copies ILibraryInstallationState files to cache
441441
/// </summary>
442-
/// <param name="state"></param>
443-
/// <param name="library"></param>
442+
/// <param name="state">Desired install state to cache</param>
443+
/// <param name="library">Library resolved from provider</param>
444444
/// <param name="cancellationToken"></param>
445445
/// <returns></returns>
446446
private async Task<ILibraryOperationResult> RefreshCacheAsync(ILibraryInstallationState state, ILibrary library, CancellationToken cancellationToken)

src/LibraryManager/Providers/Cdnjs/CdnjsCatalog.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ public async Task<CompletionSet> GetLibraryCompletionSetAsync(string value, int
5050
Length = value.Length
5151
};
5252

53+
#if NET8_0_OR_GREATER
54+
int at = value.IndexOf('@', StringComparison.Ordinal);
55+
#else
5356
int at = value.IndexOf('@');
57+
#endif
5458
string name = at > -1 ? value.Substring(0, at) : value;
5559

5660
var completions = new List<CompletionItem>();

src/LibraryManager/Providers/FileSystem/FileSystemCatalog.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Collections.Generic;
6+
using System.Diagnostics.CodeAnalysis;
67
using System.IO;
78
using System.Linq;
89
using System.Threading;
@@ -37,6 +38,7 @@ public FileSystemCatalog(FileSystemProvider provider, bool underTest = false)
3738
/// <param name="value">The current state of the library ID.</param>
3839
/// <param name="caretPosition">The caret position inside the <paramref name="value" />.</param>
3940
/// <returns></returns>
41+
[SuppressMessage("Globalization", "CA1307:Specify StringComparison for clarity", Justification = "Searching for characters which are not cased")]
4042
public Task<CompletionSet> GetLibraryCompletionSetAsync(string value, int caretPosition)
4143
{
4244
if (value.Contains("://"))
@@ -122,6 +124,7 @@ public Task<CompletionSet> GetLibraryCompletionSetAsync(string value, int caretP
122124
/// <returns>
123125
/// An instance of <see cref="Microsoft.Web.LibraryManager.Contracts.ILibraryGroup" /> or <code>null</code>.
124126
/// </returns>
127+
[SuppressMessage("Globalization", "CA1307:Specify StringComparison for clarity", Justification = "Searching for characters which are not cased")]
125128
public async Task<ILibrary> GetLibraryAsync(string libraryName, string version, CancellationToken cancellationToken)
126129
{
127130
ILibrary library;

src/LibraryManager/Providers/jsDelivr/JsDelivrCatalog.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Collections.Generic;
6+
using System.Diagnostics.CodeAnalysis;
67
using System.IO;
78
using System.Linq;
89
using System.Threading;
@@ -343,6 +344,7 @@ private async Task<IEnumerable<string>> GetGithubLibraryVersionsAsync(string nam
343344
return versions;
344345
}
345346

347+
[SuppressMessage("Globalization", "CA1307:Specify StringComparison for clarity", Justification = "Searching for characters which are not cased")]
346348
public static bool IsGitHub(string libraryId)
347349
{
348350
if (libraryId == null || libraryId.StartsWith("@", StringComparison.Ordinal))

src/LibraryManager/RelativePathEqualityComparer.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System;
45
using System.Collections.Generic;
56
using System.IO;
67

@@ -37,7 +38,11 @@ public bool Equals(string x, string y)
3738
/// <inheritdoc />
3839
public int GetHashCode(string obj)
3940
{
41+
#if NET8_0_OR_GREATER
42+
return NormalizePath(obj)?.GetHashCode(StringComparison.Ordinal) ?? 0;
43+
#else
4044
return NormalizePath(obj)?.GetHashCode() ?? 0;
45+
#endif
4146
}
4247

4348
private string NormalizePath(string path)

src/LibraryManager/SemanticVersion.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ public class SemanticVersion : IComparable<SemanticVersion>, IEquatable<Semantic
4444

4545
private SemanticVersion(string originalText)
4646
{
47+
#if NET8_0_OR_GREATER
48+
_hashCode = originalText?.GetHashCode(StringComparison.Ordinal) ?? 0;
49+
#else
4750
_hashCode = originalText?.GetHashCode() ?? 0;
51+
#endif
4852
OriginalText = originalText;
4953
}
5054

@@ -57,8 +61,13 @@ public static SemanticVersion Parse(string value)
5761
return ver;
5862
}
5963

64+
#if NET8_0_OR_GREATER
65+
int prereleaseStart = value.IndexOf('-', StringComparison.Ordinal);
66+
int buildMetadataStart = value.IndexOf('+', StringComparison.Ordinal);
67+
#else
6068
int prereleaseStart = value.IndexOf('-');
6169
int buildMetadataStart = value.IndexOf('+');
70+
#endif
6271

6372
//If the index of the build metadata marker (+) is greater than the index of the prerelease marker (-)
6473
// then it is necessarily found in the string because if both were not found they'd be equal
@@ -197,7 +206,7 @@ public int CompareTo(SemanticVersion other)
197206
}
198207

199208
/// <summary>
200-
/// Returns whether the semantic verisons are equal. This includes comparing the build metadata, and does not provide semantic equivalence.
209+
/// Returns whether the semantic versions are equal. This includes comparing the build metadata, and does not provide semantic equivalence.
201210
/// </summary>
202211
public bool Equals(SemanticVersion other)
203212
{

0 commit comments

Comments
 (0)