diff --git a/lib/rules/custom-event-name-casing.js b/lib/rules/custom-event-name-casing.js index 6c5f072c3..1fdb2b34a 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..c1c929190 100644 --- a/tests/lib/rules/custom-event-name-casing.js +++ b/tests/lib/rules/custom-event-name-casing.js @@ -166,6 +166,34 @@ tester.run('custom-event-name-casing', rule, { } ` + }, + { + filename: 'test.vue', + code: ` + + + `, + options: [ + { ignores: ['fooBar', 'barBaz', 'bazQux'] } + ] } ], invalid: [