noSetterReturn
¥Summary
-
规则生效日期:
v1.0.0¥Rule available since:
v1.0.0 -
诊断类别:
lint/correctness/noSetterReturn¥Diagnostic Category:
lint/correctness/noSetterReturn -
此规则为推荐规则,默认启用。
¥This rule is recommended, which means is enabled by default.
-
此规则没有修复方案。
¥This rule doesn’t have a fix.
-
此规则的默认严重级别为 error。
¥The default severity of this rule is error.
-
来源:
¥Sources:
-
与
no-setter-return相同¥Same as
no-setter-return
-
¥How to configure
{ "linter": { "rules": { "correctness": { "noSetterReturn": "error" } } }}¥Description
禁止从 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
class A { set foo(x) { return x; }}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.
const b = { set foo(x) { return x; },};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.
const c = { set foo(x) { if (x) { return x; } },};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
// early-returnclass A { set foo(x) { if (x) { return; } }}// not a setterclass B { set(x) { return x; }}¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号