
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.
103 lines
1.6 KiB
Plaintext
103 lines
1.6 KiB
Plaintext
== Why is this an issue?
|
|
|
|
The ``++default++`` clause should take appropriate action. Having an empty ``++default++`` is a waste of keystrokes.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,csharp]
|
|
----
|
|
enum Fruit
|
|
{
|
|
Apple,
|
|
Orange,
|
|
Banana
|
|
}
|
|
|
|
void PrintName(Fruit fruit)
|
|
{
|
|
switch(fruit)
|
|
{
|
|
case Fruit.Apple:
|
|
Console.WriteLine("apple");
|
|
break;
|
|
default: //Noncompliant
|
|
break;
|
|
}
|
|
}
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,csharp]
|
|
----
|
|
enum Fruit
|
|
{
|
|
Apple,
|
|
Orange,
|
|
Banana
|
|
}
|
|
|
|
void PrintName(Fruit fruit)
|
|
{
|
|
switch(fruit)
|
|
{
|
|
case Fruit.Apple:
|
|
Console.WriteLine("apple");
|
|
break;
|
|
default:
|
|
throw new NotSupportedException();
|
|
}
|
|
}
|
|
----
|
|
or
|
|
|
|
[source,csharp]
|
|
----
|
|
void PrintName(Fruit fruit)
|
|
{
|
|
switch(fruit)
|
|
{
|
|
case Fruit.Apple:
|
|
Console.WriteLine("apple");
|
|
break;
|
|
}
|
|
}
|
|
----
|
|
|
|
|
|
=== Exceptions
|
|
|
|
``++default++`` clauses containing only a comment are ignored with the assumption that they are empty on purpose and the comment documents why.
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Remove this empty "default" clause.
|
|
|
|
|
|
=== Highlighting
|
|
|
|
the whole default clause
|
|
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
=== relates to: S108
|
|
|
|
=== relates to: S131
|
|
|
|
=== on 5 Feb 2016, 16:42:33 Ann Campbell wrote:
|
|
Normally RSPEC-131 would be expected to cover this case, but in C# that rule is thought to make too much noise, while at the same time, there is still a desire to flag and eliminate empty ``++default++``s
|
|
|
|
endif::env-github,rspecator-view[]
|