rspec/rules/S3346/csharp/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

73 lines
1.8 KiB
Plaintext

== Why is this an issue?
An assertion is a piece of code that's used during development when the compilation debug mode is activated. It allows a program to check itself as it runs. When an assertion is true, that means everything is operating as expected.
In non-debug mode, all ``++Debug.Assert++`` are automatically left out. So, by contract, the boolean expressions that are evaluated by those assertions must absolutely not contain any side effects. Otherwise, when leaving the Debug mode, the functional behavior of the application is not the same anymore.
The rule will raise if the method name starts with any of the following ``++remove++``, ``++delete++``, ``++add++``, ``++pop++``, ``++update++``, ``++retain++``, ``++insert++``, ``++push++``, ``++append++``, ``++clear++``, ``++dequeue++``, ``++enqueue++``, ``++dispose++``, ``++put++``, or ``++set++``, although ``++SetEquals++`` will be ignored.
=== Noncompliant code example
[source,csharp]
----
Debug.Assert(list.Remove("dog"));
----
=== Compliant solution
[source,csharp]
----
bool result = list.Remove("dog");
Debug.Assert(result);
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Expressions used in "Debug.Assert" should not produce side effects.
include::../highlighting.adoc[]
'''
== Comments And Links
(visible only on this page)
=== on 28 Mar 2017, 09:38:41 Valeri Hristov wrote:
The JAVA implementation checks for certain verbs in the method name:
* "remove"
* "delete"
* "put"
* "set"
* "add"
* "pop"
* "update"
* "retain"
We could add a few more too:
* "insert"
* "push"
* "append"
* "clear"
* "dequeue"
=== on 22 May 2017, 14:22:31 Michal Barczyk wrote:
Also added "dispose"
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]