56 lines
952 B
Plaintext
Raw Normal View History

== Why is this an issue?
2020-06-30 12:48:07 +02:00
When an object is created with a setter for a property but without a getter for that property, the property is inaccessible and is thus useless.
2021-02-02 15:02:10 +01:00
2020-06-30 12:48:07 +02:00
This rule also enforces the reverse situation (getter but no setter).
=== Noncompliant code example
2020-06-30 12:48:07 +02:00
2022-02-04 17:28:24 +01:00
[source,javascript]
2020-06-30 12:48:07 +02:00
----
var obj = {
set foo(value) {
this.fooval = value;
}
};
----
=== Compliant solution
2020-06-30 12:48:07 +02:00
2022-02-04 17:28:24 +01:00
[source,javascript]
2020-06-30 12:48:07 +02:00
----
var obj = {
set foo(value) {
this.fooval = value;
},
get foo() {
return this.fooval;
}
};
----
or
2021-02-02 15:02:10 +01:00
2022-02-04 17:28:24 +01:00
[source,javascript]
2020-06-30 12:48:07 +02:00
----
var obj = {
setFoo(value) { // a standard method, not a setter
this.fooval = value;
}
};
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Provide a [setter|getter] matching this [getter|setter] or replace this accessor with a simple method.
endif::env-github,rspecator-view[]