From fc72595eac6978816a0669dfac00b737a42ed0b5 Mon Sep 17 00:00:00 2001 From: Vladiwostok <55026261+Vladiwostok@users.noreply.github.com> Date: Mon, 7 Oct 2024 09:24:04 +0300 Subject: [PATCH] Fix Autofix for ExplicitlyAnnotatedUnittestCheck (#150) --- .../analysis/explicitly_annotated_unittests.d | 44 ++++++++++--------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/src/dscanner/analysis/explicitly_annotated_unittests.d b/src/dscanner/analysis/explicitly_annotated_unittests.d index db66e7e..7734e3d 100644 --- a/src/dscanner/analysis/explicitly_annotated_unittests.d +++ b/src/dscanner/analysis/explicitly_annotated_unittests.d @@ -28,8 +28,13 @@ extern(C++) class ExplicitlyAnnotatedUnittestCheck(AST) : BaseAnalyzerDmd return; if (!(d.storage_class & STC.safe || d.storage_class & STC.system)) - addErrorMessage(cast(ulong) d.loc.linnum, cast(ulong) d.loc.charnum, - KEY, MESSAGE); + addErrorMessage( + cast(ulong) d.loc.linnum, cast(ulong) d.loc.charnum, KEY, MESSAGE, + [ + AutoFix.insertionAt(d.loc.fileOffset, "@safe "), + AutoFix.insertionAt(d.loc.fileOffset, "@system ") + ] + ); super.visit(d); } @@ -73,27 +78,26 @@ unittest } }c, sac); - // TODO: Check and fix //// nested - //assertAutoFix(q{ - //unittest {} // fix:0 - //pure nothrow @nogc unittest {} // fix:0 + assertAutoFix(q{ + unittest {} // fix:0 + pure nothrow @nogc unittest {} // fix:0 - //struct Foo - //{ - //unittest {} // fix:1 - //pure nothrow @nogc unittest {} // fix:1 - //} - //}c, q{ - //@safe unittest {} // fix:0 - //pure nothrow @nogc @safe unittest {} // fix:0 + struct Foo + { + unittest {} // fix:1 + pure nothrow @nogc unittest {} // fix:1 + } + }c, q{ + @safe unittest {} // fix:0 + pure nothrow @nogc @safe unittest {} // fix:0 - //struct Foo - //{ - //@system unittest {} // fix:1 - //pure nothrow @nogc @system unittest {} // fix:1 - //} - //}c, sac); + struct Foo + { + @system unittest {} // fix:1 + pure nothrow @nogc @system unittest {} // fix:1 + } + }c, sac, true); stderr.writeln("Unittest for ExplicitlyAnnotatedUnittestCheck passed."); }