diff --git a/.editorconfig b/.editorconfig index 9345e1b..9a3d9c4 100644 --- a/.editorconfig +++ b/.editorconfig @@ -44,4 +44,21 @@ csharp_new_line_before_else = true csharp_new_line_before_catch = true csharp_new_line_before_finally = true csharp_new_line_before_members_in_object_initializers = true -csharp_new_line_before_members_in_anonymous_types = true \ No newline at end of file +csharp_new_line_before_members_in_anonymous_types = true + +# https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/unnecessary-code-rules + +# Avoid unused private fields +dotnet_diagnostic.CA1823.severity = error + +# Use string.Contains(char) instead of string.Contains(string) with single characters +dotnet_diagnostic.CA1847.severity = error + +# Remove unnecessary import +dotnet_diagnostic.IDE0005.severity = error + +# Private member is unused +dotnet_diagnostic.IDE0051.severity = error + +# Private member is unread +dotnet_diagnostic.IDE0052.severity = error \ No newline at end of file diff --git a/Directory.Build.props b/Directory.Build.props index bfa551f..a2a68f7 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -2,5 +2,7 @@ $(MSBuildThisFileDirectory)\kubernetes-client.ruleset + true + true diff --git a/src/KubernetesClient/Authentication/ExecTokenProvider.cs b/src/KubernetesClient/Authentication/ExecTokenProvider.cs index fba1d59..f66b44a 100644 --- a/src/KubernetesClient/Authentication/ExecTokenProvider.cs +++ b/src/KubernetesClient/Authentication/ExecTokenProvider.cs @@ -1,8 +1,6 @@ -using System.Diagnostics; using System.Net.Http.Headers; using System.Threading; using System.Threading.Tasks; -using k8s.Exceptions; using k8s.KubeConfigModels; using k8s.Autorest; diff --git a/src/KubernetesClient/Autorest/BasicAuthenticationCredentials.cs b/src/KubernetesClient/Autorest/BasicAuthenticationCredentials.cs index eee1370..680d8e5 100644 --- a/src/KubernetesClient/Autorest/BasicAuthenticationCredentials.cs +++ b/src/KubernetesClient/Autorest/BasicAuthenticationCredentials.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -using System; using System.Globalization; using System.Net.Http; using System.Net.Http.Headers; diff --git a/src/KubernetesClient/Autorest/HttpExtensions.cs b/src/KubernetesClient/Autorest/HttpExtensions.cs index 59648c3..a5f6279 100644 --- a/src/KubernetesClient/Autorest/HttpExtensions.cs +++ b/src/KubernetesClient/Autorest/HttpExtensions.cs @@ -3,7 +3,6 @@ using System.Net.Http; using System.Net.Http.Headers; -using System.Text; namespace k8s.Autorest { diff --git a/src/KubernetesClient/Autorest/HttpMessageWrapper.cs b/src/KubernetesClient/Autorest/HttpMessageWrapper.cs index 3695e02..2d91aea 100644 --- a/src/KubernetesClient/Autorest/HttpMessageWrapper.cs +++ b/src/KubernetesClient/Autorest/HttpMessageWrapper.cs @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -using System.Collections.Generic; -using System.Linq; using System.Net.Http.Headers; namespace k8s.Autorest diff --git a/src/KubernetesClient/Autorest/HttpOperationException.cs b/src/KubernetesClient/Autorest/HttpOperationException.cs index 927d1e8..f698ef1 100644 --- a/src/KubernetesClient/Autorest/HttpOperationException.cs +++ b/src/KubernetesClient/Autorest/HttpOperationException.cs @@ -1,10 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -using System; -using System.Net.Http; using System.Runtime.Serialization; -using System.Security.Permissions; namespace k8s.Autorest { diff --git a/src/KubernetesClient/Autorest/HttpOperationResponse.cs b/src/KubernetesClient/Autorest/HttpOperationResponse.cs index 4cdabdc..e05b0f6 100644 --- a/src/KubernetesClient/Autorest/HttpOperationResponse.cs +++ b/src/KubernetesClient/Autorest/HttpOperationResponse.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -using System; using System.Net.Http; namespace k8s.Autorest diff --git a/src/KubernetesClient/Autorest/HttpRequestMessageWrapper.cs b/src/KubernetesClient/Autorest/HttpRequestMessageWrapper.cs index c1a6ef9..efdefa0 100644 --- a/src/KubernetesClient/Autorest/HttpRequestMessageWrapper.cs +++ b/src/KubernetesClient/Autorest/HttpRequestMessageWrapper.cs @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -using System; -using System.Collections.Generic; using System.Net.Http; namespace k8s.Autorest diff --git a/src/KubernetesClient/Autorest/HttpResponseMessageWrapper.cs b/src/KubernetesClient/Autorest/HttpResponseMessageWrapper.cs index 471c855..d124244 100644 --- a/src/KubernetesClient/Autorest/HttpResponseMessageWrapper.cs +++ b/src/KubernetesClient/Autorest/HttpResponseMessageWrapper.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -using System; using System.Net; using System.Net.Http; diff --git a/src/KubernetesClient/Autorest/RestException.cs b/src/KubernetesClient/Autorest/RestException.cs index 1c418cc..d24730f 100644 --- a/src/KubernetesClient/Autorest/RestException.cs +++ b/src/KubernetesClient/Autorest/RestException.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -using System; using System.Runtime.Serialization; namespace k8s.Autorest diff --git a/src/KubernetesClient/Autorest/TokenCredentials.cs b/src/KubernetesClient/Autorest/TokenCredentials.cs index c51b04e..8b7b9f9 100644 --- a/src/KubernetesClient/Autorest/TokenCredentials.cs +++ b/src/KubernetesClient/Autorest/TokenCredentials.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -using System; using System.Net.Http; using System.Threading; using System.Threading.Tasks; diff --git a/src/KubernetesClient/CertUtils.cs b/src/KubernetesClient/CertUtils.cs index 29ad90c..d1881c8 100644 --- a/src/KubernetesClient/CertUtils.cs +++ b/src/KubernetesClient/CertUtils.cs @@ -5,11 +5,12 @@ using Org.BouncyCastle.OpenSsl; using Org.BouncyCastle.Pkcs; using Org.BouncyCastle.Security; using Org.BouncyCastle.X509; +#else +using System.Runtime.InteropServices; +using System.Text; #endif using System.IO; -using System.Runtime.InteropServices; using System.Security.Cryptography.X509Certificates; -using System.Text; namespace k8s { diff --git a/src/KubernetesClient/Kubernetes.ConfigInit.cs b/src/KubernetesClient/Kubernetes.ConfigInit.cs index 72a2d22..7a09cff 100644 --- a/src/KubernetesClient/Kubernetes.ConfigInit.cs +++ b/src/KubernetesClient/Kubernetes.ConfigInit.cs @@ -1,9 +1,5 @@ -using System.Net; using System.Net.Http; using System.Net.Security; -using System.Net.Sockets; -using System.Reflection; -using System.Runtime.InteropServices; using System.Security.Cryptography.X509Certificates; using System.Threading; using k8s.Exceptions; diff --git a/src/KubernetesClient/Kubernetes.cs b/src/KubernetesClient/Kubernetes.cs index deb6e40..2a0275e 100644 --- a/src/KubernetesClient/Kubernetes.cs +++ b/src/KubernetesClient/Kubernetes.cs @@ -31,22 +31,6 @@ namespace k8s public HttpClient HttpClient { get; protected set; } - private IEnumerable HttpMessageHandlers - { - get - { - var handler = FirstMessageHandler; - - while (handler != null) - { - yield return handler; - - DelegatingHandler delegating = handler as DelegatingHandler; - handler = delegating != null ? delegating.InnerHandler : null; - } - } - } - /// /// Reference to the first HTTP handler (which is the start of send HTTP /// pipeline). diff --git a/src/KubernetesClient/KubernetesList.cs b/src/KubernetesClient/KubernetesList.cs index 5282cc3..e8167fd 100644 --- a/src/KubernetesClient/KubernetesList.cs +++ b/src/KubernetesClient/KubernetesList.cs @@ -1,5 +1,3 @@ -using k8s.Autorest; - namespace k8s.Models { public class KubernetesList : IMetadata, IItems diff --git a/src/KubernetesClient/Watcher.cs b/src/KubernetesClient/Watcher.cs index a99f194..f8d4c4e 100644 --- a/src/KubernetesClient/Watcher.cs +++ b/src/KubernetesClient/Watcher.cs @@ -46,6 +46,7 @@ namespace k8s private readonly Func> _streamReaderCreator; private bool disposedValue; + [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "IDE0052:Remove unread private members", Justification = "Used in an async task loop")] private readonly Task _watcherLoop; diff --git a/src/LibKubernetesGenerator/ApiGenerator.cs b/src/LibKubernetesGenerator/ApiGenerator.cs index 241a2f4..afd9172 100644 --- a/src/LibKubernetesGenerator/ApiGenerator.cs +++ b/src/LibKubernetesGenerator/ApiGenerator.cs @@ -1,9 +1,7 @@ using System.Collections.Generic; -using System.IO; using System.Linq; using Microsoft.CodeAnalysis; using NSwag; -using Nustache.Core; namespace LibKubernetesGenerator { diff --git a/src/LibKubernetesGenerator/GeneralNameHelper.cs b/src/LibKubernetesGenerator/GeneralNameHelper.cs index e999790..b34b7dc 100644 --- a/src/LibKubernetesGenerator/GeneralNameHelper.cs +++ b/src/LibKubernetesGenerator/GeneralNameHelper.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; diff --git a/src/LibKubernetesGenerator/GeneratorExecutionContextExt.cs b/src/LibKubernetesGenerator/GeneratorExecutionContextExt.cs index 4e7e894..99bd608 100644 --- a/src/LibKubernetesGenerator/GeneratorExecutionContextExt.cs +++ b/src/LibKubernetesGenerator/GeneratorExecutionContextExt.cs @@ -1,8 +1,6 @@ using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Text; using Nustache.Core; -using System; -using System.Collections.Generic; using System.IO; using System.Text; diff --git a/src/LibKubernetesGenerator/KubernetesClientSourceGenerator.cs b/src/LibKubernetesGenerator/KubernetesClientSourceGenerator.cs index 0195e46..895d25d 100644 --- a/src/LibKubernetesGenerator/KubernetesClientSourceGenerator.cs +++ b/src/LibKubernetesGenerator/KubernetesClientSourceGenerator.cs @@ -4,7 +4,6 @@ using NSwag; using Nustache.Core; using System; using System.Collections.Generic; -using System.Diagnostics; using System.Linq; using System.Reflection; diff --git a/src/LibKubernetesGenerator/ModelExtGenerator.cs b/src/LibKubernetesGenerator/ModelExtGenerator.cs index e7b3d93..13d942d 100644 --- a/src/LibKubernetesGenerator/ModelExtGenerator.cs +++ b/src/LibKubernetesGenerator/ModelExtGenerator.cs @@ -1,10 +1,7 @@ -using System; using System.Collections.Generic; -using System.IO; using System.Linq; using Microsoft.CodeAnalysis; using NSwag; -using Nustache.Core; namespace LibKubernetesGenerator { diff --git a/src/LibKubernetesGenerator/ModelGenerator.cs b/src/LibKubernetesGenerator/ModelGenerator.cs index 94badbc..8c55a0d 100644 --- a/src/LibKubernetesGenerator/ModelGenerator.cs +++ b/src/LibKubernetesGenerator/ModelGenerator.cs @@ -1,7 +1,5 @@ -using System.IO; using Microsoft.CodeAnalysis; using NSwag; -using Nustache.Core; namespace LibKubernetesGenerator { diff --git a/src/LibKubernetesGenerator/UtilHelper.cs b/src/LibKubernetesGenerator/UtilHelper.cs index 6c2cf59..484ea1b 100644 --- a/src/LibKubernetesGenerator/UtilHelper.cs +++ b/src/LibKubernetesGenerator/UtilHelper.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using System.Linq; -using System.Runtime.CompilerServices; using NSwag; using Nustache.Core; diff --git a/tests/KubernetesClient.Tests/StreamDemuxerTests.cs b/tests/KubernetesClient.Tests/StreamDemuxerTests.cs index 86ce98c..befe54a 100644 --- a/tests/KubernetesClient.Tests/StreamDemuxerTests.cs +++ b/tests/KubernetesClient.Tests/StreamDemuxerTests.cs @@ -12,13 +12,6 @@ namespace k8s.Tests { public class StreamDemuxerTests { - private readonly ITestOutputHelper testOutput; - - public StreamDemuxerTests(ITestOutputHelper testOutput) - { - this.testOutput = testOutput; - } - [Fact] public async Task SendDataRemoteCommand() { diff --git a/tests/KubernetesClient.Tests/Util/Informer/Cache/CacheTest.cs b/tests/KubernetesClient.Tests/Util/Informer/Cache/CacheTest.cs index 2597ba4..d97d647 100644 --- a/tests/KubernetesClient.Tests/Util/Informer/Cache/CacheTest.cs +++ b/tests/KubernetesClient.Tests/Util/Informer/Cache/CacheTest.cs @@ -11,7 +11,7 @@ namespace k8s.Tests.Util.Informer.Cache public class CacheTest { [Fact(DisplayName = "Create default cache success")] - private void CreateCacheSuccess() + public void CreateCacheSuccess() { var cache = new Cache(); cache.Should().NotBeNull(); @@ -19,7 +19,7 @@ namespace k8s.Tests.Util.Informer.Cache } [Fact(DisplayName = "Add cache item success")] - private void AddCacheItemSuccess() + public void AddCacheItemSuccess() { var aPod = Helpers.CreatePods(1).First(); var cache = new Cache(); @@ -30,7 +30,7 @@ namespace k8s.Tests.Util.Informer.Cache } [Fact(DisplayName = "Update cache item success")] - private void UpdateCacheItemSuccess() + public void UpdateCacheItemSuccess() { var aPod = Helpers.CreatePods(1).First(); @@ -44,7 +44,7 @@ namespace k8s.Tests.Util.Informer.Cache } [Fact(DisplayName = "Delete cache item success")] - private void DeleteCacheItemSuccess() + public void DeleteCacheItemSuccess() { var aPod = Helpers.CreatePods(1).First(); @@ -58,7 +58,7 @@ namespace k8s.Tests.Util.Informer.Cache } [Fact(DisplayName = "Replace cache items success")] - private void ReplaceCacheItemsSuccess() + public void ReplaceCacheItemsSuccess() { var pods = Helpers.CreatePods(3); var aPod = pods.First(); diff --git a/tests/KubernetesClient.Tests/Util/Informer/Cache/ListerTest.cs b/tests/KubernetesClient.Tests/Util/Informer/Cache/ListerTest.cs index 63e46b7..6a6003a 100644 --- a/tests/KubernetesClient.Tests/Util/Informer/Cache/ListerTest.cs +++ b/tests/KubernetesClient.Tests/Util/Informer/Cache/ListerTest.cs @@ -9,7 +9,7 @@ namespace k8s.Tests.Util.Informer.Cache public class ListerTest { [Fact(DisplayName = "Create default lister success")] - private void CreateListerDefaultsSuccess() + public void CreateListerDefaultsSuccess() { var cache = new Cache(); var lister = new Lister(cache); @@ -18,7 +18,7 @@ namespace k8s.Tests.Util.Informer.Cache } [Fact(DisplayName = "List with null namespace success")] - private void ListNullNamespaceSuccess() + public void ListNullNamespaceSuccess() { var aPod = Helpers.CreatePods(1).First(); var cache = new Cache(); @@ -33,7 +33,7 @@ namespace k8s.Tests.Util.Informer.Cache } [Fact(DisplayName = "List with custom namespace success")] - private void ListCustomNamespaceSuccess() + public void ListCustomNamespaceSuccess() { var aPod = Helpers.CreatePods(1).First(); var cache = new Cache(); @@ -48,7 +48,7 @@ namespace k8s.Tests.Util.Informer.Cache } [Fact(DisplayName = "Get with null namespace success")] - private void GetNullNamespaceSuccess() + public void GetNullNamespaceSuccess() { var aPod = Helpers.CreatePods(1).First(); var cache = new Cache(); @@ -63,7 +63,7 @@ namespace k8s.Tests.Util.Informer.Cache } [Fact(DisplayName = "Get with custom namespace success")] - private void GetCustomNamespaceSuccess() + public void GetCustomNamespaceSuccess() { var aPod = Helpers.CreatePods(1).First(); var cache = new Cache(); @@ -76,7 +76,7 @@ namespace k8s.Tests.Util.Informer.Cache } [Fact(DisplayName = "Set custom namespace success")] - private void SetCustomNamespaceSuccess() + public void SetCustomNamespaceSuccess() { var aPod = Helpers.CreatePods(1).First(); var cache = new Cache();