Skip to content

Commit 85eaacd

Browse files
SCAN4NET-256 Fix quality gate (#2327)
1 parent 293b9f5 commit 85eaacd

File tree

5 files changed

+19
-56
lines changed

5 files changed

+19
-56
lines changed

Tests/SonarScanner.MSBuild.PreProcessor.Test/ArgumentProcessorTests.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,8 @@
1818
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1919
*/
2020

21-
using System;
22-
using System.IO;
2321
using System.Runtime.InteropServices;
24-
using FluentAssertions;
25-
using Microsoft.VisualStudio.TestTools.UnitTesting;
26-
using NSubstitute;
2722
using NSubstitute.ExceptionExtensions;
28-
using SonarScanner.MSBuild.Common;
29-
using TestUtilities;
3023

3124
namespace SonarScanner.MSBuild.PreProcessor.Test;
3225

@@ -50,7 +43,7 @@ public void PreArgProc_MissingArguments()
5043
act.Should().ThrowExactly<ArgumentNullException>();
5144

5245
// 2. required argument missing
53-
logger = CheckProcessingFails( /* no command line args */);
46+
logger = CheckProcessingFails(/* no command line args */);
5447
logger.AssertSingleErrorExists("/key:"); // we expect error with info about the missing required parameter, which should include the primary alias
5548
logger.AssertErrorsLogged(1);
5649

Tests/SonarScanner.MSBuild.PreProcessor.Test/CacheProcessorTests.cs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,8 @@
1818
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1919
*/
2020

21-
using System;
22-
using System.Collections.Generic;
23-
using System.IO;
24-
using System.Linq;
25-
using System.Text;
26-
using System.Threading.Tasks;
27-
using FluentAssertions;
2821
using Google.Protobuf;
29-
using Microsoft.VisualStudio.TestTools.UnitTesting;
30-
using NSubstitute;
31-
using SonarScanner.MSBuild.Common;
32-
using SonarScanner.MSBuild.Common.Interfaces;
3322
using SonarScanner.MSBuild.PreProcessor.Protobuf;
34-
using TestUtilities;
3523

3624
namespace SonarScanner.MSBuild.PreProcessor.Test;
3725

@@ -108,7 +96,7 @@ public void PullRequestCacheBasePath_ProjectBaseDir_HasPriority_IsAbsolute()
10896
{
10997
var workingDirectory = TestContext.ResultsDirectory;
11098
using var scope = new WorkingDirectoryScope(workingDirectory);
111-
var localSettings = ArgumentProcessor.TryProcessArgs(new[] { "/k:key", "/d:sonar.projectBaseDir=Custom" }, logger);
99+
var localSettings = ArgumentProcessor.TryProcessArgs(["/k:key", "/d:sonar.projectBaseDir=Custom"], logger);
112100
var buildSettings = Substitute.For<IBuildSettings>();
113101
buildSettings.SourcesDirectory.Returns(@"C:\Sources\Directory");
114102
buildSettings.SonarScannerWorkingDirectory.Returns(@"C:\SonarScanner\WorkingDirectory");
@@ -305,10 +293,10 @@ private static string CreateFile(string root, string fileName, string content, E
305293
private sealed class CacheContext : IDisposable
306294
{
307295
public readonly string Root;
308-
public readonly List<string> Paths = new();
296+
public readonly List<string> Paths = [];
309297
public readonly CacheProcessor Sut;
310298

311-
private readonly IList<SensorCacheEntry> cache = new List<SensorCacheEntry>();
299+
private readonly List<SensorCacheEntry> cache = [];
312300

313301
public CacheContext(CacheProcessorTests owner, string commandLineArgs = "/k:key")
314302
{

Tests/SonarScanner.MSBuild.PreProcessor.Test/RoslynAnalyzerProviderTests.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -473,22 +473,22 @@ private void CheckRuleset(string ruleSetPath, bool isDeactivated)
473473
File.ReadAllText(ruleSetPath).Should().Be(expectedContent, "Ruleset file does not have the expected content: {0}", ruleSetPath);
474474
}
475475

476-
private static IList<AnalyzerPlugin> CreateAnalyzerPlugins(List<string[]> pluginList) =>
476+
private static List<AnalyzerPlugin> CreateAnalyzerPlugins(List<string[]> pluginList) =>
477477
pluginList.Select(x => new AnalyzerPlugin { AssemblyPaths = x.ToList() }).ToList();
478478

479-
private static string XmlnsDefinition() =>
479+
private static string XmlnsDefinition() =>
480480
#if NET
481-
@"xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema""";
481+
@"xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema""";
482482
#else
483-
@"xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""";
483+
@"xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""";
484484
#endif
485485

486-
private static void CheckFileIsXml(string fullPath)
487-
{
488-
var doc = new XmlDocument();
489-
doc.Load(fullPath);
490-
doc.FirstChild.Should().NotBeNull("Expecting the file to contain some valid XML");
491-
}
486+
private static void CheckFileIsXml(string fullPath)
487+
{
488+
var doc = new XmlDocument();
489+
doc.Load(fullPath);
490+
doc.FirstChild.Should().NotBeNull("Expecting the file to contain some valid XML");
491+
}
492492

493493
private string CreateTestFolders()
494494
{

Tests/SonarScanner.MSBuild.PreProcessor.Test/SonarCloudWebServerTest.cs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,12 @@
1818
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1919
*/
2020

21-
using System;
22-
using System.IO;
2321
using System.IO.Compression;
24-
using System.Linq;
25-
using System.Net;
26-
using System.Net.Http;
27-
using System.Threading.Tasks;
28-
using FluentAssertions;
2922
using Google.Protobuf;
30-
using Microsoft.VisualStudio.TestTools.UnitTesting;
31-
using NSubstitute;
32-
using SonarScanner.MSBuild.Common;
3323
using SonarScanner.MSBuild.PreProcessor.JreResolution;
3424
using SonarScanner.MSBuild.PreProcessor.Protobuf;
3525
using SonarScanner.MSBuild.PreProcessor.Test.Infrastructure;
3626
using SonarScanner.MSBuild.PreProcessor.WebServer;
37-
using TestUtilities;
3827

3928
namespace SonarScanner.MSBuild.PreProcessor.Test;
4029

@@ -435,7 +424,7 @@ public async Task DownloadJreAsync_NullMetadata_Failure() =>
435424
public async Task DownloadJreAsync_NullDownloadUrl_Failure() =>
436425
await CreateServer().Invoking(async x => await x.DownloadJreAsync(CreateJreMetadata(null))).Should().ThrowAsync<ArgumentNullException>();
437426

438-
private static Stream CreateCacheStream(IMessage message)
427+
private static MemoryStream CreateCacheStream(IMessage message)
439428
{
440429
using var stream = new MemoryStream();
441430
message.WriteDelimitedTo(stream);
@@ -450,7 +439,7 @@ private static Stream CreateCacheStream(IMessage message)
450439
return compressed;
451440
}
452441

453-
private IDownloader MockIDownloader(string cacheBaseUrl = null)
442+
private static IDownloader MockIDownloader(string cacheBaseUrl = null)
454443
{
455444
var serverSettingsJson = cacheBaseUrl is not null
456445
? $"{{\"settings\":[{{ \"key\":\"sonar.sensor.cache.baseUrl\",\"value\": \"{cacheBaseUrl}\" }}]}}"

src/SonarScanner.MSBuild.Shim/SonarScanner.Wrapper.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,7 @@
1818
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1919
*/
2020

21-
using System;
22-
using System.Collections.Generic;
23-
using System.Diagnostics;
24-
using System.IO;
25-
using System.Linq;
26-
using System.Text;
27-
using SonarScanner.MSBuild.Common;
21+
using System.Globalization;
2822
using SonarScanner.MSBuild.Shim.Interfaces;
2923

3024
namespace SonarScanner.MSBuild.Shim;
@@ -202,8 +196,7 @@ private static IDictionary<string, string> GetAdditionalEnvVariables(AnalysisCon
202196
/// <summary>
203197
/// Returns all the command line arguments to pass to sonar-scanner
204198
/// </summary>
205-
private static IEnumerable<string> GetAllCmdLineArgs(string projectSettingsFilePath,
206-
IEnumerable<string> userCmdLineArguments, AnalysisConfig config, ILogger logger)
199+
private static IEnumerable<string> GetAllCmdLineArgs(string projectSettingsFilePath, IEnumerable<string> userCmdLineArguments, AnalysisConfig config, ILogger logger)
207200
{
208201
// We don't know what all the valid command line arguments are so we'll
209202
// just pass them on for the sonar-scanner to validate.
@@ -216,7 +209,7 @@ private static IEnumerable<string> GetAllCmdLineArgs(string projectSettingsFileP
216209
// Experimentation suggests that the sonar-scanner won't error if duplicate arguments
217210
// are supplied - it will just use the last argument.
218211
// So we'll set our additional properties last to make sure they take precedence.
219-
args.Add(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}{1}={2}", CmdLineArgPrefix, ProjectSettingsFileArgName, projectSettingsFilePath));
212+
args.Add(string.Format(CultureInfo.InvariantCulture, "{0}{1}={2}", CmdLineArgPrefix, ProjectSettingsFileArgName, projectSettingsFilePath));
220213

221214
// Let the scanner cli know it has been ran from this MSBuild Scanner. (allows to tweak the behavior)
222215
// See https://jira.sonarsource.com/browse/SQSCANNER-65

0 commit comments

Comments
 (0)