Skip to content

Commit b4707ab

Browse files
authored
Merge pull request github#16871 from tamasvajk/fix/quality-issues
C#: Fix quality issues
2 parents 2b2c381 + 199a968 commit b4707ab

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+79
-85
lines changed

csharp/autobuilder/Semmle.Autobuild.CSharp/CSharpDiagnosticClassifier.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public override void Fire(DiagnosticClassifier classifier, Match match)
9999
{
100100
if (!match.Groups.TryGetValue("projectFile", out var projectFile))
101101
throw new ArgumentException("Expected regular expression match to contain projectFile");
102-
if (!match.Groups.TryGetValue("location", out var location))
102+
if (!match.Groups.TryGetValue("location", out _))
103103
throw new ArgumentException("Expected regular expression match to contain location");
104104

105105
var result = classifier.Results.OfType<Result>().FirstOrDefault();

csharp/autobuilder/Semmle.Autobuild.CSharp/DotNetRule.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.IO;
43
using System.Linq;
54
using Semmle.Util;
6-
using Semmle.Util.Logging;
75
using Semmle.Autobuild.Shared;
86
using Semmle.Extraction.CSharp.DependencyFetching;
97

@@ -15,14 +13,14 @@ namespace Semmle.Autobuild.CSharp
1513
/// </summary>
1614
internal class DotNetRule : IBuildRule<CSharpAutobuildOptions>
1715
{
18-
public readonly List<IProjectOrSolution> FailedProjectsOrSolutions = new();
16+
public List<IProjectOrSolution> FailedProjectsOrSolutions { get; } = [];
1917

2018
/// <summary>
2119
/// A list of projects which are incompatible with DotNet.
2220
/// </summary>
2321
public IEnumerable<Project<CSharpAutobuildOptions>> NotDotNetProjects { get; private set; }
2422

25-
public DotNetRule() => NotDotNetProjects = new List<Project<CSharpAutobuildOptions>>();
23+
public DotNetRule() => NotDotNetProjects = [];
2624

2725
public BuildScript Analyse(IAutobuilder<CSharpAutobuildOptions> builder, bool auto)
2826
{

csharp/autobuilder/Semmle.Autobuild.Shared/BuildTools.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public VcVarsBatFile(string path, int version)
1818
Path = path;
1919
ToolsVersion = version;
2020
}
21-
};
21+
}
2222

2323
/// <summary>
2424
/// Collection of available Visual Studio build tools.

