diff --git a/csharp/autobuilder/Semmle.Autobuild.CSharp/CSharpDiagnosticClassifier.cs b/csharp/autobuilder/Semmle.Autobuild.CSharp/CSharpDiagnosticClassifier.cs index 85d6c872c84b4..2f947d7c33d42 100644 --- a/csharp/autobuilder/Semmle.Autobuild.CSharp/CSharpDiagnosticClassifier.cs +++ b/csharp/autobuilder/Semmle.Autobuild.CSharp/CSharpDiagnosticClassifier.cs @@ -99,7 +99,7 @@ public override void Fire(DiagnosticClassifier classifier, Match match) { if (!match.Groups.TryGetValue("projectFile", out var projectFile)) throw new ArgumentException("Expected regular expression match to contain projectFile"); - if (!match.Groups.TryGetValue("location", out var location)) + if (!match.Groups.TryGetValue("location", out _)) throw new ArgumentException("Expected regular expression match to contain location"); var result = classifier.Results.OfType().FirstOrDefault(); diff --git a/csharp/autobuilder/Semmle.Autobuild.CSharp/DotNetRule.cs b/csharp/autobuilder/Semmle.Autobuild.CSharp/DotNetRule.cs index 20ed6f0e4129e..43efcd0352f0d 100644 --- a/csharp/autobuilder/Semmle.Autobuild.CSharp/DotNetRule.cs +++ b/csharp/autobuilder/Semmle.Autobuild.CSharp/DotNetRule.cs @@ -1,9 +1,7 @@ using System; using System.Collections.Generic; -using System.IO; using System.Linq; using Semmle.Util; -using Semmle.Util.Logging; using Semmle.Autobuild.Shared; using Semmle.Extraction.CSharp.DependencyFetching; @@ -15,14 +13,14 @@ namespace Semmle.Autobuild.CSharp /// internal class DotNetRule : IBuildRule { - public readonly List FailedProjectsOrSolutions = new(); + public List FailedProjectsOrSolutions { get; } = []; /// /// A list of projects which are incompatible with DotNet. /// public IEnumerable> NotDotNetProjects { get; private set; } - public DotNetRule() => NotDotNetProjects = new List>(); + public DotNetRule() => NotDotNetProjects = []; public BuildScript Analyse(IAutobuilder builder, bool auto) { diff --git a/csharp/autobuilder/Semmle.Autobuild.Shared/BuildTools.cs b/csharp/autobuilder/Semmle.Autobuild.Shared/BuildTools.cs index 0e910b68d48ab..c445fcb805a0c 100644 --- a/csharp/autobuilder/Semmle.Autobuild.Shared/BuildTools.cs +++ b/csharp/autobuilder/Semmle.Autobuild.Shared/BuildTools.cs @@ -18,7 +18,7 @@ public VcVarsBatFile(string path, int version) Path = path; ToolsVersion = version; } - }; + } /// /// Collection of available Visual Studio build tools. diff --git a/csharp/autobuilder/Semmle.Autobuild.Shared/DiagnosticClassifier.cs b/csharp/autobuilder/Semmle.Autobuild.Shared/DiagnosticClassifier.cs index 94af39ca9598d..43db196d9f692 100644 --- a/csharp/autobuilder/Semmle.Autobuild.Shared/DiagnosticClassifier.cs +++ b/csharp/autobuilder/Semmle.Autobuild.Shared/DiagnosticClassifier.cs @@ -60,7 +60,7 @@ public virtual void Fire(DiagnosticClassifier classifier, Match match) { } public class DiagnosticClassifier { private readonly List rules; - public readonly List Results; + public List Results { get; } public DiagnosticClassifier() { diff --git a/csharp/autobuilder/Semmle.Autobuild.Shared/MsBuildRule.cs b/csharp/autobuilder/Semmle.Autobuild.Shared/MsBuildRule.cs index eaf9449af417b..139e16566e835 100644 --- a/csharp/autobuilder/Semmle.Autobuild.Shared/MsBuildRule.cs +++ b/csharp/autobuilder/Semmle.Autobuild.Shared/MsBuildRule.cs @@ -32,7 +32,7 @@ public class MsBuildRule : IBuildRule /// /// A list of solutions or projects which failed to build. /// - public readonly List FailedProjectsOrSolutions = new(); + public List FailedProjectsOrSolutions { get; } = []; public BuildScript Analyse(IAutobuilder builder, bool auto) { @@ -60,7 +60,7 @@ public BuildScript Analyse(IAutobuilder builder, bool au // Use `nuget.exe` from source code repo, if present, otherwise first attempt with global // `nuget` command, and if that fails, attempt to download `nuget.exe` from nuget.org var nuget = builder.GetFilename("nuget.exe").Select(t => t.Item1).FirstOrDefault() ?? "nuget"; - var nugetDownloadPath = builder.Actions.PathCombine(FileUtils.GetTemporaryWorkingDirectory(builder.Actions.GetEnvironmentVariable, builder.Options.Language.UpperCaseName, out var _), ".nuget", "nuget.exe"); + var nugetDownloadPath = builder.Actions.PathCombine(FileUtils.GetTemporaryWorkingDirectory(builder.Actions.GetEnvironmentVariable, builder.Options.Language.UpperCaseName, out _), ".nuget", "nuget.exe"); var nugetDownloaded = false; var ret = BuildScript.Success; diff --git a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/AssemblyCache.cs b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/AssemblyCache.cs index 62a053870e914..953c0adc55215 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/AssemblyCache.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/AssemblyCache.cs @@ -133,12 +133,12 @@ public AssemblyInfo GetAssemblyInfo(string filepath) private readonly List dllsToIndex = new List(); - private readonly Dictionary assemblyInfoByFileName = new Dictionary(); + private readonly Dictionary assemblyInfoByFileName = []; // Map from assembly id (in various formats) to the full info. - private readonly Dictionary assemblyInfoById = new Dictionary(); + private readonly Dictionary assemblyInfoById = []; - private readonly HashSet failedAssemblyInfoIds = new HashSet(); + private readonly HashSet failedAssemblyInfoIds = []; private readonly ILogger logger; } diff --git a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/AssemblyInfo.cs b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/AssemblyInfo.cs index d77005bf458bf..b02f33842a609 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/AssemblyInfo.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/AssemblyInfo.cs @@ -94,7 +94,7 @@ private AssemblyInfo(string id, string filename) { var sections = id.Split(new string[] { ", " }, StringSplitOptions.None); - Name = sections.First(); + Name = sections[0]; foreach (var section in sections.Skip(1)) { diff --git a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/Assets.cs b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/Assets.cs index 9308a137e7e36..ef2c47397b05e 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/Assets.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/Assets.cs @@ -120,8 +120,6 @@ private void AddPackageDependencies(JObject json, string jsonPath) info.Compile .ForEach(r => Dependencies.Add(name, r.Key)); }); - - return; } /// diff --git a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DependencyContainer.cs b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DependencyContainer.cs index 2307311041246..b5abefb3a651d 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DependencyContainer.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DependencyContainer.cs @@ -12,12 +12,12 @@ internal class DependencyContainer /// /// Paths to dependencies required for compilation. /// - public HashSet Paths { get; } = new(); + public HashSet Paths { get; } = []; /// /// Packages that are used as a part of the required dependencies. /// - public HashSet Packages { get; } = new(); + public HashSet Packages { get; } = []; /// /// 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) } private static string GetPackageName(string package) => - package - .Split(Path.DirectorySeparatorChar) - .First(); + package.Split(Path.DirectorySeparatorChar)[0]; /// /// Add a dependency inside a package. diff --git a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DependencyManager.cs b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DependencyManager.cs index f18d30f4f1925..4866df1260e2a 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DependencyManager.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DependencyManager.cs @@ -310,7 +310,7 @@ private void AddNetFrameworkDlls(ISet dllLocations, ISet if (runtimeLocation is null) { - runtimeLocation ??= Runtime.ExecutingRuntime; + runtimeLocation = Runtime.ExecutingRuntime; dllLocations.Add(new AssemblyLookupLocation(runtimeLocation, name => !name.StartsWith("Semmle."))); } else diff --git a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DotNetCliInvoker.cs b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DotNetCliInvoker.cs index 1267802122706..4295cce671679 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DotNetCliInvoker.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DotNetCliInvoker.cs @@ -58,13 +58,13 @@ private bool RunCommandAux(string args, string? workingDirectory, out IList + public bool RunCommand(string args, bool silent = true) => RunCommandAux(args, null, out _, silent); - public bool RunCommand(string args, out IList output, bool silent) => + public bool RunCommand(string args, out IList output, bool silent = true) => RunCommandAux(args, null, out output, silent); - public bool RunCommand(string args, string? workingDirectory, out IList output, bool silent) => + public bool RunCommand(string args, string? workingDirectory, out IList output, bool silent = true) => RunCommandAux(args, workingDirectory, out output, silent); } } diff --git a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/EnvironmentVariableNames.cs b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/EnvironmentVariableNames.cs index d9a0eac4845af..345cb43453fc7 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/EnvironmentVariableNames.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/EnvironmentVariableNames.cs @@ -1,6 +1,6 @@ namespace Semmle.Extraction.CSharp.DependencyFetching { - internal class EnvironmentVariableNames + internal static class EnvironmentVariableNames { /// /// Controls whether to generate source files from resources (`.resx`). diff --git a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetExeWrapper.cs b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetExeWrapper.cs index 262ae4b19edd0..0371aed16e2df 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetExeWrapper.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetExeWrapper.cs @@ -51,7 +51,7 @@ public NugetExeWrapper(FileProvider fileProvider, TemporaryDirectory packageDire { if (File.Exists(nugetConfigPath)) { - var tempFolderPath = FileUtils.GetTemporaryWorkingDirectory(out var _); + var tempFolderPath = FileUtils.GetTemporaryWorkingDirectory(out _); do { @@ -188,7 +188,7 @@ private bool TryRestoreNugetPackage(string packagesConfig) var threadId = Environment.CurrentManagedThreadId; void onOut(string s) => logger.LogDebug(s, threadId); void onError(string s) => logger.LogError(s, threadId); - var exitCode = pi.ReadOutput(out var _, onOut, onError); + var exitCode = pi.ReadOutput(out _, onOut, onError); if (exitCode != 0) { logger.LogError($"Command {pi.FileName} {pi.Arguments} failed with exit code {exitCode}"); @@ -264,7 +264,7 @@ private void RunMonoNugetCommand(string command, out IList stdout) private void AddDefaultPackageSource(string nugetConfig) { logger.LogInfo("Adding default package source..."); - RunMonoNugetCommand($"sources add -Name DefaultNugetOrg -Source {NugetPackageRestorer.PublicNugetOrgFeed} -ConfigFile \"{nugetConfig}\"", out var _); + RunMonoNugetCommand($"sources add -Name DefaultNugetOrg -Source {NugetPackageRestorer.PublicNugetOrgFeed} -ConfigFile \"{nugetConfig}\"", out _); } public void Dispose() diff --git a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetPackageRestorer.cs b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetPackageRestorer.cs index 0204e9b7c408f..4ad4c8c9e31a1 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetPackageRestorer.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetPackageRestorer.cs @@ -538,7 +538,7 @@ private void TryChangePackageVersion(DirectoryInfo tempDir, string newVersion) TryChangeProjectFile(tempDir, PackageReferenceVersion(), $"Version=\"{newVersion}\"", "package reference version"); } - private bool TryChangeProjectFile(DirectoryInfo projectDir, Regex pattern, string replacement, string patternName) + private void TryChangeProjectFile(DirectoryInfo projectDir, Regex pattern, string replacement, string patternName) { try { @@ -548,7 +548,7 @@ private bool TryChangeProjectFile(DirectoryInfo projectDir, Regex pattern, strin if (csprojs.Length != 1) { logger.LogError($"Could not find the .csproj file in {projectDir.FullName}, count = {csprojs.Length}"); - return false; + return; } var csproj = csprojs[0]; @@ -557,18 +557,16 @@ private bool TryChangeProjectFile(DirectoryInfo projectDir, Regex pattern, strin if (matches.Count == 0) { logger.LogError($"Could not find the {patternName} in {csproj.FullName}"); - return false; + return; } content = pattern.Replace(content, replacement, 1); File.WriteAllText(csproj.FullName, content); - return true; } catch (Exception exc) { logger.LogError($"Failed to change the {patternName} in {projectDir.FullName}: {exc}"); } - return false; } private static async Task ExecuteGetRequest(string address, HttpClient httpClient, CancellationToken cancellationToken) @@ -644,7 +642,7 @@ private bool CheckFeeds(out HashSet explicitFeeds) (explicitFeeds, var allFeeds) = GetAllFeeds(); var excludedFeeds = EnvironmentVariables.GetURLs(EnvironmentVariableNames.ExcludedNugetFeedsFromResponsivenessCheck) - .ToHashSet() ?? []; + .ToHashSet(); if (excludedFeeds.Count > 0) { @@ -779,7 +777,7 @@ private static string ComputeTempDirectoryPath(string srcDir, string subfolderNa foreach (var b in sha.Take(8)) sb.AppendFormat("{0:x2}", b); - return Path.Combine(FileUtils.GetTemporaryWorkingDirectory(out var _), sb.ToString(), subfolderName); + return Path.Combine(FileUtils.GetTemporaryWorkingDirectory(out _), sb.ToString(), subfolderName); } } } diff --git a/csharp/extractor/Semmle.Extraction.CSharp.StubGenerator/StubVisitor.cs b/csharp/extractor/Semmle.Extraction.CSharp.StubGenerator/StubVisitor.cs index 56a20473fa3f2..80f6b2d6617b9 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp.StubGenerator/StubVisitor.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp.StubGenerator/StubVisitor.cs @@ -201,12 +201,12 @@ private void StubTypedConstant(TypedConstant c) } } - private static readonly HashSet attributeAllowList = new() { + private static readonly HashSet attributeAllowList = [ "System.FlagsAttribute", "System.AttributeUsageAttribute", "System.Runtime.CompilerServices.InterpolatedStringHandlerAttribute", "System.Runtime.CompilerServices.InterpolatedStringHandlerArgumentAttribute", - }; + ]; private void StubAttribute(AttributeData a, string prefix, bool addNewLine) { @@ -298,7 +298,7 @@ private static bool IsUnsafe(ITypeSymbol symbol) => (symbol is INamedTypeSymbol named && named.TypeArguments.Any(IsUnsafe)) || (symbol is IArrayTypeSymbol at && IsUnsafe(at.ElementType)); - private static readonly HashSet keywords = new() { + private static readonly HashSet keywords = [ "abstract", "as", "base", "bool", "break", "byte", "case", "catch", "char", "checked", "class", "const", "continue", "decimal", "default", "delegate", "do", "double", "else", "enum", "event", "explicit", "extern", "false", "finally", "fixed", "float", "for", "foreach", @@ -308,7 +308,7 @@ private static bool IsUnsafe(ITypeSymbol symbol) => "stackalloc", "static", "string", "struct", "switch", "this", "throw", "true", "try", "typeof", "uint", "ulong", "unchecked", "unsafe", "ushort", "using", "virtual", "void", "volatile", "while" - }; + ]; private static string EscapeIdentifier(string identifier) => keywords.Contains(identifier) ? "@" + identifier : identifier; diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Comments/CommentBinding.cs b/csharp/extractor/Semmle.Extraction.CSharp/Comments/CommentBinding.cs index 22518ba493016..2089cf7d8fe60 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Comments/CommentBinding.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Comments/CommentBinding.cs @@ -9,5 +9,5 @@ public enum CommentBinding Best, // The most likely element associated with a comment Before, // The element before the comment After // The element after the comment - }; + } } diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Comments/CommentLineType.cs b/csharp/extractor/Semmle.Extraction.CSharp/Comments/CommentLineType.cs index 8506ca701b3e0..94ef2dbfa4b82 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Comments/CommentLineType.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Comments/CommentLineType.cs @@ -9,5 +9,5 @@ public enum CommentLineType XmlDoc, // Comment starting /// ... Multiline, // Comment starting /* ..., even if the comment only spans one line. MultilineContinuation // The second and subsequent lines of comment in a multiline comment. - }; + } } diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Compilations/Compilation.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Compilations/Compilation.cs index 0ba1965723eb8..8685c9d7a7dc3 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Compilations/Compilation.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Compilations/Compilation.cs @@ -9,7 +9,7 @@ namespace Semmle.Extraction.CSharp.Entities { internal class Compilation : CachedEntity { - internal readonly ConcurrentDictionary messageCounts = new(); + internal readonly ConcurrentDictionary messageCounts = []; private readonly string cwd; private readonly string[] args; diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/ExpressionNodeInfo.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/ExpressionNodeInfo.cs index 4e99689ebe0c2..a78f7e8c80b94 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/ExpressionNodeInfo.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/ExpressionNodeInfo.cs @@ -193,7 +193,7 @@ private bool TryGetStringValueFromUtf8Literal(out string? value) public bool IsBoolLiteral() { - return TryGetBoolValueFromLiteral(out var _); + return TryGetBoolValueFromLiteral(out _); } } } diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/Patterns/PropertyPattern.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/Patterns/PropertyPattern.cs index a195d9ffb8328..aa9d4eaea88dc 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/Patterns/PropertyPattern.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/Patterns/PropertyPattern.cs @@ -25,7 +25,7 @@ private record AccessStep(string Identifier, Microsoft.CodeAnalysis.Location Loc private class AccessStepPack { - public readonly List Prefix = new(); + public List Prefix { get; } = []; public AccessStep Last { get; private set; } public AccessStepPack Add(string identifier, Microsoft.CodeAnalysis.Location location) diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Extractor/Analyser.cs b/csharp/extractor/Semmle.Extraction.CSharp/Extractor/Analyser.cs index 45228e8b81d8d..0d8d7df6c424a 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Extractor/Analyser.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Extractor/Analyser.cs @@ -346,7 +346,7 @@ public virtual void Dispose() /// public void LogExtractorInfo() { - Logger.LogInfo($" Extractor: {Environment.GetCommandLineArgs().First()}"); + Logger.LogInfo($" Extractor: {Environment.GetCommandLineArgs()[0]}"); Logger.LogInfo($" Extractor version: {Version}"); Logger.LogInfo($" Current working directory: {Directory.GetCurrentDirectory()}"); } diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Extractor/CompilerVersion.cs b/csharp/extractor/Semmle.Extraction.CSharp/Extractor/CompilerVersion.cs index a84a912d85ed9..c08721ea4b8ab 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Extractor/CompilerVersion.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Extractor/CompilerVersion.cs @@ -34,7 +34,7 @@ public string? SkipReason private set; } - private static readonly Dictionary knownCompilerNames = new Dictionary + private static readonly Dictionary knownCompilerNames = new() { { "csc.exe", "Microsoft" }, { "csc2.exe", "Microsoft" }, diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Extractor/Context.cs b/csharp/extractor/Semmle.Extraction.CSharp/Extractor/Context.cs index 57e9a5ca9f17a..654ce0cc0f503 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Extractor/Context.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Extractor/Context.cs @@ -68,7 +68,7 @@ internal void CacheLambdaParameterSymbol(IParameterSymbol param, SyntaxNode synt lambdaParameterCache[syntax] = param; } - private readonly Dictionary lambdaParameterCache = new Dictionary(); + private readonly Dictionary lambdaParameterCache = []; /// /// The current compilation unit. diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Populators/DirectiveVisitor.cs b/csharp/extractor/Semmle.Extraction.CSharp/Populators/DirectiveVisitor.cs index b80d5175a8d19..f5f3c7d2acdf4 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Populators/DirectiveVisitor.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Populators/DirectiveVisitor.cs @@ -8,7 +8,7 @@ namespace Semmle.Extraction.CSharp.Populators internal class DirectiveVisitor : CSharpSyntaxWalker { private readonly Context cx; - private readonly List branchesTaken = new(); + private readonly List branchesTaken = []; /// /// Gets a list of `#if`, `#elif`, and `#else` entities where the branch diff --git a/csharp/extractor/Semmle.Extraction.Tests/DotNet.cs b/csharp/extractor/Semmle.Extraction.Tests/DotNet.cs index 0f6683d329852..3c1b41f54bf1a 100644 --- a/csharp/extractor/Semmle.Extraction.Tests/DotNet.cs +++ b/csharp/extractor/Semmle.Extraction.Tests/DotNet.cs @@ -72,7 +72,7 @@ public void TestDotnetInfo() var dotnetCliInvoker = new DotNetCliInvokerStub(new List()); // Execute - var _ = MakeDotnet(dotnetCliInvoker); + _ = MakeDotnet(dotnetCliInvoker); // Verify var lastArgs = dotnetCliInvoker.GetLastArgs(); @@ -88,7 +88,7 @@ public void TestDotnetInfoFailure() // Execute try { - var _ = MakeDotnet(dotnetCliInvoker); + _ = MakeDotnet(dotnetCliInvoker); } // Verify diff --git a/csharp/extractor/Semmle.Extraction/Context.cs b/csharp/extractor/Semmle.Extraction/Context.cs index ec1ba53d08fce..8b7b750768c48 100644 --- a/csharp/extractor/Semmle.Extraction/Context.cs +++ b/csharp/extractor/Semmle.Extraction/Context.cs @@ -37,7 +37,7 @@ public class Context // A recursion guard against writing to the trap file whilst writing an id to the trap file. private bool writingLabel = false; - private readonly Queue labelQueue = new(); + private readonly Queue labelQueue = []; protected void DefineLabel(IEntity entity) { diff --git a/csharp/extractor/Semmle.Extraction/EscapingTextWriter.cs b/csharp/extractor/Semmle.Extraction/EscapingTextWriter.cs index 6294ec3ffd310..2374b398843d7 100644 --- a/csharp/extractor/Semmle.Extraction/EscapingTextWriter.cs +++ b/csharp/extractor/Semmle.Extraction/EscapingTextWriter.cs @@ -56,7 +56,7 @@ private void WriteEscaped(char c) default: wrapped.Write(c); break; - }; + } } public void WriteSubId(IEntity entity) diff --git a/csharp/extractor/Semmle.Extraction/Extractor/ExtractionContext.cs b/csharp/extractor/Semmle.Extraction/Extractor/ExtractionContext.cs index 539b339f85c30..26b30ad004b2e 100644 --- a/csharp/extractor/Semmle.Extraction/Extractor/ExtractionContext.cs +++ b/csharp/extractor/Semmle.Extraction/Extractor/ExtractionContext.cs @@ -65,7 +65,7 @@ public void Message(Message msg) // Roslyn framework has no apparent mechanism to associate assemblies with their files. // So this lookup table needs to be populated. - private readonly Dictionary referenceFilenames = new Dictionary(); + private readonly Dictionary referenceFilenames = []; public void SetAssemblyFile(string assembly, string file) { diff --git a/csharp/extractor/Semmle.Extraction/TrapWriter.cs b/csharp/extractor/Semmle.Extraction/TrapWriter.cs index 6baf55f7647a3..53c98003ef57c 100644 --- a/csharp/extractor/Semmle.Extraction/TrapWriter.cs +++ b/csharp/extractor/Semmle.Extraction/TrapWriter.cs @@ -48,7 +48,7 @@ public TrapWriter(ILogger logger, PathTransformer.ITransformedPath outputfile, s writerLazy = new Lazy(() => { - var tempPath = trap ?? FileUtils.GetTemporaryWorkingDirectory(out var _); + var tempPath = trap ?? FileUtils.GetTemporaryWorkingDirectory(out _); do { diff --git a/csharp/extractor/Semmle.Util/EnvironmentVariables.cs b/csharp/extractor/Semmle.Util/EnvironmentVariables.cs index 076507d07e0a2..1b0e40790ff18 100644 --- a/csharp/extractor/Semmle.Util/EnvironmentVariables.cs +++ b/csharp/extractor/Semmle.Util/EnvironmentVariables.cs @@ -45,7 +45,7 @@ public static bool GetBooleanOptOut(string name) public static bool GetBoolean(string name) { var env = Environment.GetEnvironmentVariable(name); - var _ = bool.TryParse(env, out var value); + _ = bool.TryParse(env, out var value); return value; } diff --git a/csharp/extractor/Semmle.Util/Initializer.cs b/csharp/extractor/Semmle.Util/Initializer.cs index 179c7efbe12ba..76d6b022de6ba 100644 --- a/csharp/extractor/Semmle.Util/Initializer.cs +++ b/csharp/extractor/Semmle.Util/Initializer.cs @@ -22,7 +22,7 @@ public Initializer(Action action) public void Run() { - var _ = doInit.Value; + _ = doInit.Value; } } } diff --git a/csharp/extractor/Semmle.Util/MemoizedFunc.cs b/csharp/extractor/Semmle.Util/MemoizedFunc.cs index f2018df8bb71f..d1a0edd3a4368 100644 --- a/csharp/extractor/Semmle.Util/MemoizedFunc.cs +++ b/csharp/extractor/Semmle.Util/MemoizedFunc.cs @@ -7,7 +7,7 @@ namespace Semmle.Util; public class MemoizedFunc where T1 : notnull { private readonly Func f; - private readonly Dictionary cache = new(); + private readonly Dictionary cache = []; public MemoizedFunc(Func f) { @@ -28,7 +28,7 @@ public T2 Invoke(T1 s) public class ConcurrentMemoizedFunc where T1 : notnull { private readonly Func f; - private readonly ConcurrentDictionary cache = new(); + private readonly ConcurrentDictionary cache = []; public ConcurrentMemoizedFunc(Func f) {