rspec/rules/S108/ruby/rule.adoc

52 lines
855 B
Plaintext
Raw Normal View History

2020-06-30 10:16:44 +02:00
include::../description.adoc[]
== Noncompliant Code Example
2022-02-04 17:28:24 +01:00
[source,ruby]
2020-06-30 10:16:44 +02:00
----
def compute(a, b)
sum = a + b
if sum > 0 # Noncompliant; empty on purpose or missing piece of code?
end
puts "Result: #{sum}"
end
----
== Compliant Solution
2022-02-04 17:28:24 +01:00
[source,ruby]
2020-06-30 10:16:44 +02:00
----
def compute(a, b)
sum = a + b
if sum > 0
puts "Positive result"
end
puts "Result: #{sum}"
end
----
== Exceptions
When a block contains a comment, this block is not considered to be empty.
2021-02-02 15:02:10 +01:00
2021-01-27 13:42:22 +01:00
``++while++`` and ``++unless++`` loops are also exception to the rule.
2020-06-30 10:16:44 +02:00
----
while @order.process_next; end # Compliant
----
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[]