csharp/autobuilder/Semmle.Autobuild.Shared/DiagnosticClassifier.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public virtual void Fire(DiagnosticClassifier classifier, Match match) { }
6060
public class DiagnosticClassifier
6161
{
6262
private readonly List<DiagnosticRule> rules;
63-
public readonly List<IDiagnosticsResult> Results;
63+
public List<IDiagnosticsResult> Results { get; }
6464

6565
public DiagnosticClassifier()
6666
{

csharp/autobuilder/Semmle.Autobuild.Shared/MsBuildRule.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class MsBuildRule : IBuildRule<AutobuildOptionsShared>
3232
/// <summary>
3333
/// A list of solutions or projects which failed to build.
3434
/// </summary>
35-
public readonly List<IProjectOrSolution> FailedProjectsOrSolutions = new();
35+
public List<IProjectOrSolution> FailedProjectsOrSolutions { get; } = [];
3636

3737
public BuildScript Analyse(IAutobuilder<AutobuildOptionsShared> builder, bool auto)
3838
{
@@ -60,7 +60,7 @@ public BuildScript Analyse(IAutobuilder<AutobuildOptionsShared> builder, bool au
6060
// Use `nuget.exe` from source code repo, if present, otherwise first attempt with global
6161
// `nuget` command, and if that fails, attempt to download `nuget.exe` from nuget.org
6262
var nuget = builder.GetFilename("nuget.exe").Select(t => t.Item1).FirstOrDefault() ?? "nuget";
63-
var nugetDownloadPath = builder.Actions.PathCombine(FileUtils.GetTemporaryWorkingDirectory(builder.Actions.GetEnvironmentVariable, builder.Options.Language.UpperCaseName, out var _), ".nuget", "nuget.exe");
63+
var nugetDownloadPath = builder.Actions.PathCombine(FileUtils.GetTemporaryWorkingDirectory(builder.Actions.GetEnvironmentVariable, builder.Options.Language.UpperCaseName, out _), ".nuget", "nuget.exe");
6464
var nugetDownloaded = false;
6565

6666
var ret = BuildScript.Success;
@@ -126,7 +126,7 @@ BuildScript GetNugetRestoreScript() =>
126126
var platform = projectOrSolution is ISolution s1 ? s1.DefaultPlatformName : null;
127127
var configuration = projectOrSolution is ISolution s2 ? s2.DefaultConfigurationName : null;
128128

129-
command.Argument("/t:" + target);
129+
command.Argument($"/t:{target}");
130130
if (platform is not null)
131131
command.Argument($"/p:Platform=\"{platform}\"");
132132
if (configuration is not null)

csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/AssemblyCache.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,12 @@ public AssemblyInfo GetAssemblyInfo(string filepath)
133133

134134
private readonly List<string> dllsToIndex = new List<string>();
135135

136-
private readonly Dictionary<string, AssemblyInfo> assemblyInfoByFileName = new Dictionary<string, AssemblyInfo>();
136+
private readonly Dictionary<string, AssemblyInfo> assemblyInfoByFileName = [];
137137

138138
// Map from assembly id (in various formats) to the full info.
139-
private readonly Dictionary<string, AssemblyInfo> assemblyInfoById = new Dictionary<string, AssemblyInfo>();
139+
private readonly Dictionary<string, AssemblyInfo> assemblyInfoById = [];
140140

141-
private readonly HashSet<string> failedAssemblyInfoIds = new HashSet<string>();
141+
private readonly HashSet<string> failedAssemblyInfoIds = [];
142142

143143
private readonly ILogger logger;
144144
}

csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ private AssemblyInfo(string id, string filename)
9494
{
9595
var sections = id.Split(new string[] { ", " }, StringSplitOptions.None);
9696

97-
Name = sections.First();
97+
Name = sections[0];
9898

9999
foreach (var section in sections.Skip(1))
100100
{

csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/AssemblyLookupLocation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public List<string> GetDlls(ILogger logger)
8080
}
8181
else
8282
{
83-
logger.LogDebug("AssemblyLookupLocation: Path not found: " + path);
83+
logger.LogDebug($"AssemblyLookupLocation: Path not found: {path}");
8484
}
8585
return dllsToIndex;
8686
}

csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/Assets.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,6 @@ private void AddPackageDependencies(JObject json, string jsonPath)
120120
info.Compile
121121
.ForEach(r => Dependencies.Add(name, r.Key));
122122
});
123-
124-
return;
125123
}
126124

127125
/// <summary>

csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DependencyContainer.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ internal class DependencyContainer
1212
/// <summary>
1313
/// Paths to dependencies required for compilation.
1414
/// </summary>
15-
public HashSet<string> Paths { get; } = new();
15+
public HashSet<string> Paths { get; } = [];
1616

1717
/// <summary>
1818
/// Packages that are used as a part of the required dependencies.
1919
/// </summary>
20-
public HashSet<string> Packages { get; } = new();
20+
public HashSet<string> Packages { get; } = [];
2121

2222
/// <summary>
2323
/// If the path specifically adds a .dll we use that, otherwise we as a fallback
@@ -33,9 +33,7 @@ private static string ParseFilePath(string path)
3333
}
3434

3535
private static string GetPackageName(string package) =>
36-
package
37-
.Split(Path.DirectorySeparatorChar)
38-
.First();
36+
package.Split(Path.DirectorySeparatorChar)[0];
3937

4038
/// <summary>
4139
/// Add a dependency inside a package.

0 commit comments

Comments
 (0)