From 780294034f658d5c1c53fa7553fdda1f99514ed0 Mon Sep 17 00:00:00 2001 From: Owen Smith Date: Thu, 25 Apr 2024 20:00:43 +0000 Subject: [PATCH] Fix the #nullable annotation (#950) --- .../Async/Generator/FileCollector.cs | 2 +- .../Async/Generator/FileCollectorTests.cs | 12 ++++++------ .../Async/Generator/SyncGeneratorTests.cs | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/D2L.CodeStyle.Analyzers/Async/Generator/FileCollector.cs b/src/D2L.CodeStyle.Analyzers/Async/Generator/FileCollector.cs index f4f5b9fa..e70ecbc5 100644 --- a/src/D2L.CodeStyle.Analyzers/Async/Generator/FileCollector.cs +++ b/src/D2L.CodeStyle.Analyzers/Async/Generator/FileCollector.cs @@ -84,7 +84,7 @@ public string CollectSource() { m_out.AppendLine( "#pragma warning disable CS1572" ); // This allows us to copy+paste annotations but otherwise does not emit diagnostics // otherwise we get "CS8669: The annotation for nullable reference types should only be used in code within a '#nullable' annotations context. Auto-generated code requires an explicit '#nullable' directive in source." - m_out.AppendLine( "#nullable annotations" ); + m_out.AppendLine( "#nullable enable annotations" ); // File-scoped usings: m_out.Append( m_root.Usings.ToFullString() ); diff --git a/tests/D2L.CodeStyle.Analyzers.Test/Async/Generator/FileCollectorTests.cs b/tests/D2L.CodeStyle.Analyzers.Test/Async/Generator/FileCollectorTests.cs index 6d7faacb..01b992e4 100644 --- a/tests/D2L.CodeStyle.Analyzers.Test/Async/Generator/FileCollectorTests.cs +++ b/tests/D2L.CodeStyle.Analyzers.Test/Async/Generator/FileCollectorTests.cs @@ -24,7 +24,7 @@ void SomeMethod() {} ); Assert.AreEqual( @"#pragma warning disable CS1572 -#nullable annotations +#nullable enable annotations ", collector.CollectSource() ); } @@ -53,7 +53,7 @@ void MyMethodBefore() { ); Assert.AreEqual( @"#pragma warning disable CS1572 -#nullable annotations +#nullable enable annotations using Foo; @@ -91,7 +91,7 @@ void MyMethodBefore() { ); Assert.AreEqual( @"#pragma warning disable CS1572 -#nullable annotations +#nullable enable annotations using Foo; @@ -127,7 +127,7 @@ void MyMethodBefore() {{ ); Assert.AreEqual( @$"#pragma warning disable CS1572 -#nullable annotations +#nullable enable annotations partial {kind} X {{ any text @@ -167,7 +167,7 @@ class Ignored2 {} ); Assert.AreEqual( @"#pragma warning disable CS1572 -#nullable annotations +#nullable enable annotations using Foo; @@ -249,7 +249,7 @@ void MyBeforeMethod4() { } ); Assert.AreEqual( @"#pragma warning disable CS1572 -#nullable annotations +#nullable enable annotations using Foo; diff --git a/tests/D2L.CodeStyle.Analyzers.Test/Async/Generator/SyncGeneratorTests.cs b/tests/D2L.CodeStyle.Analyzers.Test/Async/Generator/SyncGeneratorTests.cs index b467d769..44ad47cf 100644 --- a/tests/D2L.CodeStyle.Analyzers.Test/Async/Generator/SyncGeneratorTests.cs +++ b/tests/D2L.CodeStyle.Analyzers.Test/Async/Generator/SyncGeneratorTests.cs @@ -58,7 +58,7 @@ sealed class Bar { ); AssertNewTrees( result, @"#pragma warning disable CS1572 -#nullable annotations +#nullable enable annotations using System; using System.IO; @@ -92,7 +92,7 @@ partial interface IFoo { ); AssertNewTrees( result, @"#pragma warning disable CS1572 -#nullable annotations +#nullable enable annotations using System; using System.Threading.Tasks; @@ -142,7 +142,7 @@ public async Task BarAsync() {} ); AssertNewTrees( result, @"#pragma warning disable CS1572 -#nullable annotations +#nullable enable annotations using System; using System.IO; @@ -156,7 +156,7 @@ partial class Bar { [Blocking] public void Baz( StreamWriter x ) { return; } }", @"#pragma warning disable CS1572 -#nullable annotations +#nullable enable annotations using System; using System.IO;