Add components
This commit is contained in:
79
slider/node_modules/eslint-plugin-vue/lib/rules/restricted-component-names.js
generated
vendored
Normal file
79
slider/node_modules/eslint-plugin-vue/lib/rules/restricted-component-names.js
generated
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* @author Wayne Zhang
|
||||
* See LICENSE file in root directory for full license.
|
||||
*/
|
||||
'use strict'
|
||||
|
||||
const utils = require('../utils')
|
||||
const { toRegExpGroupMatcher } = require('../utils/regexp')
|
||||
|
||||
const htmlElements = require('../utils/html-elements.json')
|
||||
const deprecatedHtmlElements = require('../utils/deprecated-html-elements.json')
|
||||
const svgElements = require('../utils/svg-elements.json')
|
||||
const vue2builtinComponents = require('../utils/vue2-builtin-components')
|
||||
const vue3builtinComponents = require('../utils/vue3-builtin-components')
|
||||
|
||||
const reservedNames = new Set([
|
||||
...htmlElements,
|
||||
...deprecatedHtmlElements,
|
||||
...svgElements,
|
||||
...vue2builtinComponents,
|
||||
...vue3builtinComponents
|
||||
])
|
||||
|
||||
module.exports = {
|
||||
meta: {
|
||||
type: 'problem',
|
||||
docs: {
|
||||
description: 'enforce using only specific component names',
|
||||
categories: undefined,
|
||||
url: 'https://eslint.vuejs.org/rules/restricted-component-names.html'
|
||||
},
|
||||
fixable: null,
|
||||
schema: [
|
||||
{
|
||||
type: 'object',
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
allow: {
|
||||
type: 'array',
|
||||
items: { type: 'string' },
|
||||
uniqueItems: true,
|
||||
additionalItems: false
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
messages: {
|
||||
invalidName: 'Component name "{{name}}" is not allowed.'
|
||||
}
|
||||
},
|
||||
/** @param {RuleContext} context */
|
||||
create(context) {
|
||||
const options = context.options[0] || {}
|
||||
const isAllowed = toRegExpGroupMatcher(options.allow)
|
||||
|
||||
/** @param {string} name */
|
||||
function isAllowedTarget(name) {
|
||||
return reservedNames.has(name) || isAllowed(name)
|
||||
}
|
||||
|
||||
return utils.defineTemplateBodyVisitor(context, {
|
||||
VElement(node) {
|
||||
const name = node.rawName
|
||||
if (isAllowedTarget(name)) {
|
||||
return
|
||||
}
|
||||
|
||||
context.report({
|
||||
node,
|
||||
loc: node.loc,
|
||||
messageId: 'invalidName',
|
||||
data: {
|
||||
name
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user