/** * @author Yosuke Ota * issue https://github.com/vuejs/eslint-plugin-vue/issues/250 */ 'use strict' const utils = require('../utils') const casing = require('../utils/casing') const { toRegExp } = require('../utils/regexp') const allowedCaseOptions = ['PascalCase', 'kebab-case'] const defaultCase = 'PascalCase' /** * Checks whether the given variable is the type-only import object. * @param {Variable} variable * @returns {boolean} `true` if the given variable is the type-only import. */ function isTypeOnlyImport(variable) { if (variable.defs.length === 0) return false return variable.defs.every((def) => { if (def.type !== 'ImportBinding') { return false } if (def.parent.importKind === 'type') { // check for `import type Foo from './xxx'` return true } if (def.node.type === 'ImportSpecifier' && def.node.importKind === 'type') { // check for `import { type Foo } from './xxx'` return true } return false }) } module.exports = { meta: { type: 'suggestion', docs: { description: 'enforce specific casing for the component naming style in template', categories: undefined, url: 'https://eslint.vuejs.org/rules/component-name-in-template-casing.html' }, fixable: 'code', schema: [ { enum: allowedCaseOptions }, { type: 'object', properties: { globals: { type: 'array', items: { type: 'string' }, uniqueItems: true }, ignores: { type: 'array', items: { type: 'string' }, uniqueItems: true, additionalItems: false }, registeredComponentsOnly: { type: 'boolean' } }, additionalProperties: false } ], messages: { incorrectCase: 'Component name "{{name}}" is not {{caseType}}.' } }, /** @param {RuleContext} context */ create(context) { const caseOption = context.options[0] const options = context.options[1] || {} const caseType = allowedCaseOptions.includes(caseOption) ? caseOption : defaultCase /** @type {RegExp[]} */ const ignores = (options.ignores || []).map(toRegExp) /** @type {string[]} */ const globals = (options.globals || []).map(casing.pascalCase) const registeredComponentsOnly = options.registeredComponentsOnly !== false const sourceCode = context.getSourceCode() const tokens = sourceCode.parserServices.getTemplateBodyTokenStore && sourceCode.parserServices.getTemplateBodyTokenStore() /** @type { Set } */ const registeredComponents = new Set(globals) if (utils.isScriptSetup(context)) { // For