
When an include is not surrounded by empty lines, its content is inlined on the same line as the adjacent content. That can lead to broken tags and other display issues. This PR fixes all such includes and introduces a validation step that forbids introducing the same problem again.
88 lines
1.8 KiB
Plaintext
88 lines
1.8 KiB
Plaintext
== Why is this an issue?
|
|
|
|
Unnecessarily verbose declarations and initializations make it harder to read the code, and should be simplified.
|
|
|
|
|
|
Specifically the following should be omitted when they can be inferred:
|
|
|
|
* array element type
|
|
* array size
|
|
* ``++new DelegateType++``
|
|
* ``++new Nullable<Type>++``
|
|
* object or collection initializers ({})
|
|
* type of lambda expression parameters
|
|
* parameter declarations of anonymous methods when the parameters are not used.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,csharp]
|
|
----
|
|
var l = new List<int>() {}; // Noncompliant, {} can be removed
|
|
var o = new object() {}; // Noncompliant, {} can be removed
|
|
|
|
var ints = new int[] {1, 2, 3}; // Noncompliant, int can be omitted
|
|
ints = new int[3] {1, 2, 3}; // Noncompliant, the size specification can be removed
|
|
|
|
int? i = new int?(5); // Noncompliant new int? could be omitted, it can be inferred from the declaration, and there's implicit conversion from T to T?
|
|
var j = new int?(5);
|
|
|
|
Func<int, int> f1 = (int i) => 1; //Noncompliant, can be simplified
|
|
|
|
class Class
|
|
{
|
|
private event EventHandler MyEvent;
|
|
|
|
public Class()
|
|
{
|
|
MyEvent += new EventHandler((a,b)=>{ }); // Noncompliant, needlessly verbose
|
|
}
|
|
}
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,csharp]
|
|
----
|
|
var l = new List<int>();
|
|
var o = new object();
|
|
|
|
var ints = new [] {1, 2, 3};
|
|
ints = new [] {1, 2, 3};
|
|
|
|
int? i = 5;
|
|
var j = new int?(5);
|
|
|
|
Func<int, int> f1 = (i) => 1;
|
|
|
|
class Class
|
|
{
|
|
private event EventHandler MyEvent;
|
|
|
|
public Class()
|
|
{
|
|
MyEvent += (a,b)=>{ };
|
|
}
|
|
}
|
|
----
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
include::../message.adoc[]
|
|
|
|
include::../highlighting.adoc[]
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
include::../comments-and-links.adoc[]
|
|
|
|
endif::env-github,rspecator-view[]
|