From 6c8d13306044a2caa471f4b0822e1a9156c24b03 Mon Sep 17 00:00:00 2001 From: mary-georgiou-sonarsource <89914005+mary-georgiou-sonarsource@users.noreply.github.com> Date: Wed, 16 Apr 2025 18:17:17 +0200 Subject: [PATCH 1/3] Add exclusion to rspec --- rules/S3236/rule.adoc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/rules/S3236/rule.adoc b/rules/S3236/rule.adoc index f99f539d576..bb170a9109f 100644 --- a/rules/S3236/rule.adoc +++ b/rules/S3236/rule.adoc @@ -1,6 +1,6 @@ == Why is this an issue? -Caller information attributes: ``++CallerFilePathAttribute++``, ``++CallerLineNumberAttribute++``, and ``++CallerArgumentExpressionAttribute++`` provide a way to get information about the caller of a method through optional parameters. But the arguments for these optional parameters are only generated if they are not explicitly defined in the call. Thus, specifying the argument values defeats the purpose of the attributes. +Caller information attributes: `CallerFilePathAttribute`, `CallerLineNumberAttribute`, and `CallerArgumentExpressionAttribute` provide a way to get information about the caller of a method through optional parameters. But the arguments for these optional parameters are only generated if they are not explicitly defined in the call. Thus, specifying the argument values defeats the purpose of the attributes. === Noncompliant code example @@ -41,5 +41,6 @@ void MyMethod() === Exceptions -``++CallerMemberName++`` is not checked to avoid False-Positives with WPF/UWP applications. - +`CallerMemberName` is not checked to avoid False-Positives with WPF/UWP applications. +`System.Diagnostics.Debug.Assert` is excluded. The signature of this method has been updated from .NET9 onwards from `public static void Assert(bool condition, string message)` to `public static void Assert([DoesNotReturnIf(false)] bool condition, [CallerArgumentExpression(nameof(condition))] string? message = null)`. +The default message provided by this method is the failed assertion and its position in the code, however a custom message from the developer is many times preferred as an explanation of the failed assertion. \ No newline at end of file From b19d564db027ee883c1ac93a84e4f320d292a6af Mon Sep 17 00:00:00 2001 From: Mary Georgiou <89914005+mary-georgiou-sonarsource@users.noreply.github.com> Date: Thu, 17 Apr 2025 10:56:09 +0200 Subject: [PATCH 2/3] Update rules/S3236/rule.adoc Co-authored-by: Sebastien Marichal --- rules/S3236/rule.adoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rules/S3236/rule.adoc b/rules/S3236/rule.adoc index bb170a9109f..313f6d57339 100644 --- a/rules/S3236/rule.adoc +++ b/rules/S3236/rule.adoc @@ -41,6 +41,6 @@ void MyMethod() === Exceptions -`CallerMemberName` is not checked to avoid False-Positives with WPF/UWP applications. -`System.Diagnostics.Debug.Assert` is excluded. The signature of this method has been updated from .NET9 onwards from `public static void Assert(bool condition, string message)` to `public static void Assert([DoesNotReturnIf(false)] bool condition, [CallerArgumentExpression(nameof(condition))] string? message = null)`. +* `CallerMemberName` is not checked to avoid False-Positives with WPF/UWP applications. +* `System.Diagnostics.Debug.Assert` is excluded. The signature of this method has been updated from .NET9 onwards from `public static void Assert(bool condition, string message)` to `public static void Assert([DoesNotReturnIf(false)] bool condition, [CallerArgumentExpression(nameof(condition))] string? message = null)`. The default message provided by this method is the failed assertion and its position in the code, however a custom message from the developer is many times preferred as an explanation of the failed assertion. \ No newline at end of file From 42eb550c8c23f59cd328072893ba610920d00585 Mon Sep 17 00:00:00 2001 From: mary-georgiou-sonarsource <89914005+mary-georgiou-sonarsource@users.noreply.github.com> Date: Thu, 17 Apr 2025 10:58:40 +0200 Subject: [PATCH 3/3] apply comments --- rules/S3236/rule.adoc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/rules/S3236/rule.adoc b/rules/S3236/rule.adoc index bb170a9109f..e66a56abd36 100644 --- a/rules/S3236/rule.adoc +++ b/rules/S3236/rule.adoc @@ -41,6 +41,5 @@ void MyMethod() === Exceptions -`CallerMemberName` is not checked to avoid False-Positives with WPF/UWP applications. -`System.Diagnostics.Debug.Assert` is excluded. The signature of this method has been updated from .NET9 onwards from `public static void Assert(bool condition, string message)` to `public static void Assert([DoesNotReturnIf(false)] bool condition, [CallerArgumentExpression(nameof(condition))] string? message = null)`. -The default message provided by this method is the failed assertion and its position in the code, however a custom message from the developer is many times preferred as an explanation of the failed assertion. \ No newline at end of file +* `CallerMemberName` is not checked to avoid False-Positives with WPF/UWP applications. +* `System.Diagnostics.Debug.Assert` is excluded as a custom message from the developer is sometimes preferred as an explanation of the failed assertion. \ No newline at end of file