97 lines
1.4 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
2020-06-30 12:49:37 +02:00
include::../description.adoc[]
=== Noncompliant code example
2020-06-30 12:49:37 +02:00
2022-02-04 17:28:24 +01:00
[source,javascript]
2020-06-30 12:49:37 +02:00
----
class A {
#x: number = 0;
#y: number = 0;
2020-06-30 12:49:37 +02:00
get x() { // Noncompliant: field 'x' is not used in the return value
return this.#y;
2020-06-30 12:49:37 +02:00
}
set x(val: number) { // Noncompliant: field 'x' is not updated
this.#y = val;
2020-06-30 12:49:37 +02:00
}
getY() { // Noncompliant: field 'y' is not used in the return value
}
setY(val: number) { // Noncompliant: field 'y' is not updated
2020-06-30 12:49:37 +02:00
}
}
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;
}
});
2020-06-30 12:49:37 +02:00
----
=== Compliant solution
2020-06-30 12:49:37 +02:00
2022-02-04 17:28:24 +01:00
[source,javascript]
2020-06-30 12:49:37 +02:00
----
class A {
#x: number = 0;
#y: number = 0;
2020-06-30 12:49:37 +02:00
get x() {
return this.#x;
2020-06-30 12:49:37 +02:00
}
set x(val: number) {
this.#x = val;
2020-06-30 12:49:37 +02:00
}
getY() {
return this.#y;
}
setY(val: number) {
this.#y = val;
2020-06-30 12:49:37 +02:00
}
}
const obj = {
_x: 0,
_y: 0,
get x() {
return this._x;
}
};
let x = 0;
let y = 0;
Object.defineProperty(o, 'x', {
get() {
return x;
}
});
2020-06-30 12:49:37 +02:00
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
include::../highlighting.adoc[]
endif::env-github,rspecator-view[]