From af5c4c0afa9aea5461bc48e9a8984edb91a5cd38 Mon Sep 17 00:00:00 2001 From: Moulik Aggarwal Date: Fri, 4 Dec 2020 09:35:04 +0530 Subject: [PATCH] fix(eslint-plugin-vue): [valid-v-bind-sync] Added Case: when valid is then valid .sync (#1335) * fix(eslint-plugin-vue): [valid-v-bind-sync] If Valid Is then .sync is Valid Signed-off-by: Moulik Aggarwal * Formatted Document Signed-off-by: Moulik Aggarwal * fix: [v-bind-sync] added check for :is bind attribute Signed-off-by: Moulik Aggarwal * fix: [valid-v-bind-sync] add unit tests for `v-bind:is` Signed-off-by: Moulik Aggarwal * Update tests/lib/rules/valid-v-bind-sync.js * Update package.json Co-authored-by: Yosuke Ota --- lib/rules/valid-v-bind-sync.js | 18 +++++++++++- tests/lib/rules/valid-v-bind-sync.js | 42 ++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/lib/rules/valid-v-bind-sync.js b/lib/rules/valid-v-bind-sync.js index 48452f822..d6ab658e2 100644 --- a/lib/rules/valid-v-bind-sync.js +++ b/lib/rules/valid-v-bind-sync.js @@ -82,6 +82,22 @@ function maybeNullObjectMemberExpression(node) { return false } +function isValidIs(node) { + const { attributes } = node + const isAttribute = attributes.some((attr) => { + // check for `VAttribute` + if (attr.type === 'VAttribute') { + // check for `is` attribute + if (attr.key.type === 'VIdentifier' && attr.key.name === 'is') return true + + // check for `:is` `bind` attribute + if (attr.key.type === 'VDirectiveKey' && attr.key.argument.name === 'is') + return true + } + }) + return isAttribute +} + // ------------------------------------------------------------------------------ // Rule Definition // ------------------------------------------------------------------------------ @@ -120,7 +136,7 @@ module.exports = { const element = node.parent.parent const name = element.name - if (!isValidElement(element)) { + if (!isValidElement(element) && !isValidIs(node.parent)) { context.report({ node, loc: node.loc, diff --git a/tests/lib/rules/valid-v-bind-sync.js b/tests/lib/rules/valid-v-bind-sync.js index dfaf161ea..6ff2c462d 100644 --- a/tests/lib/rules/valid-v-bind-sync.js +++ b/tests/lib/rules/valid-v-bind-sync.js @@ -145,6 +145,48 @@ tester.run('valid-v-bind-sync', rule, { { filename: 'empty-value.vue', code: '' + }, + { + filename: 'test.vue', + code: ` + + ` + }, + { + filename: 'test.vue', + code: ` + + ` + }, + { + filename: 'test.vue', + code: ` + + ` } ], invalid: [