97 lines
1.4 KiB
Plaintext
97 lines
1.4 KiB
Plaintext
== Why is this an issue?
|
|
|
|
include::../description.adoc[]
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,javascript]
|
|
----
|
|
class A {
|
|
#x: number = 0;
|
|
#y: number = 0;
|
|
|
|
get x() { // Noncompliant: field 'x' is not used in the return value
|
|
return this.#y;
|
|
}
|
|
|
|
set x(val: number) { // Noncompliant: field 'x' is not updated
|
|
this.#y = val;
|
|
}
|
|
|
|
getY() { // Noncompliant: field 'y' is not used in the return value
|
|
}
|
|
|
|
setY(val: number) { // Noncompliant: field 'y' is not updated
|
|
}
|
|
}
|
|
|
|
const obj = {
|
|
_x: 0,
|
|
_y: 0,
|
|
get x() { // Noncompliant: field '_x' is not used in the return value
|
|
return this._y;
|
|
}
|
|
};
|
|
|
|
let x = 0;
|
|
let y = 0;
|
|
Object.defineProperty(o, 'x', {
|
|
get() { // Noncompliant: variable 'x' is not used in the return value
|
|
return y;
|
|
}
|
|
});
|
|
----
|
|
|
|
=== Compliant solution
|
|
|
|
[source,javascript]
|
|
----
|
|
class A {
|
|
#x: number = 0;
|
|
#y: number = 0;
|
|
|
|
get x() {
|
|
return this.#x;
|
|
}
|
|
|
|
set x(val: number) {
|
|
this.#x = val;
|
|
}
|
|
|
|
getY() {
|
|
return this.#y;
|
|
}
|
|
|
|
setY(val: number) {
|
|
this.#y = val;
|
|
}
|
|
}
|
|
|
|
const obj = {
|
|
_x: 0,
|
|
_y: 0,
|
|
get x() {
|
|
return this._x;
|
|
}
|
|
};
|
|
|
|
let x = 0;
|
|
let y = 0;
|
|
Object.defineProperty(o, 'x', {
|
|
get() {
|
|
return x;
|
|
}
|
|
});
|
|
----
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
include::../message.adoc[]
|
|
|
|
include::../highlighting.adoc[]
|
|
|
|
endif::env-github,rspecator-view[]
|