forked from vuejs/eslint-plugin-vue
/
no-deprecated-events-api.js
57 lines (51 loc) · 1.58 KB
/
no-deprecated-events-api.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
46
47
48
49
50
51
52
53
54
55
56
57
/**
* @fileoverview disallow using deprecated events api
* @author yoyo930021
*/
'use strict'
// ------------------------------------------------------------------------------
// Requirements
// ------------------------------------------------------------------------------
const utils = require('../utils')
// ------------------------------------------------------------------------------
// Rule Definition
// ------------------------------------------------------------------------------
module.exports = {
meta: {
type: 'problem',
docs: {
description: 'disallow using deprecated events api',
categories: ['vue3-essential'],
url: 'https://eslint.vuejs.org/rules/no-deprecated-events-api.html'
},
fixable: null,
schema: [],
messages: {
noDeprecatedEventsApi: 'The Events api `$on`, `$off` `$once` is deprecated. Using external library instead, for example mitt.'
}
},
create (context) {
const forbiddenNodes = []
return Object.assign(
{
'CallExpression > MemberExpression > ThisExpression' (node) {
if (!['$on', '$off', '$once'].includes(node.parent.property.name)) return
forbiddenNodes.push(node.parent.parent)
}
},
utils.executeOnVue(context, (obj) => {
forbiddenNodes.forEach(node => {
if (
node.loc.start.line >= obj.loc.start.line &&
node.loc.end.line <= obj.loc.end.line
) {
context.report({
node,
messageId: 'noDeprecatedEventsApi'
})
}
})
})
)
}
}