vue hello world项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.8 KiB

3 years ago
/**
* @fileoverview disallow using deprecated number (keycode) modifiers
* @author yoyo930021
*/
'use strict'
// ------------------------------------------------------------------------------
// Requirements
// ------------------------------------------------------------------------------
const utils = require('../utils')
const keyCodeToKey = require('../utils/keycode-to-key')
// ------------------------------------------------------------------------------
// Rule Definition
// ------------------------------------------------------------------------------
module.exports = {
meta: {
type: 'problem',
docs: {
description:
'disallow using deprecated number (keycode) modifiers (in Vue.js 3.0.0+)',
categories: ['vue3-essential'],
url: 'https://eslint.vuejs.org/rules/no-deprecated-v-on-number-modifiers.html'
},
fixable: 'code',
schema: [],
messages: {
numberModifierIsDeprecated:
"'KeyboardEvent.keyCode' modifier on 'v-on' directive is deprecated. Using 'KeyboardEvent.key' instead."
}
},
/** @param {RuleContext} context */
create(context) {
return utils.defineTemplateBodyVisitor(context, {
/** @param {VDirectiveKey} node */
"VAttribute[directive=true][key.name.name='on'] > VDirectiveKey"(node) {
const modifier = node.modifiers.find((mod) =>
Number.isInteger(parseInt(mod.name, 10))
)
if (!modifier) return
const keyCodes = parseInt(modifier.name, 10)
if (keyCodes > 9 || keyCodes < 0) {
context.report({
node: modifier,
messageId: 'numberModifierIsDeprecated',
fix(fixer) {
const key = keyCodeToKey[keyCodes]
if (!key) return null
return fixer.replaceText(modifier, `${key}`)
}
})
}
}
})
}
}