-
-
Notifications
You must be signed in to change notification settings - Fork 681
/
Copy pathrequire-render-return.js
45 lines (42 loc) · 1.11 KB
/
require-render-return.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
* @fileoverview Enforces render function to always return value.
* @author Armano
*/
'use strict'
const utils = require('../utils')
module.exports = {
meta: {
type: 'problem',
docs: {
description: 'enforce render function to always return value',
categories: ['vue3-essential', 'vue2-essential'],
url: 'https://eslint.vuejs.org/rules/require-render-return.html'
},
fixable: null,
schema: [],
messages: {
expectedReturn: 'Expected to return a value in render function.'
}
},
/** @param {RuleContext} context */
create(context) {
/** @type {Map<ESNode, Property['key']>} */
const renderFunctions = new Map()
return utils.compositingVisitors(
utils.defineVueVisitor(context, {
onRenderFunctionEnter(node) {
renderFunctions.set(node, node.parent.key)
}
}),
utils.executeOnFunctionsWithoutReturn(true, (node) => {
const key = renderFunctions.get(node)
if (key) {
context.report({
node: key,
messageId: 'expectedReturn'
})
}
})
)
}
}