Skip to content

Commit ea3f24b

Browse files
committed
update
- require-v-for-key - require-valid-default-prop - return-in-computed-property
1 parent bcb2d93 commit ea3f24b

File tree

3 files changed

+83
-80
lines changed

3 files changed

+83
-80
lines changed

docs/rules/require-v-for-key.md

+12-13
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,19 @@ This rule reports the elements which have `v-for` and do not have `v-bind:key`.
1212
This rule does not report custom components.
1313
It will be reported by [valid-v-for] rule.
1414

15-
:-1: Examples of **incorrect** code for this rule:
16-
17-
```html
18-
<div v-for="todo in todos"/>
19-
```
20-
21-
:+1: Examples of **correct** code for this rule:
22-
23-
```html
24-
<div
25-
v-for="todo in todos"
26-
:key="todo.id"
27-
/>
15+
<eslint-code-block :rules="{'vue/require-v-for-key': ['error']}">
16+
```vue
17+
<template>
18+
<!-- ✓ GOOD -->
19+
<div
20+
v-for="todo in todos"
21+
:key="todo.id"
22+
/>
23+
<!-- ✗ BAD -->
24+
<div v-for="todo in todos"/>
25+
</template>
2826
```
27+
</eslint-code-block>
2928

3029
## :wrench: Options
3130

docs/rules/require-valid-default-prop.md

+52-53
Original file line numberDiff line numberDiff line change
@@ -2,65 +2,64 @@
22

33
- :gear: This rule is included in all of `"plugin:vue/essential"`, `"plugin:vue/strongly-recommended"` and `"plugin:vue/recommended"`.
44

5-
This rule checks whether the default value of each prop is valid for the given type. It should report an error when default value for type `Array` or `Object` is not returned using function.
6-
75
## :book: Rule Details
86

9-
:-1: Examples of **incorrect** code for this rule:
10-
11-
```js
12-
props: {
13-
propA: {
14-
type: String,
15-
default: {}
16-
},
17-
propB: {
18-
type: String,
19-
default: []
20-
},
21-
propC: {
22-
type: Object,
23-
default: []
24-
},
25-
propD: {
26-
type: Array,
27-
default: []
28-
},
29-
propE: {
30-
type: Object,
31-
default: { message: 'hello' }
32-
}
33-
}
34-
```
35-
36-
:+1: Examples of **correct** code for this rule:
7+
This rule checks whether the default value of each prop is valid for the given type. It should report an error when default value for type `Array` or `Object` is not returned using function.
378

38-
```js
39-
props: {
40-
// basic type check (`null` means accept any type)
41-
propA: Number,
42-
// multiple possible types
43-
propB: [String, Number],
44-
// a number with default value
45-
propD: {
46-
type: Number,
47-
default: 100
48-
},
49-
// object/array defaults should be returned from a factory function
50-
propE: {
51-
type: Object,
52-
default() {
53-
return { message: 'hello' }
9+
<eslint-code-block :rules="{'vue/require-valid-default-prop': ['error']}">
10+
```vue
11+
<script>
12+
export default {
13+
props: {
14+
/* ✓ GOOD */
15+
// basic type check (`null` means accept any type)
16+
propA: Number,
17+
// multiple possible types
18+
propB: [String, Number],
19+
// a number with default value
20+
propD: {
21+
type: Number,
22+
default: 100
23+
},
24+
// object/array defaults should be returned from a factory function
25+
propE: {
26+
type: Object,
27+
default() {
28+
return { message: 'hello' }
29+
}
30+
},
31+
propF: {
32+
type: Array,
33+
default() {
34+
return []
35+
}
36+
},
37+
/* ✗ BAD */
38+
propA: {
39+
type: String,
40+
default: {}
41+
},
42+
propB: {
43+
type: String,
44+
default: []
45+
},
46+
propC: {
47+
type: Object,
48+
default: []
49+
},
50+
propD: {
51+
type: Array,
52+
default: []
53+
},
54+
propE: {
55+
type: Object,
56+
default: { message: 'hello' }
5457
}
55-
},
56-
propF: {
57-
type: Array,
58-
default() {
59-
return []
60-
}
61-
}
58+
}
6259
}
60+
</script>
6361
```
62+
</eslint-code-block>
6463

6564
## :wrench: Options
6665

docs/rules/return-in-computed-property.md

+19-14
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,34 @@ This rule enforces that a `return` statement is present in `computed` properties
88

99
:-1: Examples of **incorrect** code for this rule:
1010

11-
```js
12-
export default {
13-
computed: {
14-
foo () {},
15-
bar: function () {}
16-
}
17-
}
18-
```
19-
20-
:+1: Examples of **correct** code for this rule:
21-
22-
```js
11+
<eslint-code-block :rules="{'vue/return-in-computed-property': ['error']}">
12+
```vue
13+
<script>
2314
export default {
2415
computed: {
16+
/* ✓ GOOD */
2517
foo () {
26-
return true
18+
if (this.bar) {
19+
return this.baz
20+
} else {
21+
return this.baf
22+
}
2723
},
2824
bar: function () {
2925
return false
30-
}
26+
},
27+
/* ✗ BAD */
28+
baz () {
29+
if (this.baf) {
30+
return this.baf
31+
}
32+
},
33+
baf: function () {}
3134
}
3235
}
36+
</script>
3337
```
38+
</eslint-code-block>
3439

3540
## :wrench: Options
3641

0 commit comments

Comments
 (0)