Skip to content

Commit d514178

Browse files
committed
added options for custom-event-name-casing
1 parent ff78496 commit d514178

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

lib/rules/custom-event-name-casing.js

+19-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
const { findVariable } = require('eslint-utils')
1212
const utils = require('../utils')
1313
const { isKebabCase } = require('../utils/casing')
14+
const { toRegExp } = require('../utils/regexp')
1415

1516
// ------------------------------------------------------------------------------
1617
// Helpers
@@ -72,21 +73,37 @@ module.exports = {
7273
url: 'https://eslint.vuejs.org/rules/custom-event-name-casing.html'
7374
},
7475
fixable: null,
75-
schema: [],
76+
schema: [
77+
{
78+
type: 'object',
79+
properties: {
80+
ignores: {
81+
type: 'array',
82+
items: { type: 'string' },
83+
uniqueItems: true,
84+
additionalItems: false
85+
},
86+
},
87+
additionalProperties: false
88+
}
89+
],
7690
messages: {
7791
unexpected: "Custom event name '{{name}}' must be kebab-case."
7892
}
7993
},
8094
/** @param {RuleContext} context */
8195
create(context) {
8296
const setupContexts = new Map()
97+
const options = context.options[0] || {}
98+
/** @type {RegExp[]} */
99+
const ignores = (options.ignores || []).map(toRegExp)
83100

84101
/**
85102
* @param { Literal & { value: string } } nameLiteralNode
86103
*/
87104
function verify(nameLiteralNode) {
88105
const name = nameLiteralNode.value
89-
if (isValidEventName(name)) {
106+
if (ignores.some((re) => re.test(name)) || isValidEventName(name)) {
90107
return
91108
}
92109
context.report({

tests/lib/rules/custom-event-name-casing.js

+28
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,34 @@ tester.run('custom-event-name-casing', rule, {
166166
}
167167
</script>
168168
`
169+
},
170+
{
171+
filename: 'test.vue',
172+
code: `
173+
<template>
174+
<input
175+
@click="$emit('fooBar')">
176+
</template>
177+
<script>
178+
export default {
179+
setup(props, context) {
180+
return {
181+
onInput(value) {
182+
context.emit('barBaz')
183+
}
184+
}
185+
},
186+
methods: {
187+
onClick() {
188+
this.$emit('bazQux')
189+
}
190+
}
191+
}
192+
</script>
193+
`,
194+
options: [
195+
{ ignores: ['fooBar', 'barBaz', 'bazQux'] }
196+
]
169197
}
170198
],
171199
invalid: [

0 commit comments

Comments
 (0)