Code quality improvements

This commit is contained in:
Tamas Vajk
2023-10-13 13:42:33 +02:00
parent 3b4ea27caf
commit 15ec0a10c9
4 changed files with 14 additions and 16 deletions

View File

@@ -101,6 +101,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
var existsNetFrameworkRefNugetPackage = false;
// Find DLLs in the .Net / Asp.Net Framework
// This block needs to come after the nuget restore, because the nuget restore might fetch the .NET Core/Framework reference assemblies.
if (options.ScanNetFrameworkDlls)
{
existsNetCoreRefNugetPackage = IsNugetPackageAvailable("microsoft.netcore.app.ref");

View File

@@ -162,19 +162,15 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
}
// Determine if ASP.NET is used.
if (!useAspNetCoreDlls)
{
useAspNetCoreDlls =
IsGroupMatch(line, ProjectSdk(), "Sdk", "Microsoft.NET.Sdk.Web") ||
IsGroupMatch(line, FrameworkReference(), "Include", "Microsoft.AspNetCore.App");
}
useAspNetCoreDlls = useAspNetCoreDlls
|| IsGroupMatch(line, ProjectSdk(), "Sdk", "Microsoft.NET.Sdk.Web")
|| IsGroupMatch(line, FrameworkReference(), "Include", "Microsoft.AspNetCore.App");
// Determine if implicit usings are used.
if (!useImplicitUsings)
{
useImplicitUsings = line.Contains("<ImplicitUsings>enable</ImplicitUsings>".AsSpan(), StringComparison.Ordinal) ||
line.Contains("<ImplicitUsings>true</ImplicitUsings>".AsSpan(), StringComparison.Ordinal);
}
useImplicitUsings = useImplicitUsings
|| line.Contains("<ImplicitUsings>enable</ImplicitUsings>".AsSpan(), StringComparison.Ordinal)
|| line.Contains("<ImplicitUsings>true</ImplicitUsings>".AsSpan(), StringComparison.Ordinal);
// Find all custom implicit usings.
foreach (var valueMatch in CustomImplicitUsingDeclarations().EnumerateMatches(line))
@@ -187,9 +183,10 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
}
// Determine project structure:
isLegacyProjectStructureUsed |= MicrosoftCSharpTargets().IsMatch(line);
isNewProjectStructureUsed |= ProjectSdk().IsMatch(line);
isNewProjectStructureUsed |= FrameworkReference().IsMatch(line);
isLegacyProjectStructureUsed = isLegacyProjectStructureUsed || MicrosoftCSharpTargets().IsMatch(line);
isNewProjectStructureUsed = isNewProjectStructureUsed
|| ProjectSdk().IsMatch(line)
|| FrameworkReference().IsMatch(line);
// TODO: we could also check `<Sdk Name="Microsoft.NET.Sdk" />`
}
}

View File

@@ -116,7 +116,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
public string? DesktopRuntime => DesktopRuntimes?.FirstOrDefault();
/// <summary>
/// Gets the executiing runtime location, this is the self contained runtime shipped in the CodeQL CLI bundle.
/// Gets the executing runtime location, this is the self contained runtime shipped in the CodeQL CLI bundle.
/// </summary>
public string ExecutingRuntime => RuntimeEnvironment.GetRuntimeDirectory();

View File

@@ -1,7 +1,7 @@
using Xunit;
using System;
using System.Collections.Generic;
using Semmle.Extraction.CSharp.DependencyFetching;
using System;
namespace Semmle.Extraction.Tests
{