From f7b8341a1125c9681d1b2467017bd30b6ca84579 Mon Sep 17 00:00:00 2001 From: devTeaa Date: Thu, 8 Oct 2020 17:57:45 +0700 Subject: [PATCH 1/7] added options for custom-event-name-casing --- lib/rules/custom-event-name-casing.js | 21 +++++++++++++++-- tests/lib/rules/custom-event-name-casing.js | 26 +++++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/lib/rules/custom-event-name-casing.js b/lib/rules/custom-event-name-casing.js index 6c5f072c3..7ed9335a2 100644 --- a/lib/rules/custom-event-name-casing.js +++ b/lib/rules/custom-event-name-casing.js @@ -11,6 +11,7 @@ const { findVariable } = require('eslint-utils') const utils = require('../utils') const { isKebabCase } = require('../utils/casing') +const { toRegExp } = require('../utils/regexp') // ------------------------------------------------------------------------------ // Helpers @@ -72,7 +73,20 @@ module.exports = { url: 'https://eslint.vuejs.org/rules/custom-event-name-casing.html' }, fixable: null, - schema: [], + schema: [ + { + type: 'object', + properties: { + ignores: { + type: 'array', + items: { type: 'string' }, + uniqueItems: true, + additionalItems: false + } + }, + additionalProperties: false + } + ], messages: { unexpected: "Custom event name '{{name}}' must be kebab-case." } @@ -80,13 +94,16 @@ module.exports = { /** @param {RuleContext} context */ create(context) { const setupContexts = new Map() + const options = context.options[0] || {} + /** @type {RegExp[]} */ + const ignores = (options.ignores || []).map(toRegExp) /** * @param { Literal & { value: string } } nameLiteralNode */ function verify(nameLiteralNode) { const name = nameLiteralNode.value - if (isValidEventName(name)) { + if (ignores.some((re) => re.test(name)) || isValidEventName(name)) { return } context.report({ diff --git a/tests/lib/rules/custom-event-name-casing.js b/tests/lib/rules/custom-event-name-casing.js index 934bb079f..2942c9c72 100644 --- a/tests/lib/rules/custom-event-name-casing.js +++ b/tests/lib/rules/custom-event-name-casing.js @@ -166,6 +166,32 @@ tester.run('custom-event-name-casing', rule, { } ` + }, + { + filename: 'test.vue', + code: ` + + + `, + options: [{ ignores: ['fooBar', 'barBaz', 'bazQux'] }] } ], invalid: [ From 348cc1bb5ac3fb588aa821f7c85117a54ffb6958 Mon Sep 17 00:00:00 2001 From: devTeaa Date: Thu, 8 Oct 2020 18:43:56 +0700 Subject: [PATCH 2/7] add test case to close #1260 --- tests/lib/rules/custom-event-name-casing.js | 34 +++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/lib/rules/custom-event-name-casing.js b/tests/lib/rules/custom-event-name-casing.js index 2942c9c72..58211689b 100644 --- a/tests/lib/rules/custom-event-name-casing.js +++ b/tests/lib/rules/custom-event-name-casing.js @@ -192,6 +192,40 @@ tester.run('custom-event-name-casing', rule, { `, options: [{ ignores: ['fooBar', 'barBaz', 'bazQux'] }] + }, + { + filename: 'test.vue', + code: ` + + + `, + options: [{ ignores: ['input:update', 'search:update', 'click:row'] }] } ], invalid: [ From ff2f95d3c1423c4e6cf5fd57f8d4bb3a4cd3cf76 Mon Sep 17 00:00:00 2001 From: devTeaa Date: Thu, 8 Oct 2020 18:52:20 +0700 Subject: [PATCH 3/7] update docs for custom-event-name-casing --- docs/rules/custom-event-name-casing.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/docs/rules/custom-event-name-casing.md b/docs/rules/custom-event-name-casing.md index b4faacfbd..07d6ef323 100644 --- a/docs/rules/custom-event-name-casing.md +++ b/docs/rules/custom-event-name-casing.md @@ -49,7 +49,16 @@ export default { ## :wrench: Options -Nothing. + +```json +{ + "vue/custom-event-name-casing": ["error", { + "ignores": [] + }] +} +``` +- `ignores` (`string[]`) ... The event names to ignore. Sets the event name to allow. For example, custom event names, Vue components event with special name, or Vue library component event name. You can set the regexp by writing it like `"/^name/"` or `update:input` or `fooBar`. + ## :books: Further Reading From 625c9aa83e6815b6cd1d1d452323812423ea4e74 Mon Sep 17 00:00:00 2001 From: devTeaa Date: Fri, 9 Oct 2020 09:50:58 +0700 Subject: [PATCH 4/7] Update test case event name with regex Co-authored-by: Yosuke Ota --- tests/lib/rules/custom-event-name-casing.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/lib/rules/custom-event-name-casing.js b/tests/lib/rules/custom-event-name-casing.js index 58211689b..3e7b7c01c 100644 --- a/tests/lib/rules/custom-event-name-casing.js +++ b/tests/lib/rules/custom-event-name-casing.js @@ -225,7 +225,7 @@ tester.run('custom-event-name-casing', rule, { } `, - options: [{ ignores: ['input:update', 'search:update', 'click:row'] }] + options: [{ ignores: ['/^[a-z]+(?:-[a-z]+)*:[a-z]+(?:-[a-z]+)*$/u'] }] } ], invalid: [ From 574d218bc3970cb87ce121d521ff4b385bef13c6 Mon Sep 17 00:00:00 2001 From: devTeaa Date: Fri, 9 Oct 2020 09:52:29 +0700 Subject: [PATCH 5/7] Update docs/rules/custom-event-name-casing.md for better description Co-authored-by: Yosuke Ota --- docs/rules/custom-event-name-casing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/rules/custom-event-name-casing.md b/docs/rules/custom-event-name-casing.md index 07d6ef323..98bc5c728 100644 --- a/docs/rules/custom-event-name-casing.md +++ b/docs/rules/custom-event-name-casing.md @@ -57,7 +57,7 @@ export default { }] } ``` -- `ignores` (`string[]`) ... The event names to ignore. Sets the event name to allow. For example, custom event names, Vue components event with special name, or Vue library component event name. You can set the regexp by writing it like `"/^name/"` or `update:input` or `fooBar`. +- `ignores` (`string[]`) ... The event names to ignore. Sets the event name to allow. For example, custom event names, Vue components event with special name, or Vue library component event name. You can set the regexp by writing it like `"/^name/"` or `click:row` or `fooBar`. ## :books: Further Reading From b1042892c589473d2383fe3a9beeaa05ebbc15fd Mon Sep 17 00:00:00 2001 From: devTeaa Date: Fri, 9 Oct 2020 10:00:08 +0700 Subject: [PATCH 6/7] updated custom-event-name-casing readme with ignores options --- docs/rules/custom-event-name-casing.md | 31 ++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/docs/rules/custom-event-name-casing.md b/docs/rules/custom-event-name-casing.md index 98bc5c728..2b3dfb089 100644 --- a/docs/rules/custom-event-name-casing.md +++ b/docs/rules/custom-event-name-casing.md @@ -59,6 +59,37 @@ export default { ``` - `ignores` (`string[]`) ... The event names to ignore. Sets the event name to allow. For example, custom event names, Vue components event with special name, or Vue library component event name. You can set the regexp by writing it like `"/^name/"` or `click:row` or `fooBar`. +### `"ignores": ["fooBar", "/^[a-z]+(?:-[a-z]+)*:[a-z]+(?:-[a-z]+)*$/u"]` + + + +```vue + + +``` + + + ## :books: Further Reading From 750e23fccee1ab6180877d516863dd18f10d1c3c Mon Sep 17 00:00:00 2001 From: devTeaa Date: Fri, 9 Oct 2020 10:34:52 +0700 Subject: [PATCH 7/7] added custom-event-name-casing invalid test cases --- tests/lib/rules/custom-event-name-casing.js | 62 +++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/tests/lib/rules/custom-event-name-casing.js b/tests/lib/rules/custom-event-name-casing.js index 3e7b7c01c..ed0ba0eb5 100644 --- a/tests/lib/rules/custom-event-name-casing.js +++ b/tests/lib/rules/custom-event-name-casing.js @@ -336,6 +336,68 @@ tester.run('custom-event-name-casing', rule, { "Custom event name 'barBaz' must be kebab-case.", "Custom event name 'bazQux' must be kebab-case." ] + }, + { + filename: 'test.vue', + code: ` + + + `, + options: [{ ignores: ['/^[a-z]+(?:-[a-z]+)*:[a-z]+(?:-[a-z]+)*$/u'] }], + errors: [ + "Custom event name 'input/update' must be kebab-case.", + "Custom event name 'search/update' must be kebab-case.", + "Custom event name 'click/row' must be kebab-case." + ] + }, + { + filename: 'test.vue', + code: ` + + + `, + options: [{ ignores: ['input:update', 'search:update', 'click:row'] }], + errors: [ + "Custom event name 'input/update' must be kebab-case.", + "Custom event name 'search/update' must be kebab-case.", + "Custom event name 'click/row' must be kebab-case." + ] } ] })