Rudy Regazzoni 1763d7fe2b
Modify S1186: Migrate to LayC - empty methods (#3285)
## Review

A dedicated reviewer checked the rule description successfully for:

- [ ] logical errors and incorrect information
- [ ] information gaps and missing content
- [ ] text style and tone
- [ ] PR summary and labels follow [the
guidelines](https://github.com/SonarSource/rspec/#to-modify-an-existing-rule)
2023-10-18 18:21:32 +02:00

80 lines
1.4 KiB
Plaintext

== Why is this an issue?
:operationName: method
include::../description.adoc[]
=== Exceptions
This does not raise an issue in the following cases:
* Function expressions and arrow functions as they can denote default values
* Empty functions with a name starting with the prefix `on` like `onClick`.
[source,javascript]
----
static defaultProps = {
listStyle: () => {}
};
function onClick() {
}
----
== How to fix it
=== Code examples
==== Noncompliant code example
[source,javascript,diff-id=1,diff-type=noncompliant]
----
function shouldNotBeEmpty() { // Noncompliant - method is empty
}
function notImplemented() { // Noncompliant - method is empty
}
function emptyOnPurpose() { // Noncompliant - method is empty
}
----
==== Compliant solution
[source,javascript,diff-id=1,diff-type=compliant]
----
function shouldNotBeEmpty() {
doSomething();
}
function notImplemented() {
throw new Error("notImplemented() cannot be performed because ...");
}
function emptyOnPurpose() {
// comment explaining why the method is empty
}
----
== Resources
=== Documentation
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions[MDN - Functions]
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[]