diff --git a/csharp/extractor/Semmle.Extraction.Tests/Layout.cs b/csharp/extractor/Semmle.Extraction.Tests/Layout.cs index 303ea5bf71e..49da0fd45c5 100644 --- a/csharp/extractor/Semmle.Extraction.Tests/Layout.cs +++ b/csharp/extractor/Semmle.Extraction.Tests/Layout.cs @@ -185,7 +185,7 @@ namespace Semmle.Extraction.Tests class StringTrapEmitter : ITrapEmitter { - string Content; + readonly string Content; public StringTrapEmitter(string content) { Content = content; diff --git a/csharp/extractor/Semmle.Extraction.Tests/Options.cs b/csharp/extractor/Semmle.Extraction.Tests/Options.cs index ce240ce146d..afb6df2e9ba 100644 --- a/csharp/extractor/Semmle.Extraction.Tests/Options.cs +++ b/csharp/extractor/Semmle.Extraction.Tests/Options.cs @@ -191,7 +191,7 @@ namespace Semmle.Extraction.Tests [Fact] public void ArchiveArguments() { - var sw = new StringWriter(); + using var sw = new StringWriter(); var file = Path.GetTempFileName(); try diff --git a/csharp/extractor/Semmle.Extraction/Entities/GeneratedLocation.cs b/csharp/extractor/Semmle.Extraction/Entities/GeneratedLocation.cs index 926fa722ae6..57f81d92b4c 100644 --- a/csharp/extractor/Semmle.Extraction/Entities/GeneratedLocation.cs +++ b/csharp/extractor/Semmle.Extraction/Entities/GeneratedLocation.cs @@ -32,7 +32,7 @@ namespace Semmle.Extraction.Entities class GeneratedLocationFactory : ICachedEntityFactory { - public static GeneratedLocationFactory Instance = new GeneratedLocationFactory(); + public static readonly GeneratedLocationFactory Instance = new GeneratedLocationFactory(); public GeneratedLocation Create(Context cx, string? init) => new GeneratedLocation(cx); } diff --git a/csharp/extractor/Semmle.Util.Tests/CanonicalPathCache.cs b/csharp/extractor/Semmle.Util.Tests/CanonicalPathCache.cs index c76256ef9b2..04ef8ff11a5 100644 --- a/csharp/extractor/Semmle.Util.Tests/CanonicalPathCache.cs +++ b/csharp/extractor/Semmle.Util.Tests/CanonicalPathCache.cs @@ -21,15 +21,7 @@ namespace SemmleTests.Semmle.Util // Change directories to a directory that is in canonical form. Directory.SetCurrentDirectory(cache.GetCanonicalPath(Path.GetTempPath())); - if (Win32.IsWindows()) - { - root = @"X:\"; - } - else - { - root = "/"; - } - + root = Win32.IsWindows() ? @"X:\" : "/"; } void IDisposable.Dispose() @@ -143,10 +135,10 @@ namespace SemmleTests.Semmle.Util Assert.Equal(0, cache.CacheSize); // The file "ABC" will fill the cache with parent directory info. - string cp = cache.GetCanonicalPath("ABC"); + cache.GetCanonicalPath("ABC"); Assert.True(cache.CacheSize == 2); - cp = cache.GetCanonicalPath("def"); + string cp = cache.GetCanonicalPath("def"); Assert.Equal(2, cache.CacheSize); Assert.Equal(Path.GetFullPath("def"), cp); } diff --git a/csharp/extractor/Semmle.Util.Tests/LongPaths.cs b/csharp/extractor/Semmle.Util.Tests/LongPaths.cs index c2a3f500de6..93f3a9f3353 100644 --- a/csharp/extractor/Semmle.Util.Tests/LongPaths.cs +++ b/csharp/extractor/Semmle.Util.Tests/LongPaths.cs @@ -93,7 +93,7 @@ namespace SemmleTests.Semmle.Util Assert.Equal("def", File.ReadAllText(shortPath)); } - byte[] buffer1 = new byte[10] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + readonly byte[] buffer1 = new byte[10] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; [Fact] public void CreateShortStream()