From 9cfba4b04372aefeb6b45965cf93b13fc6c0f235 Mon Sep 17 00:00:00 2001 From: qmhc <40221744+qmhc@users.noreply.github.com> Date: Mon, 31 Oct 2022 19:20:51 +0800 Subject: [PATCH 1/4] fix: ensure `no-textarea-mustache` difference `' + }, + { + filename: 'test.vue', + code: '' } ], invalid: [ @@ -30,6 +34,11 @@ tester.run('no-textarea-mustache', rule, { code: '', errors: ["Unexpected mustache. Use 'v-model' instead."] }, + { + filename: 'test.vue', + code: '', + errors: ["Unexpected mustache. Use 'v-model' instead."] + }, { filename: 'test.vue', code: '', From 6bf098f692d375d42d8a587870797f611a20b5dd Mon Sep 17 00:00:00 2001 From: qmhc <40221744+qmhc@users.noreply.github.com> Date: Mon, 31 Oct 2022 19:24:20 +0800 Subject: [PATCH 2/4] chore: lift sourceCode --- lib/rules/no-textarea-mustache.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/rules/no-textarea-mustache.js b/lib/rules/no-textarea-mustache.js index cfed2aa3e..335af11c4 100644 --- a/lib/rules/no-textarea-mustache.js +++ b/lib/rules/no-textarea-mustache.js @@ -20,6 +20,8 @@ module.exports = { }, /** @param {RuleContext} context */ create(context) { + const sourceCode = context.getSourceCode() + return utils.defineTemplateBodyVisitor(context, { /** @param {VExpressionContainer} node */ "VElement[name='textarea'] VExpressionContainer"(node) { @@ -27,7 +29,6 @@ module.exports = { return } - const sourceCode = context.getSourceCode() const parentStartTag = sourceCode.getText(node.parent.startTag) if (parentStartTag.startsWith(' Date: Mon, 31 Oct 2022 20:58:08 +0800 Subject: [PATCH 3/4] chore: using node.parent.rawName instead --- lib/rules/no-textarea-mustache.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/lib/rules/no-textarea-mustache.js b/lib/rules/no-textarea-mustache.js index 335af11c4..d81b7b148 100644 --- a/lib/rules/no-textarea-mustache.js +++ b/lib/rules/no-textarea-mustache.js @@ -20,18 +20,13 @@ module.exports = { }, /** @param {RuleContext} context */ create(context) { - const sourceCode = context.getSourceCode() - return utils.defineTemplateBodyVisitor(context, { /** @param {VExpressionContainer} node */ "VElement[name='textarea'] VExpressionContainer"(node) { - if (node.parent.type !== 'VElement') { - return - } - - const parentStartTag = sourceCode.getText(node.parent.startTag) - - if (parentStartTag.startsWith(' Date: Mon, 31 Oct 2022 22:03:23 +0800 Subject: [PATCH 4/4] chore: switch to use selector to distinguish --- lib/rules/no-textarea-mustache.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/rules/no-textarea-mustache.js b/lib/rules/no-textarea-mustache.js index d81b7b148..29c8a4da2 100644 --- a/lib/rules/no-textarea-mustache.js +++ b/lib/rules/no-textarea-mustache.js @@ -22,11 +22,8 @@ module.exports = { create(context) { return utils.defineTemplateBodyVisitor(context, { /** @param {VExpressionContainer} node */ - "VElement[name='textarea'] VExpressionContainer"(node) { - if ( - node.parent.type !== 'VElement' || - node.parent.rawName.startsWith('T') - ) { + "VElement[rawName='textarea'] VExpressionContainer"(node) { + if (node.parent.type !== 'VElement') { return }