Fred Tingaud 51369b610e
Make sure that includes are always surrounded by empty lines (#2270)
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.
2023-06-22 10:38:01 +02:00

109 lines
1.6 KiB
Plaintext

== Why is this an issue?
include::../description.adoc[]
=== Noncompliant code example
[source,javascript]
----
switch (param) { //missing default clause
case 0:
doSomething();
break;
case 1:
doSomethingElse();
break;
}
switch (param) {
default: // default clause should be the last one
error();
break;
case 0:
doSomething();
break;
case 1:
doSomethingElse();
break;
}
----
=== Compliant solution
[source,javascript]
----
switch (param) {
case 0:
doSomething();
break;
case 1:
doSomethingElse();
break;
default:
error();
break;
}
----
=== Exceptions
The rule ignores ``++switch++`` statements where the discriminant is a TypeScript union and there is a ``++case++`` branch for each constituent.
[source,javascript]
----
type Season = 'Spring' | 'Summer' | 'Fall' | 'Winter';
let season: Season;
switch (season) {
case 'Spring':
wakeUp();
break;
case 'Summer':
getOut();
break;
case 'Fall':
saveFood();
break;
case 'Winter':
sleep();
break;
}
----
The same applies for TypeScript enums.
[source,javascript]
----
enum Direction {
Up,
Down
}
let dir: Direction;
switch (dir) {
case Direction.Up:
getUp();
break;
case Direction.Down:
getDown();
break;
}
----
include::../see.adoc[]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
'''
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]