Skip to content

Commit

Permalink
Fix tsc error (#1480)
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi committed Apr 21, 2021
1 parent 01d1e45 commit 7e5f2e9
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions lib/rules/no-invalid-model-keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ const utils = require('../utils')
// ------------------------------------------------------------------------------
// Rule Definition
// ------------------------------------------------------------------------------
/** @type {GroupName[]} */
const GROUP_NAMES = ['model']

const VALID_MODEL_KEYS = ['prop', 'event']

module.exports = {
Expand All @@ -31,22 +28,30 @@ module.exports = {
},
/** @param {RuleContext} context */
create(context) {
const groups = new Set(GROUP_NAMES)

// ----------------------------------------------------------------------
// Public
// ----------------------------------------------------------------------

return utils.executeOnVue(context, (obj) => {
const properties = utils.iterateProperties(obj, groups)
const modelProperty = utils.findProperty(obj, 'model')
if (!modelProperty || modelProperty.value.type !== 'ObjectExpression') {
return
}

for (const o of properties) {
if (VALID_MODEL_KEYS.indexOf(o.name) === -1) {
for (const p of modelProperty.value.properties) {
if (p.type !== 'Property') {
continue
}
const name = utils.getStaticPropertyName(p)
if (!name) {
continue
}
if (VALID_MODEL_KEYS.indexOf(name) === -1) {
context.report({
node: o.node,
node: p,
message: "Invalid key '{{name}}' in model option.",
data: {
name: o.name
name
}
})
}
Expand Down

0 comments on commit 7e5f2e9

Please sign in to comment.