85 lines
1.3 KiB
Plaintext
85 lines
1.3 KiB
Plaintext
include::../description.adoc[]
|
|
|
|
Additionally, one shouldn't use a class to define exclusively static methods. Instead one can use a module, or better, export each function separately.
|
|
|
|
== Why is this an issue?
|
|
|
|
Using an empty class serves no purpose and can hinder the readability of the code.
|
|
|
|
[source,javascript]
|
|
----
|
|
class Foo {
|
|
static bar() {
|
|
// ...
|
|
}
|
|
}
|
|
----
|
|
|
|
//=== What is the potential impact?
|
|
|
|
== How to fix it
|
|
|
|
You can export the functions that you wish to make available.
|
|
|
|
[source,javascript]
|
|
----
|
|
export function bar() {
|
|
// ...
|
|
}
|
|
----
|
|
|
|
=== Code examples
|
|
|
|
==== Noncompliant code example
|
|
|
|
[source,javascript,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
class Foo { // Noncompliant
|
|
static bar() {
|
|
// ...
|
|
}
|
|
}
|
|
----
|
|
|
|
==== Compliant solution
|
|
|
|
[source,javascript,diff-id=1,diff-type=compliant]
|
|
----
|
|
export function bar() {
|
|
// ...
|
|
}
|
|
----
|
|
|
|
==== Noncompliant code example
|
|
|
|
[source,javascript,diff-id=2,diff-type=noncompliant]
|
|
----
|
|
class DoAndLog { // Noncompliant
|
|
constructor () {
|
|
console.log('I\'m done!');
|
|
}
|
|
}
|
|
----
|
|
|
|
==== Compliant solution
|
|
|
|
[source,javascript,diff-id=2,diff-type=compliant]
|
|
----
|
|
function doAndLog() {
|
|
console.log('I\'m done!');
|
|
}
|
|
----
|
|
|
|
//=== How does this work?
|
|
|
|
//=== Pitfalls
|
|
|
|
//=== Going the extra mile
|
|
|
|
//== Resources
|
|
|
|
//=== Documentation
|
|
//=== Articles & blog posts
|
|
//=== Conference presentations
|
|
//=== Standards
|