Skip to content

Commit f82fedf

Browse files
committed
C#: Fix the cs/path-combine code quality issues in the extractor.
1 parent 72f34c2 commit f82fedf

24 files changed

Lines changed: 53 additions & 53 deletions

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void Add(string package, string dependency)
5050
return;
5151
}
5252

53-
var path = Path.Combine(p, ParseFilePath(d));
53+
var path = Path.Join(p, ParseFilePath(d));
5454
Paths.Add(path);
5555
Packages.Add(GetPackageName(p));
5656
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public DependencyManager(string srcDir, ILogger logger)
7575
}
7676
}
7777

78-
this.diagnosticsWriter = new DiagnosticsStream(Path.Combine(
78+
this.diagnosticsWriter = new DiagnosticsStream(Path.Join(
7979
diagDirEnv ?? "",
8080
$"dependency-manager-{DateTime.UtcNow:yyyyMMddHHmm}-{Environment.ProcessId}.jsonc"));
8181
this.sourceDir = new DirectoryInfo(srcDir);
@@ -327,7 +327,7 @@ private void AddNetFrameworkDlls(ISet<AssemblyLookupLocation> dllLocations, ISet
327327
private void RemoveNugetPackageReference(string packagePrefix, ISet<AssemblyLookupLocation> dllLocations)
328328
{
329329
var packageFolder = nugetPackageRestorer.PackageDirectory.DirInfo.FullName.ToLowerInvariant();
330-
var packagePathPrefix = Path.Combine(packageFolder, packagePrefix.ToLowerInvariant());
330+
var packagePathPrefix = Path.Join(packageFolder, packagePrefix.ToLowerInvariant());
331331
var toRemove = dllLocations.Where(s => s.Path.StartsWith(packagePathPrefix, StringComparison.InvariantCultureIgnoreCase));
332332
foreach (var path in toRemove)
333333
{

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ private DotNet(IDotNetCliInvoker dotnetCliInvoker, ILogger logger, bool runDotne
3131
}
3232
}
3333

34-
private DotNet(ILogger logger, string? dotNetPath, TemporaryDirectory tempWorkingDirectory, DependabotProxy? dependabotProxy) : this(new DotNetCliInvoker(logger, Path.Combine(dotNetPath ?? string.Empty, "dotnet"), dependabotProxy), logger, dotNetPath is null, tempWorkingDirectory) { }
34+
private DotNet(ILogger logger, string? dotNetPath, TemporaryDirectory tempWorkingDirectory, DependabotProxy? dependabotProxy) : this(new DotNetCliInvoker(logger, Path.Join(dotNetPath ?? string.Empty, "dotnet"), dependabotProxy), logger, dotNetPath is null, tempWorkingDirectory) { }
3535

3636
internal static IDotNet Make(IDotNetCliInvoker dotnetCliInvoker, ILogger logger, bool runDotnetInfo) => new DotNet(dotnetCliInvoker, logger, runDotnetInfo);
3737

@@ -73,7 +73,7 @@ private string GetRestoreArgs(RestoreSettings restoreSettings)
7373
var path = ".empty";
7474
if (tempWorkingDirectory != null)
7575
{
76-
path = Path.Combine(tempWorkingDirectory.ToString(), "emptyFakeDotnetRoot");
76+
path = Path.Join(tempWorkingDirectory.ToString(), "emptyFakeDotnetRoot");
7777
Directory.CreateDirectory(path);
7878
}
7979

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ internal record DotNetVersion : IComparable<DotNetVersion>
1212
private string FullVersion =>
1313
version.ToString();
1414

15-
public string FullPath => Path.Combine(dir, FullVersion);
15+
public string FullPath => Path.Join(dir, FullVersion);
1616

1717
/**
1818
* The full path to the reference assemblies for this runtime.
@@ -33,7 +33,7 @@ public string? FullPathReferenceAssemblies
3333
{
3434
directories[^2] = "packs";
3535
directories[^1] = $"{directories[^1]}.Ref";
36-
return Path.Combine(string.Join(Path.DirectorySeparatorChar, directories), FullVersion, "ref");
36+
return Path.Join(string.Join(Path.DirectorySeparatorChar, directories), FullVersion, "ref");
3737
}
3838
return null;
3939
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public NugetExeWrapper(FileProvider fileProvider, DependencyDirectory packageDir
4646
if (HasNoPackageSource() && useDefaultFeed())
4747
{
4848
// We only modify or add a top level nuget.config file
49-
nugetConfigPath = Path.Combine(fileProvider.SourceDir.FullName, "nuget.config");
49+
nugetConfigPath = Path.Join(fileProvider.SourceDir.FullName, "nuget.config");
5050
try
5151
{
5252
if (File.Exists(nugetConfigPath))
@@ -55,7 +55,7 @@ public NugetExeWrapper(FileProvider fileProvider, DependencyDirectory packageDir
5555

5656
do
5757
{
58-
backupNugetConfig = Path.Combine(tempFolderPath, Path.GetRandomFileName());
58+
backupNugetConfig = Path.Join(tempFolderPath, Path.GetRandomFileName());
5959
}
6060
while (File.Exists(backupNugetConfig));
6161
File.Copy(nugetConfigPath, backupNugetConfig, true);
@@ -123,7 +123,7 @@ private string ResolveNugetExe()
123123
var nugetPath = FileUtils.FindProgramOnPath(executableName);
124124
if (nugetPath is not null)
125125
{
126-
nugetPath = Path.Combine(nugetPath, executableName);
126+
nugetPath = Path.Join(nugetPath, executableName);
127127
logger.LogInfo($"Using nuget.exe from PATH: {nugetPath}");
128128
return nugetPath;
129129
}
@@ -133,8 +133,8 @@ private string ResolveNugetExe()
133133

134134
private string DownloadNugetExe(string sourceDir)
135135
{
136-
var directory = Path.Combine(sourceDir, ".nuget");
137-
var nuget = Path.Combine(directory, "nuget.exe");
136+
var directory = Path.Join(sourceDir, ".nuget");
137+
var nuget = Path.Join(directory, "nuget.exe");
138138

139139
// Nuget.exe already exists in the .nuget directory.
140140
if (File.Exists(nuget))

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public HashSet<AssemblyLookupLocation> Restore()
209209

210210
var paths = dependencies
211211
.Paths
212-
.Select(d => Path.Combine(PackageDirectory.DirInfo.FullName, d))
212+
.Select(d => Path.Join(PackageDirectory.DirInfo.FullName, d))
213213
.ToList();
214214
assemblyLookupLocations.UnionWith(paths.Select(p => new AssemblyLookupLocation(p)));
215215

@@ -527,7 +527,7 @@ private void RestoreProjects(IEnumerable<string> projects, HashSet<string> reach
527527
var sb = new StringBuilder();
528528
fallbackNugetFeeds.ForEach((feed, index) => sb.AppendLine($"<add key=\"feed{index}\" value=\"{feed}\" />"));
529529

530-
var nugetConfigPath = Path.Combine(folderPath, "nuget.config");
530+
var nugetConfigPath = Path.Join(folderPath, "nuget.config");
531531
logger.LogInfo($"Creating fallback nuget.config file {nugetConfigPath}.");
532532
File.WriteAllText(nugetConfigPath,
533533
$"""
@@ -1052,15 +1052,15 @@ public void Dispose()
10521052
/// </summary>
10531053
private static string ComputeTempDirectoryPath(string subfolderName)
10541054
{
1055-
return Path.Combine(FileUtils.GetTemporaryWorkingDirectory(out _), subfolderName);
1055+
return Path.Join(FileUtils.GetTemporaryWorkingDirectory(out _), subfolderName);
10561056
}
10571057

10581058
/// <summary>
10591059
/// Computes a unique temporary directory path based on the source directory and the subfolder name.
10601060
/// </summary>
10611061
private static string ComputeTempDirectoryPath(string srcDir, string subfolderName)
10621062
{
1063-
return Path.Combine(FileUtils.GetTemporaryWorkingDirectory(out _), FileUtils.ComputeHash(srcDir), subfolderName);
1063+
return Path.Join(FileUtils.GetTemporaryWorkingDirectory(out _), FileUtils.ComputeHash(srcDir), subfolderName);
10641064
}
10651065
}
10661066
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ private IEnumerable<string> DesktopRuntimes
7979

8080
var monoPath = FileUtils.FindProgramOnPath(Win32.IsWindows() ? "mono.exe" : "mono");
8181
string[] monoDirs = monoPath is not null
82-
? [Path.GetFullPath(Path.Combine(monoPath, "..", "lib", "mono")), monoPath]
82+
? [Path.GetFullPath(Path.Join(monoPath, "..", "lib", "mono")), monoPath]
8383
: ["/usr/lib/mono", "/usr/local/mono", "/usr/local/bin/mono", @"C:\Program Files\Mono\lib\mono"];
8484

8585
var monoDir = monoDirs.FirstOrDefault(Directory.Exists);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ private static HashSet<DotNetVersion> ParseSdks(IList<string> listed)
6363
return null;
6464
}
6565

66-
var path = Path.Combine(version.FullPath, "Roslyn", "bincore", "csc.dll");
66+
var path = Path.Join(version.FullPath, "Roslyn", "bincore", "csc.dll");
6767
logger.LogDebug($"Source generator CSC: '{path}'");
6868
if (!File.Exists(path))
6969
{

csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/SourceGenerators/DotnetSourceGeneratorWrapper/DotnetSourceGeneratorWrapper.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ public IEnumerable<string> RunSourceGenerator(IEnumerable<string> additionalFile
4141
.Replace('\\', '/'); // Ensure we're generating the same hash regardless of the OS
4242
var name = FileUtils.ComputeHash($"{relativePathToCsProj}\n{this.GetType().Name}");
4343
using var tempDir = new TemporaryDirectory(Path.Join(FileUtils.GetTemporaryWorkingDirectory(out _), "source-generator"), "source generator temporary", logger);
44-
var analyzerConfigPath = Path.Combine(tempDir.DirInfo.FullName, $"{name}.txt");
45-
var dllPath = Path.Combine(tempDir.DirInfo.FullName, $"{name}.dll");
46-
var cscArgsPath = Path.Combine(tempDir.DirInfo.FullName, $"{name}.rsp");
47-
var outputFolder = Path.Combine(targetDir, name);
44+
var analyzerConfigPath = Path.Join(tempDir.DirInfo.FullName, $"{name}.txt");
45+
var dllPath = Path.Join(tempDir.DirInfo.FullName, $"{name}.dll");
46+
var cscArgsPath = Path.Join(tempDir.DirInfo.FullName, $"{name}.rsp");
47+
var outputFolder = Path.Join(targetDir, name);
4848
Directory.CreateDirectory(outputFolder);
4949
logger.LogInfo("Producing analyzer config content.");
5050
GenerateAnalyzerConfig(additionalFiles, csprojFile, analyzerConfigPath);

csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/SourceGenerators/DotnetSourceGeneratorWrapper/Razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public Razor(Sdk sdk, IDotNet dotNet, ILogger logger) : base(sdk, dotNet, logger
2121
throw new Exception("No SDK path available.");
2222
}
2323

24-
SourceGeneratorFolder = Path.Combine(sdkPath, "Sdks", "Microsoft.NET.Sdk.Razor", "source-generators");
24+
SourceGeneratorFolder = Path.Join(sdkPath, "Sdks", "Microsoft.NET.Sdk.Razor", "source-generators");
2525
this.logger.LogInfo($"Razor source generator folder: {SourceGeneratorFolder}");
2626
if (!Directory.Exists(SourceGeneratorFolder))
2727
{

0 commit comments

Comments
 (0)