From 92f550aa33364f420e939f59212b6027d4a869a6 Mon Sep 17 00:00:00 2001 From: Moulik Aggarwal Date: Sun, 18 Oct 2020 00:15:04 +0530 Subject: [PATCH 1/6] fix(eslint-plugin-vue): [valid-v-bind-sync] If Valid Is then .sync is Valid Signed-off-by: Moulik Aggarwal --- lib/rules/valid-v-bind-sync.js | 13 ++++++++++++- tests/lib/rules/valid-v-bind-sync.js | 14 ++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/rules/valid-v-bind-sync.js b/lib/rules/valid-v-bind-sync.js index 48452f822..cf5b9fc2c 100644 --- a/lib/rules/valid-v-bind-sync.js +++ b/lib/rules/valid-v-bind-sync.js @@ -82,6 +82,17 @@ function maybeNullObjectMemberExpression(node) { return false } +function isValidIs(node){ + let { attributes } = node + let isAttribute = attributes.filter((attr) => { + if(attr.type === "VAttribute" && attr.key.name === "is") return attr + }) + if(isAttribute.length > 0 && ['tr', 'li', 'option'].includes(node.parent.name)){ + return true + } + return false +} + // ------------------------------------------------------------------------------ // Rule Definition // ------------------------------------------------------------------------------ @@ -120,7 +131,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..930b66081 100644 --- a/tests/lib/rules/valid-v-bind-sync.js +++ b/tests/lib/rules/valid-v-bind-sync.js @@ -145,6 +145,20 @@ tester.run('valid-v-bind-sync', rule, { { filename: 'empty-value.vue', code: '' + }, + { + filename: 'test.vue', + code: ` + + ` } ], invalid: [ From e618757e9e63c5e50fbad1540e932411daa408ca Mon Sep 17 00:00:00 2001 From: Moulik Aggarwal Date: Sun, 18 Oct 2020 00:30:04 +0530 Subject: [PATCH 2/6] Formatted Document Signed-off-by: Moulik Aggarwal --- lib/rules/valid-v-bind-sync.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/rules/valid-v-bind-sync.js b/lib/rules/valid-v-bind-sync.js index cf5b9fc2c..3d2786521 100644 --- a/lib/rules/valid-v-bind-sync.js +++ b/lib/rules/valid-v-bind-sync.js @@ -82,12 +82,15 @@ function maybeNullObjectMemberExpression(node) { return false } -function isValidIs(node){ - let { attributes } = node - let isAttribute = attributes.filter((attr) => { - if(attr.type === "VAttribute" && attr.key.name === "is") return attr +function isValidIs(node) { + const { attributes } = node + const isAttribute = attributes.filter((attr) => { + if (attr.type === 'VAttribute' && attr.key.name === 'is') return attr }) - if(isAttribute.length > 0 && ['tr', 'li', 'option'].includes(node.parent.name)){ + if ( + isAttribute.length > 0 && + ['tr', 'li', 'option'].includes(node.parent.name) + ) { return true } return false From 9eb250c7072d68170539df361686a26602734214 Mon Sep 17 00:00:00 2001 From: Moulik Aggarwal Date: Mon, 19 Oct 2020 14:26:33 +0530 Subject: [PATCH 3/6] fix: [v-bind-sync] added check for :is bind attribute Signed-off-by: Moulik Aggarwal --- lib/rules/valid-v-bind-sync.js | 20 +++++++++++--------- package.json | 3 ++- tests/lib/rules/valid-v-bind-sync.js | 14 ++++++++++++++ 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/lib/rules/valid-v-bind-sync.js b/lib/rules/valid-v-bind-sync.js index 3d2786521..d6ab658e2 100644 --- a/lib/rules/valid-v-bind-sync.js +++ b/lib/rules/valid-v-bind-sync.js @@ -84,16 +84,18 @@ function maybeNullObjectMemberExpression(node) { function isValidIs(node) { const { attributes } = node - const isAttribute = attributes.filter((attr) => { - if (attr.type === 'VAttribute' && attr.key.name === 'is') return attr + 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 + } }) - if ( - isAttribute.length > 0 && - ['tr', 'li', 'option'].includes(node.parent.name) - ) { - return true - } - return false + return isAttribute } // ------------------------------------------------------------------------------ diff --git a/package.json b/package.json index ef4847dbf..cec179ddf 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,8 @@ "version": "npm run lint -- --fix && git add .", "update": "node ./tools/update.js", "docs:watch": "vuepress dev docs", - "docs:build": "vuepress build docs" + "docs:build": "vuepress build docs", + "tests": "mocha" }, "files": [ "lib" diff --git a/tests/lib/rules/valid-v-bind-sync.js b/tests/lib/rules/valid-v-bind-sync.js index 930b66081..b2cc70128 100644 --- a/tests/lib/rules/valid-v-bind-sync.js +++ b/tests/lib/rules/valid-v-bind-sync.js @@ -159,6 +159,20 @@ tester.run('valid-v-bind-sync', rule, { ` + }, + { + filename: 'test.vue', + code: ` + + ` } ], invalid: [ From 25e5139ec04a92594680a11e075dabcb566d8591 Mon Sep 17 00:00:00 2001 From: Moulik Aggarwal Date: Mon, 19 Oct 2020 14:29:03 +0530 Subject: [PATCH 4/6] fix: [valid-v-bind-sync] add unit tests for `v-bind:is` Signed-off-by: Moulik Aggarwal --- tests/lib/rules/valid-v-bind-sync.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/lib/rules/valid-v-bind-sync.js b/tests/lib/rules/valid-v-bind-sync.js index b2cc70128..5500f53ac 100644 --- a/tests/lib/rules/valid-v-bind-sync.js +++ b/tests/lib/rules/valid-v-bind-sync.js @@ -173,6 +173,20 @@ tester.run('valid-v-bind-sync', rule, { ` + }, + { + filename: 'test.vue', + code: ` + + ` } ], invalid: [ From fab27611cad6a6306752ee96e3d02c2dfc90ec8b Mon Sep 17 00:00:00 2001 From: Yosuke Ota Date: Fri, 4 Dec 2020 12:57:23 +0900 Subject: [PATCH 5/6] Update tests/lib/rules/valid-v-bind-sync.js --- tests/lib/rules/valid-v-bind-sync.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/lib/rules/valid-v-bind-sync.js b/tests/lib/rules/valid-v-bind-sync.js index 5500f53ac..6ff2c462d 100644 --- a/tests/lib/rules/valid-v-bind-sync.js +++ b/tests/lib/rules/valid-v-bind-sync.js @@ -179,7 +179,7 @@ tester.run('valid-v-bind-sync', rule, { code: `