useGetterReturn
诊断类别:lint/suspicious/useGetterReturn
¥Diagnostic Category: lint/suspicious/useGetterReturn
自从:v1.0.0
¥Since: v1.0.0
来源:
¥Sources:
-
与以下相同:
getter-return
¥Same as:
getter-return
强制 get
方法始终返回一个值。
¥Enforce get
methods to always return a value.
¥Examples
¥Invalid
code-block.js:2:5 lint/suspicious/useGetterReturn ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ This getter should return a value.
1 │ class Person {
> 2 │ get firstName() {}
│ ^^^^^^^^^^^^^^^^^^
3 │ }
4 │
code-block.js:3:9 lint/suspicious/useGetterReturn ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ This return should return a value because it is located in a getter.
1 │ const obj = {
2 │ get firstName() {
> 3 │ return;
│ ^^^^^^^
4 │ }
5 │ }
code-block.js:2:5 lint/suspicious/useGetterReturn ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ This getter should return a value.
1 │ class Option {
> 2 │ get value() {
│ ^^^^^^^^^^^^^
> 3 │ if (this.hasValue) {
> 4 │ log();
> 5 │ } else {
> 6 │ return null;
> 7 │ }
> 8 │ }
│ ^
9 │ }
10 │
¥Valid
¥Related links