Skip to content

Commit

Permalink
added options for custom-event-name-casing
Browse files Browse the repository at this point in the history
  • Loading branch information
devTeaa committed Oct 8, 2020
1 parent ff78496 commit d514178
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
21 changes: 19 additions & 2 deletions lib/rules/custom-event-name-casing.js
Expand Up @@ -11,6 +11,7 @@
const { findVariable } = require('eslint-utils')
const utils = require('../utils')
const { isKebabCase } = require('../utils/casing')
const { toRegExp } = require('../utils/regexp')

// ------------------------------------------------------------------------------
// Helpers
Expand Down Expand Up @@ -72,21 +73,37 @@ 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."
}
},
/** @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({
Expand Down
28 changes: 28 additions & 0 deletions tests/lib/rules/custom-event-name-casing.js
Expand Up @@ -166,6 +166,34 @@ tester.run('custom-event-name-casing', rule, {
}
</script>
`
},
{
filename: 'test.vue',
code: `
<template>
<input
@click="$emit('fooBar')">
</template>
<script>
export default {
setup(props, context) {
return {
onInput(value) {
context.emit('barBaz')
}
}
},
methods: {
onClick() {
this.$emit('bazQux')
}
}
}
</script>
`,
options: [
{ ignores: ['fooBar', 'barBaz', 'bazQux'] }
]
}
],
invalid: [
Expand Down

0 comments on commit d514178

Please sign in to comment.