From 68e5fcb25ebfb60c8c4cc2b0fde658eb9a03cc53 Mon Sep 17 00:00:00 2001 From: Jamie Magee Date: Thu, 4 Aug 2022 10:16:05 -0700 Subject: [PATCH] refactor: remove unused usings --- .../DependencyScopeComparer.cs | 9 +++------ .../DockerReference/DockerReferenceUtility.cs | 7 ++----- .../DockerReference/DockerRegex.cs | 8 +++----- .../Telemetry/Records/PyPiCacheTelemetryRecord.cs | 4 +--- .../BcdeModels/DependencyScope.cs | 10 +++------- .../go/GoComponentDetector.cs | 1 - .../maven/MavenParsingUtilities.cs | 7 +++---- .../vcpkg/VcpkgComponentDetector.cs | 3 --- .../DependencyScopeComparerTests.cs | 4 ---- .../EnvironmentVariableServiceTests.cs | 7 +++---- .../MavenParsingUtilitiesTests.cs | 9 ++------- 11 files changed, 20 insertions(+), 49 deletions(-) diff --git a/src/Microsoft.ComponentDetection.Common/DependencyScopeComparer.cs b/src/Microsoft.ComponentDetection.Common/DependencyScopeComparer.cs index ddd7413df..37e182f03 100644 --- a/src/Microsoft.ComponentDetection.Common/DependencyScopeComparer.cs +++ b/src/Microsoft.ComponentDetection.Common/DependencyScopeComparer.cs @@ -1,13 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.ComponentDetection.Contracts.BcdeModels; +using Microsoft.ComponentDetection.Contracts.BcdeModels; namespace Microsoft.ComponentDetection.Common { /// - /// Merges dependnecy Scope in their order of Priority. - /// Higher priority scope, as indicated by its lower enum value is given precendence. + /// Merges dependnecy Scope in their order of Priority. + /// Higher priority scope, as indicated by its lower enum value is given precendence. /// public class DependencyScopeComparer { diff --git a/src/Microsoft.ComponentDetection.Common/DockerReference/DockerReferenceUtility.cs b/src/Microsoft.ComponentDetection.Common/DockerReference/DockerReferenceUtility.cs index 0505d6fe7..2bc4e9bb1 100644 --- a/src/Microsoft.ComponentDetection.Common/DockerReference/DockerReferenceUtility.cs +++ b/src/Microsoft.ComponentDetection.Common/DockerReference/DockerReferenceUtility.cs @@ -1,7 +1,4 @@ using Microsoft.ComponentDetection.Contracts; -using System; -using System.Collections.Generic; -using System.Linq; using System.Text.RegularExpressions; // transcribed from https://github.com/containers/image/blob/c1a5f92d0ebbf9e0bf187b3353dd400472b388eb/docker/reference/reference.go @@ -67,7 +64,7 @@ public static DockerReference ParseQualifiedName(string qualifiedName) } Reference reference = new Reference(); - + var nameMatch = DockerRegex.AnchoredNameRegexp.Match(name).Groups; if (nameMatch.Count == 3) { @@ -172,4 +169,4 @@ private static DockerReference CreateDockerReference(Reference options) return DockerReference.CreateDockerReference(options.Repository, options.Domain, options.Digest, options.Tag); } } -} \ No newline at end of file +} diff --git a/src/Microsoft.ComponentDetection.Common/DockerReference/DockerRegex.cs b/src/Microsoft.ComponentDetection.Common/DockerReference/DockerRegex.cs index 780460668..1d51c6251 100644 --- a/src/Microsoft.ComponentDetection.Common/DockerReference/DockerRegex.cs +++ b/src/Microsoft.ComponentDetection.Common/DockerReference/DockerRegex.cs @@ -1,5 +1,3 @@ -using System; -using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; @@ -71,10 +69,10 @@ public static Regex Capture(params Regex[] regexps) DomainComponentRegexp, Optional( Repeated( - new Regex(@"\."), + new Regex(@"\."), DomainComponentRegexp)), Optional( - new Regex(":"), + new Regex(":"), new Regex("[0-9]+"))); public static Regex AnchoredDigestRegexp = Anchored(DigestRegexp); @@ -107,4 +105,4 @@ public static Regex Capture(params Regex[] regexps) public static Regex AnchoredIdentifierRegexp = Anchored(IdentifierRegexp); } -} \ No newline at end of file +} diff --git a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/PyPiCacheTelemetryRecord.cs b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/PyPiCacheTelemetryRecord.cs index 39ba28e89..4102fc25e 100644 --- a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/PyPiCacheTelemetryRecord.cs +++ b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/PyPiCacheTelemetryRecord.cs @@ -1,6 +1,4 @@ -using System.Net; - -namespace Microsoft.ComponentDetection.Common.Telemetry.Records +namespace Microsoft.ComponentDetection.Common.Telemetry.Records { public class PypiCacheTelemetryRecord : BaseDetectionTelemetryRecord { diff --git a/src/Microsoft.ComponentDetection.Contracts/BcdeModels/DependencyScope.cs b/src/Microsoft.ComponentDetection.Contracts/BcdeModels/DependencyScope.cs index 4f6774f1f..5c72f728c 100644 --- a/src/Microsoft.ComponentDetection.Contracts/BcdeModels/DependencyScope.cs +++ b/src/Microsoft.ComponentDetection.Contracts/BcdeModels/DependencyScope.cs @@ -1,11 +1,7 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Microsoft.ComponentDetection.Contracts.BcdeModels +namespace Microsoft.ComponentDetection.Contracts.BcdeModels { - /// Used to communicate Dependency Scope of Component. - /// Currently only populated for Maven component. + /// Used to communicate Dependency Scope of Component. + /// Currently only populated for Maven component. /// The values are ordered in terms of priority, which is used to resolve the scope for duplicate component while merging them. /// public enum DependencyScope diff --git a/src/Microsoft.ComponentDetection.Detectors/go/GoComponentDetector.cs b/src/Microsoft.ComponentDetection.Detectors/go/GoComponentDetector.cs index 705216a91..973bdec64 100644 --- a/src/Microsoft.ComponentDetection.Detectors/go/GoComponentDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/go/GoComponentDetector.cs @@ -3,7 +3,6 @@ using System.Composition; using System.IO; using System.Linq; -using System.Security.Cryptography.X509Certificates; using System.Text.RegularExpressions; using System.Threading.Tasks; using Microsoft.ComponentDetection.Common.Telemetry.Records; diff --git a/src/Microsoft.ComponentDetection.Detectors/maven/MavenParsingUtilities.cs b/src/Microsoft.ComponentDetection.Detectors/maven/MavenParsingUtilities.cs index 610adc433..70058f46f 100644 --- a/src/Microsoft.ComponentDetection.Detectors/maven/MavenParsingUtilities.cs +++ b/src/Microsoft.ComponentDetection.Detectors/maven/MavenParsingUtilities.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Net; using System.Text.RegularExpressions; using Microsoft.ComponentDetection.Contracts; using Microsoft.ComponentDetection.Contracts.BcdeModels; @@ -10,7 +9,7 @@ namespace Microsoft.ComponentDetection.Detectors.Maven { public static class MavenParsingUtilities { - private static readonly Dictionary MavenScopeToDependencyScopeMapping = new Dictionary() + private static readonly Dictionary MavenScopeToDependencyScopeMapping = new Dictionary() { { "compile", DependencyScope.MavenCompile }, { "provided", DependencyScope.MavenProvided }, @@ -60,8 +59,8 @@ private static (string groupId, string artifactId, string version, bool? isDevel { dependencyScope = MavenScopeToDependencyScopeMapping.TryGetValue( Regex.Match(results[4], @"^([\w]+)").Value, - out dependencyScope) - ? dependencyScope + out dependencyScope) + ? dependencyScope : throw new InvalidOperationException($"Invalid scope ('{results[4]}') found for '{mavenComponentString}' found in generated dependency graph."); isDevDependency = dependencyScope == DependencyScope.MavenTest; } diff --git a/src/Microsoft.ComponentDetection.Detectors/vcpkg/VcpkgComponentDetector.cs b/src/Microsoft.ComponentDetection.Detectors/vcpkg/VcpkgComponentDetector.cs index 60a8e99c6..2e31046ea 100644 --- a/src/Microsoft.ComponentDetection.Detectors/vcpkg/VcpkgComponentDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/vcpkg/VcpkgComponentDetector.cs @@ -3,10 +3,7 @@ using System.Composition; using System.IO; using System.Linq; -using System.Text.RegularExpressions; using System.Threading.Tasks; -using Microsoft.ComponentDetection.Common; -using Microsoft.ComponentDetection.Common.Telemetry.Records; using Microsoft.ComponentDetection.Contracts; using Microsoft.ComponentDetection.Contracts.Internal; using Microsoft.ComponentDetection.Contracts.TypedComponent; diff --git a/test/Microsoft.ComponentDetection.Common.Tests/DependencyScopeComparerTests.cs b/test/Microsoft.ComponentDetection.Common.Tests/DependencyScopeComparerTests.cs index 0bc7f0205..a68f825cb 100644 --- a/test/Microsoft.ComponentDetection.Common.Tests/DependencyScopeComparerTests.cs +++ b/test/Microsoft.ComponentDetection.Common.Tests/DependencyScopeComparerTests.cs @@ -1,11 +1,7 @@ using FluentAssertions; -using FluentAssertions.Primitives; using Microsoft.ComponentDetection.Contracts.BcdeModels; using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Faker; using static Microsoft.ComponentDetection.Common.DependencyScopeComparer; -using System.Linq; namespace Microsoft.ComponentDetection.Common.Tests { diff --git a/test/Microsoft.ComponentDetection.Common.Tests/EnvironmentVariableServiceTests.cs b/test/Microsoft.ComponentDetection.Common.Tests/EnvironmentVariableServiceTests.cs index 7e8fd2ffd..6ff7dd50a 100644 --- a/test/Microsoft.ComponentDetection.Common.Tests/EnvironmentVariableServiceTests.cs +++ b/test/Microsoft.ComponentDetection.Common.Tests/EnvironmentVariableServiceTests.cs @@ -1,5 +1,4 @@ -using Microsoft.ComponentDetection.Common; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; using System; @@ -26,14 +25,14 @@ public void TestCleanup() [TestMethod] public void DoesEnvironmentVariableExist_ChecksAreCaseInsensitive() - { + { Assert.IsFalse(testSubject.DoesEnvironmentVariableExist("THIS_ENVIRONMENT_VARIABLE_DOES_NOT_EXIST")); Assert.IsTrue(testSubject.DoesEnvironmentVariableExist(MyEnvVar)); Assert.IsTrue(testSubject.DoesEnvironmentVariableExist(MyEnvVar.ToLower())); Assert.IsTrue(testSubject.DoesEnvironmentVariableExist(MyEnvVar.ToUpper())); } - + [TestMethod] public void GetEnvironmentVariable_returnNullIfVariableDoesNotExist() { diff --git a/test/Microsoft.ComponentDetection.Detectors.Tests/MavenParsingUtilitiesTests.cs b/test/Microsoft.ComponentDetection.Detectors.Tests/MavenParsingUtilitiesTests.cs index 1574e3e06..5692d9fde 100644 --- a/test/Microsoft.ComponentDetection.Detectors.Tests/MavenParsingUtilitiesTests.cs +++ b/test/Microsoft.ComponentDetection.Detectors.Tests/MavenParsingUtilitiesTests.cs @@ -1,13 +1,8 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -using Microsoft.ComponentDetection.Detectors.Maven; using System; -using System.Collections.Generic; -using System.Text; using static Microsoft.ComponentDetection.Detectors.Maven.MavenParsingUtilities; using Microsoft.ComponentDetection.Contracts.TypedComponent; -using FluentAssertions.Collections; using Microsoft.ComponentDetection.Contracts.BcdeModels; -using Microsoft.ComponentDetection.Contracts; namespace Microsoft.ComponentDetection.Detectors.Tests { @@ -26,12 +21,12 @@ public void GenerateDetectedComponentAndIsDeveDependencyAndDependencyScope_Happy Assert.IsNotNull(componentAndMetaData.Component); Assert.IsNotNull(componentAndMetaData.IsDevelopmentDependency); Assert.IsNotNull(componentAndMetaData.dependencyScope); - + var actualComponent = (MavenComponent)componentAndMetaData.Component.Component; Assert.IsInstanceOfType(actualComponent, typeof(MavenComponent)); var expectedComponent = new MavenComponent("org.apache.maven", "maven-artifact", "3.6.1-SNAPSHOT"); - + Assert.AreEqual(expectedComponent.ArtifactId, actualComponent.ArtifactId); Assert.AreEqual(expectedComponent.GroupId, actualComponent.GroupId); Assert.AreEqual(expectedComponent.Version, actualComponent.Version);