forked from vuejs/eslint-plugin-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathno-arrow-functions-in-watch.js
39 lines (37 loc) · 1016 Bytes
/
no-arrow-functions-in-watch.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
/**
* @author Sosuke Suzuki
*/
'use strict'
const utils = require('../utils')
module.exports = {
meta: {
type: 'problem',
docs: {
description: 'disallow using arrow functions to define watcher',
categories: undefined,
url: 'https://eslint.vuejs.org/rules/no-arrow-functions-in-watch.html'
},
fixable: null,
schema: []
},
create (context) {
return utils.executeOnVue(context, (obj) => {
const watchNode = obj.properties.find((property) => utils.getStaticPropertyName(property) === 'watch')
if (watchNode == null) {
return
}
const watchValue = watchNode.value
if (watchValue.type !== 'ObjectExpression') {
return
}
for (const property of watchValue.properties) {
if (property.value.type === 'ArrowFunctionExpression') {
context.report({
node: property,
message: 'You should not use an arrow function to define a watcher.'
})
}
}
})
}
}