noSetterReturn
诊断类别:lint/correctness/noSetterReturn
¥Diagnostic Category: lint/correctness/noSetterReturn
自从:v1.0.0
¥Since: v1.0.0
来源:
¥Sources:
-
与以下相同:
no-setter-return
¥Same as:
no-setter-return
禁止从 setter 返回值
¥Disallow returning a value from a setter
虽然从 setter 返回值不会产生错误,但返回的值将被忽略。因此,从 setter 返回值要么是不必要的,要么是可能的错误。
¥While returning a value from a setter does not produce an error, the returned value is being ignored. Therefore, returning a value from a setter is either unnecessary or a possible error.
仅允许返回没有值,因为它是控制流语句。
¥Only returning without a value is allowed, as it’s a control flow statement.
¥Examples
¥Invalid
code-block.js:3:9 lint/correctness/noSetterReturn ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ The setter should not return a value.
1 │ class A {
2 │ set foo(x) {
> 3 │ return x;
│ ^^^^^^^^^
4 │ }
5 │ }
ℹ The setter is here:
1 │ class A {
> 2 │ set foo(x) {
│ ^^^^^^^^^^^^
> 3 │ return x;
> 4 │ }
│ ^
5 │ }
6 │
ℹ Returning a value from a setter is ignored.
code-block.js:3:9 lint/correctness/noSetterReturn ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ The setter should not return a value.
1 │ const b = {
2 │ set foo(x) {
> 3 │ return x;
│ ^^^^^^^^^
4 │ },
5 │ };
ℹ The setter is here:
1 │ const b = {
> 2 │ set foo(x) {
│ ^^^^^^^^^^^^
> 3 │ return x;
> 4 │ },
│ ^
5 │ };
6 │
ℹ Returning a value from a setter is ignored.
code-block.js:4:13 lint/correctness/noSetterReturn ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ The setter should not return a value.
2 │ set foo(x) {
3 │ if (x) {
> 4 │ return x;
│ ^^^^^^^^^
5 │ }
6 │ },
ℹ The setter is here:
1 │ const c = {
> 2 │ set foo(x) {
│ ^^^^^^^^^^^^
> 3 │ if (x) {
> 4 │ return x;
> 5 │ }
> 6 │ },
│ ^
7 │ };
8 │
ℹ Returning a value from a setter is ignored.
¥Valid
¥Related links