noSetterReturn
此内容尚不支持你的语言。
Diagnostic Category: lint/correctness/noSetterReturn
Since: v1.0.0
Sources:
- Same as:
no-setter-return
Disallow returning a value from a 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
Section titled ExamplesInvalid
Section titled Invalidcode-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.