[no-setter-return] Add option to ignore `set: () => value`
See original GitHub issueWhat rule do you want to change?
no-setter-return
Does this change cause the rule to produce more or fewer warnings?
Fewer warnings if enabled.
How will the change be implemented? (New option, new default behaviour, etc.)?
Adding an object as an optional second parameter which supports the option ignoreExpressions
(or something similarly-named):
{
"no-setter-return": [
"error",
{
"ignoreExpressions": "always | never | ignore"
}
]
}
Please provide some example code that this change will affect:
In the setter function below, the return value is purely implicit, and shouldn’t be held in the same light as an explicit return
statement (which is indicative of a refactoring or authoring error):
let foo;
Object.defineProperty(subject, "foo", {
get: () => foo,
set: to => foo = to,
});
What does the rule currently do for this code?
Raise an error because an assigned value is implicitly returned by an arrow-function expression.
What will the rule do after it’s changed?
Allow authors to keep their getter/setter pairs terse and nicely-aligned (as illustrated above).
Are you willing to submit a pull request to implement this change?
Yes.
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
The rule is precisely to block a return value though - in your case, you’re not trying to return anything, so you definitely should be using curly braces.
@ljharb No, the intent was keeping code brief when a return value is meaningless, irrespective of whether somebody’s siphoned a setter out of a property descriptor or not.
I already regret filing this stupid issue.