You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By default, this rule does not enforce getter/setter pairs in class declarations and class expressions,
as the default value for enforceForClassMembers is false.
When enforceForClassMembers is set to true:
"setWithoutGet": true will also warn for setters without getters in classes.
Examples of incorrect code for { "setWithoutGet": true, "enforceForClassMembers": true }:
I can think of at least one legit use case of using setters without getters. For example, in a test, where you pass a test object into some API that mutates it by assigning to its properties. If what you cared about is the order and perhaps timing of the mutations, then you could use setters to receive the values and make the assertions on that. You would not read from those properties, so there's no need for getters on those same properties. Does that sound like a legit use case?
I agree that there seem to be valid use cases that this rule would prevent, but in practice it seems that it hasn't been an issue even though it's been enabled since this rule has been present ("setWithoutGet": true is the default).
So, let's also enforce it in classes to be consistent.
https://eslint.org/docs/rules/accessor-pairs
Add the
enforceForClassMembers
option to theaccessor-pairs
rule.Current rule:
Proposed rule:
enforceForClassMembers
By default, this rule does not enforce getter/setter pairs in class declarations and class expressions,
as the default value for
enforceForClassMembers
isfalse
.When
enforceForClassMembers
is set totrue
:"setWithoutGet": true
will also warn for setters without getters in classes.Examples of incorrect code for
{ "setWithoutGet": true, "enforceForClassMembers": true }
:The text was updated successfully, but these errors were encountered: