Skip to content

Commit 8dd3142

Browse files
committed
Updated to .NET analyzers and fixed warnings
1 parent 7659f83 commit 8dd3142

19 files changed

Lines changed: 80 additions & 101 deletions

‎.editorconfig‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ dotnet_diagnostic.CA1034.severity = none
1414
dotnet_diagnostic.CA1054.severity = none
1515
dotnet_diagnostic.CA2227.severity = none
1616
dotnet_diagnostic.CA1308.severity = none
17+
dotnet_diagnostic.CA1002.severity = none
18+
# TODO: Enable for next major version, EventArgs breaking change:
19+
dotnet_diagnostic.CA1003.severity = none
20+
#
1721
# Sort using and Import directives with System.* appearing first
1822
dotnet_sort_system_directives_first = true
1923
dotnet_style_require_accessibility_modifiers = always:warning
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
using System;
2+
using System.Runtime.CompilerServices;
3+
4+
[assembly: InternalsVisibleTo("SpotifyAPI.Web.Tests")]
5+
[assembly: CLSCompliant(true)]

‎SpotifyAPI.Web.Tests/Http/NetHTTPClientTest.cs‎

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

‎SpotifyAPI.Web.Tests/UtilTests/URIExtensionTest.cs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class URIExtensionTest
1111
public void ApplyParameters_WithoutExistingParameters()
1212
{
1313
var expected = "http://google.com/?hello=world&nice=day";
14-
Uri uri = new Uri("http://google.com/");
14+
var uri = new Uri("http://google.com/");
1515

1616
var parameters = new Dictionary<string, string>
1717
{
@@ -25,7 +25,7 @@ public void ApplyParameters_WithoutExistingParameters()
2525
public void ApplyParameters_WithExistingParameters()
2626
{
2727
var expected = "http://google.com/?existing=paramter&hello=world&nice=day";
28-
Uri uri = new Uri("http://google.com/?existing=paramter");
28+
var uri = new Uri("http://google.com/?existing=paramter");
2929

3030
var parameters = new Dictionary<string, string>
3131
{
@@ -39,7 +39,7 @@ public void ApplyParameters_WithExistingParameters()
3939
public void ApplyParameters_HandlesEscape()
4040
{
4141
var expected = "http://google.com/?existing=paramter&hello=%26world++";
42-
Uri uri = new Uri("http://google.com/?existing=paramter");
42+
var uri = new Uri("http://google.com/?existing=paramter");
4343

4444
var parameters = new Dictionary<string, string>
4545
{

‎SpotifyAPI.Web/Assembly.cs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System;
12
using System.Runtime.CompilerServices;
23

34
[assembly: InternalsVisibleTo("SpotifyAPI.Web.Tests")]
5+
[assembly: CLSCompliant(true)]

‎SpotifyAPI.Web/Clients/APIClient.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace SpotifyAPI.Web
44
{
55
public abstract class APIClient
66
{
7-
public APIClient(IAPIConnector apiConnector)
7+
protected APIClient(IAPIConnector apiConnector)
88
{
99
Ensure.ArgumentNotNull(apiConnector, nameof(apiConnector));
1010

‎SpotifyAPI.Web/Clients/PlaylistsClient.cs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ public Task<FullPlaylist> Create(string userId, PlaylistCreateRequest request)
4949
return API.Post<FullPlaylist>(URLs.UserPlaylists(userId), null, request.BuildBodyParams());
5050
}
5151

52-
public async Task<bool> UploadCover(string playlistId, string base64Jpg)
52+
public async Task<bool> UploadCover(string playlistId, string base64JpgData)
5353
{
5454
Ensure.ArgumentNotNullOrEmptyString(playlistId, nameof(playlistId));
55-
Ensure.ArgumentNotNullOrEmptyString(base64Jpg, nameof(base64Jpg));
55+
Ensure.ArgumentNotNullOrEmptyString(base64JpgData, nameof(base64JpgData));
5656

57-
var statusCode = await API.PutRaw(URLs.PlaylistImages(playlistId), null, base64Jpg).ConfigureAwait(false);
57+
var statusCode = await API.PutRaw(URLs.PlaylistImages(playlistId), null, base64JpgData).ConfigureAwait(false);
5858
return statusCode == HttpStatusCode.Accepted;
5959
}
6060

‎SpotifyAPI.Web/Clients/SpotifyClient.cs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ public SpotifyClient(SpotifyClientConfig config)
2424
Ensure.ArgumentNotNull(config, nameof(config));
2525
if (config.Authenticator == null)
2626
{
27-
throw new NullReferenceException("Authenticator in config is null. Please supply it via `WithAuthenticator` or `WithToken`");
27+
#pragma warning disable CA2208
28+
throw new ArgumentNullException("Authenticator in config is null. Please supply it via `WithAuthenticator` or `WithToken`");
29+
#pragma warning restore CA2208
2830
}
2931

3032
_apiConnector = new APIConnector(

‎SpotifyAPI.Web/Http/APIConnector.cs‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -279,15 +279,13 @@ private static void ProcessErrors(IResponse response)
279279
return;
280280
}
281281

282-
switch (response.StatusCode)
282+
throw response.StatusCode switch
283283
{
284-
case HttpStatusCode.Unauthorized:
285-
throw new APIUnauthorizedException(response);
286-
case (HttpStatusCode)429: // TODO: Remove hack once .netstandard 2.0 is not supported
287-
throw new APITooManyRequestsException(response);
288-
default:
289-
throw new APIException(response);
290-
}
284+
HttpStatusCode.Unauthorized => new APIUnauthorizedException(response),
285+
// TODO: Remove hack once .netstandard 2.0 is not supported
286+
(HttpStatusCode)429 => new APITooManyRequestsException(response),
287+
_ => new APIException(response),
288+
};
291289
}
292290
}
293291
}

‎SpotifyAPI.Web/Http/NetHttpClient.cs‎

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,34 +35,30 @@ public async Task<IResponse> DoRequest(IRequest request)
3535
{
3636
Ensure.ArgumentNotNull(request, nameof(request));
3737

38-
using (HttpRequestMessage requestMsg = BuildRequestMessage(request))
39-
{
40-
var responseMsg = await _httpClient
41-
.SendAsync(requestMsg, HttpCompletionOption.ResponseContentRead)
42-
.ConfigureAwait(false);
38+
using HttpRequestMessage requestMsg = BuildRequestMessage(request);
39+
var responseMsg = await _httpClient
40+
.SendAsync(requestMsg, HttpCompletionOption.ResponseContentRead)
41+
.ConfigureAwait(false);
4342

44-
return await BuildResponse(responseMsg).ConfigureAwait(false);
45-
}
43+
return await BuildResponse(responseMsg).ConfigureAwait(false);
4644
}
4745

4846
private static async Task<IResponse> BuildResponse(HttpResponseMessage responseMsg)
4947
{
5048
Ensure.ArgumentNotNull(responseMsg, nameof(responseMsg));
5149

5250
// We only support text stuff for now
53-
using (var content = responseMsg.Content)
51+
using var content = responseMsg.Content;
52+
var headers = responseMsg.Headers.ToDictionary(header => header.Key, header => header.Value.First());
53+
var body = await responseMsg.Content.ReadAsStringAsync().ConfigureAwait(false);
54+
var contentType = content.Headers?.ContentType?.MediaType;
55+
56+
return new Response(headers)
5457
{
55-
var headers = responseMsg.Headers.ToDictionary(header => header.Key, header => header.Value.First());
56-
var body = await responseMsg.Content.ReadAsStringAsync().ConfigureAwait(false);
57-
var contentType = content.Headers?.ContentType?.MediaType;
58-
59-
return new Response(headers)
60-
{
61-
ContentType = contentType,
62-
StatusCode = responseMsg.StatusCode,
63-
Body = body
64-
};
65-
}
58+
ContentType = contentType,
59+
StatusCode = responseMsg.StatusCode,
60+
Body = body
61+
};
6662
}
6763

6864
private static HttpRequestMessage BuildRequestMessage(IRequest request)

0 commit comments

Comments
 (0)