This repository has been archived on 2020-11-02. You can view files and clone it, but cannot push or open issues or pull requests.
TripSit_Suite/node_modules/eslint-plugin-vue/lib/rules/no-arrow-functions-in-watch.js
2020-11-01 22:46:04 +00:00

44 lines
1.1 KiB
JavaScript

/**
* @author Sosuke Suzuki
*/
'use strict'
const utils = require('../utils')
module.exports = {
meta: {
type: 'problem',
docs: {
description: 'disallow using arrow functions to define watcher',
categories: ['vue3-essential', 'essential'],
url: 'https://eslint.vuejs.org/rules/no-arrow-functions-in-watch.html'
},
fixable: null,
schema: []
},
/** @param {RuleContext} context */
create(context) {
return utils.executeOnVue(context, (obj) => {
const watchNode = utils.findProperty(obj, 'watch')
if (watchNode == null) {
return
}
const watchValue = watchNode.value
if (watchValue.type !== 'ObjectExpression') {
return
}
for (const property of watchValue.properties) {
if (
property.type === 'Property' &&
property.value.type === 'ArrowFunctionExpression'
) {
context.report({
node: property,
message: 'You should not use an arrow function to define a watcher.'
})
}
}
})
}
}