no-setter-return
禁止从设置器返回值
配置文件 中的
"extends": "eslint:recommended"
属性启用了该规则
Setter 不能返回值。
虽然从 setter 返回值不会产生错误,但返回的值将被忽略。因此,从 setter 返回一个值要么是不必要的,要么是可能的错误,因为返回的值不能被使用。
规则详情
此规则不允许从 setter 中返回值,并在 setter 函数中报告 return
语句。
lB1qFUtbdzz1bdIAkSiNUp/DAy92vx+KdZdrcDav3U3wTlz+zh4DUDv+e4XGqPns8QXq9xBkaXykduUs2wZbEdReaFFDd9kJ9cZrfZQnvPru6Mdcdc/CuAaHWFvMlO7J
6gbj/vKpc49i6UN9nlHBz8gljX3BkyszfnBVLOcC+28=
- AHVROUsRlinT1wda8poy8CgvDdNHc9nCeexN6Y0MG04W8xZ5VyEoRscDtxnUJjVU6ECVnfgy8P6F5zS6XidV1PE9x+rhjYkjgd8bIAjVETOGJ/17cBFTBXMN8S2YJP15EZfdG6JEMmTwm+wFdBWPS1xWeA6OrLT6YSD7nzZt6XFMdRcRBjsS3Pg4sYTTzTEc1aqXMIc+qe2whk5rsFA3aryelOISVjPohOnPm1zex+uN8kcObuQ/pMM2Tm0s7WCMXLUrtUVtdU47bhxzHKJVkrKwYPyqVus9uROhx+tZC3MOGwFXTj1r29g3PEDY5nLr40+bgE0d38WjBPdSoFZueiqtx4VIR0SFTlV13IcqddA=
P6820Z8G9wSG50SW7a53cABVQLzOImcIRV+hQUkxjXCO67pG2wyQwHch0OYzHhMo
/*eslint no-setter-return: "error"*/
var 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;
}
});
L9CfmI+BHDwYx59RS77HEHanEO40ClscOusGIf+RQNhowUc7Zz7f+Hb0VCfK93W9
/*eslint no-setter-return: "error"*/
var 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;
}
});