Skip to content

Commit 5cf8338

Browse files
committed
Fix issue return in computed properties & render to match only corret nodes
fixes #130
1 parent dfae686 commit 5cf8338

File tree

4 files changed

+51
-2
lines changed

4 files changed

+51
-2
lines changed

lib/rules/require-render-return.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ function create (context) {
2828
forbiddenNodes.forEach(el => {
2929
if (
3030
el.loc.start.line >= node.value.loc.start.line &&
31-
el.loc.end.line <= node.value.loc.end.line
31+
el.loc.end.line <= node.value.loc.end.line &&
32+
node.value === el
3233
) {
3334
context.report({
3435
node: node.key,

lib/rules/return-in-computed-property.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ function create (context) {
2828
if (
2929
cp.value &&
3030
el.loc.start.line >= cp.value.loc.start.line &&
31-
el.loc.end.line <= cp.value.loc.end.line
31+
el.loc.end.line <= cp.value.loc.end.line &&
32+
cp.value.parent === el
3233
) {
3334
context.report({
3435
node: el,

tests/lib/rules/require-render-return.js

+13
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,19 @@ ruleTester.run('require-render-return', rule, {
8888
}
8989
}`,
9090
parserOptions
91+
},
92+
{
93+
filename: 'test.vue',
94+
code: `export default {
95+
render(h) {
96+
const options = []
97+
this.matches.forEach(function (match) {
98+
options.push(match)
99+
})
100+
return h('div', options)
101+
}
102+
}`,
103+
parserOptions
91104
}
92105
],
93106

tests/lib/rules/return-in-computed-property.js

+34
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,40 @@ ruleTester.run('return-in-computed-property', rule, {
5151
`,
5252
parserOptions: { ecmaVersion: 8, sourceType: 'module' }
5353
},
54+
{
55+
filename: 'test.vue',
56+
code: `
57+
export default {
58+
computed: {
59+
foo () {
60+
const options = []
61+
this.matches.forEach((match) => {
62+
options.push(match)
63+
})
64+
return options
65+
}
66+
}
67+
}
68+
`,
69+
parserOptions: { ecmaVersion: 8, sourceType: 'module' }
70+
},
71+
{
72+
filename: 'test.vue',
73+
code: `
74+
export default {
75+
computed: {
76+
foo () {
77+
const options = []
78+
this.matches.forEach(function (match) {
79+
options.push(match)
80+
})
81+
return options
82+
}
83+
}
84+
}
85+
`,
86+
parserOptions: { ecmaVersion: 8, sourceType: 'module' }
87+
},
5488
{
5589
filename: 'test.vue',
5690
code: `

0 commit comments

Comments
 (0)