no-setter-return
eslint
No autofixRecommended
eslint.config.js
export default [
{
rules: {
"no-setter-return": "error",
},
},
];const foo = {
set a(value) {
this.val = value;
return value;
}
};
class Foo {
set a(value) {
this.val = value * 2;
return this.val;
}
}
const Bar = class {
static set a(value) {
if (value < 0) {
this.val = 0;
return 0;
}
this.val = value;
}
};
Object.defineProperty(foo, "bar", {
set(value) {
if (value < 0) {
return false;
}
this.val = value;
}
});const foo = {
set a(value) {
this.val = value;
}
};
class Foo {
set a(value) {
this.val = value * 2;
}
}
const Bar = class {
static set a(value) {
if (value < 0) {
this.val = 0;
return;
}
this.val = value;
}
};
Object.defineProperty(foo, "bar", {
set(value) {
if (value < 0) {
throw new Error("Negative value.");
}
this.val = value;
}
});Examples from the ESLint documentation.
no-setter-return
eslint
export default [
{
rules: {
"no-setter-return": "error",
},
},
];no-setter-return
eslint plugin · correctness
{
"rules": {
"no-setter-return": "error"
}
}correctness/noSetterReturn
correctness · since 1.0.0
{
"linter": {
"rules": {
"correctness": {
"noSetterReturn": "error"
}
}
}
}Disallow use of optional chaining in contexts where the undefined value is not allowed
Disallow unused private class members
Disallow \8 and \9 escape sequences in string literals
Disallow duplicate conditions in if-else-if chains
Enforce for loop update clause moving the counter in the right direction
Disallow assigning to imported bindings