From 63dc10305212361b8d9660dc7bfdcc67466cde88 Mon Sep 17 00:00:00 2001 From: Toru Nagashima Date: Sun, 25 Jun 2017 03:44:40 +0900 Subject: [PATCH 1/2] Fix: allow `v-on` without attribute values if it has verb modifiers (fixes #49) --- docs/rules/no-invalid-v-on.md | 6 ++++-- lib/rules/no-invalid-v-on.js | 7 +++++-- tests/lib/rules/no-invalid-v-on.js | 6 +++++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/docs/rules/no-invalid-v-on.md b/docs/rules/no-invalid-v-on.md index 38da1e6e6..640b111ee 100644 --- a/docs/rules/no-invalid-v-on.md +++ b/docs/rules/no-invalid-v-on.md @@ -8,7 +8,7 @@ This rule reports `v-on` directives if the following cases: - The directive does not have that event name. E.g. `
` - The directive has invalid modifiers. E.g. `
` -- The directive does not have that attribute value. E.g. `
` +- The directive does not have that attribute value and any verb modifiers. E.g. `
` This rule does not check syntax errors in directives because it's checked by [no-parsing-error] rule. @@ -31,7 +31,9 @@ This rule does not check syntax errors in directives because it's checked by [no
-
+
+
+
``` diff --git a/lib/rules/no-invalid-v-on.js b/lib/rules/no-invalid-v-on.js index 54ddc7b2c..ad397677c 100644 --- a/lib/rules/no-invalid-v-on.js +++ b/lib/rules/no-invalid-v-on.js @@ -20,6 +20,9 @@ const VALID_MODIFIERS = new Set([ 'native', 'once', 'left', 'right', 'middle', 'passive', 'esc', 'tab', 'enter', 'space', 'up', 'left', 'right', 'down', 'delete' ]) +const VERB_MODIFIERS = new Set([ + 'stop', 'prevent' +]) /** * Creates AST event handlers for no-invalid-v-on. @@ -47,11 +50,11 @@ function create (context) { }) } } - if (!utils.hasAttributeValue(node)) { + if (!utils.hasAttributeValue(node) && !node.key.modifiers.some(VERB_MODIFIERS.has, VERB_MODIFIERS)) { context.report({ node, loc: node.loc, - message: "'v-on' directives require that attribute value." + message: "'v-on' directives require that attribute value or verb modifiers." }) } } diff --git a/tests/lib/rules/no-invalid-v-on.js b/tests/lib/rules/no-invalid-v-on.js index 24cc67eec..de2a6873b 100644 --- a/tests/lib/rules/no-invalid-v-on.js +++ b/tests/lib/rules/no-invalid-v-on.js @@ -42,6 +42,10 @@ tester.run('no-invalid-v-on', rule, { { filename: 'test.vue', code: '' + }, + { + filename: 'test.vue', + code: '' } ], invalid: [ @@ -58,7 +62,7 @@ tester.run('no-invalid-v-on', rule, { { filename: 'test.vue', code: '', - errors: ["'v-on' directives require that attribute value."] + errors: ["'v-on' directives require that attribute value or verb modifiers."] } ] }) From d18327e2273c89fd3252b8fc7d7ae595fb11839d Mon Sep 17 00:00:00 2001 From: Toru Nagashima Date: Tue, 27 Jun 2017 19:56:59 +0900 Subject: [PATCH 2/2] Chore: add more tests --- tests/lib/rules/no-invalid-v-on.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/lib/rules/no-invalid-v-on.js b/tests/lib/rules/no-invalid-v-on.js index de2a6873b..820a9509e 100644 --- a/tests/lib/rules/no-invalid-v-on.js +++ b/tests/lib/rules/no-invalid-v-on.js @@ -46,6 +46,14 @@ tester.run('no-invalid-v-on', rule, { { filename: 'test.vue', code: '' + }, + { + filename: 'test.vue', + code: '' + }, + { + filename: 'test.vue', + code: '' } ], invalid: [ @@ -63,6 +71,11 @@ tester.run('no-invalid-v-on', rule, { filename: 'test.vue', code: '', errors: ["'v-on' directives require that attribute value or verb modifiers."] + }, + { + filename: 'test.vue', + code: '', + errors: ["'v-on' directives require that attribute value or verb modifiers."] } ] })