Skip to content

Commit 54ce73b

Browse files
authored
Merge pull request github#3995 from hvitved/csharp/fix-alerts
C#: Fix a few alerts
2 parents 18fa6b6 + e08e7cd commit 54ce73b

File tree

5 files changed

+7
-15
lines changed

5 files changed

+7
-15
lines changed

csharp/extractor/Semmle.Extraction.Tests/Layout.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public static void Emit(this TrapWriter trapFile, string s)
185185

186186
class StringTrapEmitter : ITrapEmitter
187187
{
188-
string Content;
188+
readonly string Content;
189189
public StringTrapEmitter(string content)
190190
{
191191
Content = content;

csharp/extractor/Semmle.Extraction.Tests/Options.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public void Fast()
191191
[Fact]
192192
public void ArchiveArguments()
193193
{
194-
var sw = new StringWriter();
194+
using var sw = new StringWriter();
195195
var file = Path.GetTempFileName();
196196

197197
try

csharp/extractor/Semmle.Extraction/Entities/GeneratedLocation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public override void WriteId(TextWriter trapFile)
3232

3333
class GeneratedLocationFactory : ICachedEntityFactory<string?, GeneratedLocation>
3434
{
35-
public static GeneratedLocationFactory Instance = new GeneratedLocationFactory();
35+
public static readonly GeneratedLocationFactory Instance = new GeneratedLocationFactory();
3636

3737
public GeneratedLocation Create(Context cx, string? init) => new GeneratedLocation(cx);
3838
}

csharp/extractor/Semmle.Util.Tests/CanonicalPathCache.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,7 @@ public CanonicalPathCacheTest()
2121
// Change directories to a directory that is in canonical form.
2222
Directory.SetCurrentDirectory(cache.GetCanonicalPath(Path.GetTempPath()));
2323

24-
if (Win32.IsWindows())
25-
{
26-
root = @"X:\";
27-
}
28-
else
29-
{
30-
root = "/";
31-
}
32-
24+
root = Win32.IsWindows() ? @"X:\" : "/";
3325
}
3426

3527
void IDisposable.Dispose()
@@ -143,10 +135,10 @@ public void CanonicalPathCacheSize()
143135
Assert.Equal(0, cache.CacheSize);
144136

145137
// The file "ABC" will fill the cache with parent directory info.
146-
string cp = cache.GetCanonicalPath("ABC");
138+
cache.GetCanonicalPath("ABC");
147139
Assert.True(cache.CacheSize == 2);
148140

149-
cp = cache.GetCanonicalPath("def");
141+
string cp = cache.GetCanonicalPath("def");
150142
Assert.Equal(2, cache.CacheSize);
151143
Assert.Equal(Path.GetFullPath("def"), cp);
152144
}

csharp/extractor/Semmle.Util.Tests/LongPaths.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public void Replace()
9393
Assert.Equal("def", File.ReadAllText(shortPath));
9494
}
9595

96-
byte[] buffer1 = new byte[10] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
96+
readonly byte[] buffer1 = new byte[10] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
9797

9898
[Fact]
9999
public void CreateShortStream()

0 commit comments

Comments
 (0)