From a999b34a4611297a4a70a144cd47fe86b991fa33 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Tue, 24 Oct 2023 11:17:31 +0800 Subject: [PATCH 1/3] fix(component-name-in-template-casing): ignore vue template syntax --- lib/rules/component-name-in-template-casing.js | 3 ++- lib/utils/index.js | 10 ++++++++++ lib/utils/vue-template-syntax.js | 1 + tests/lib/rules/component-name-in-template-casing.js | 8 ++++++++ 4 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 lib/utils/vue-template-syntax.js diff --git a/lib/rules/component-name-in-template-casing.js b/lib/rules/component-name-in-template-casing.js index fc1849b18..11a936dcb 100644 --- a/lib/rules/component-name-in-template-casing.js +++ b/lib/rules/component-name-in-template-casing.js @@ -123,7 +123,8 @@ module.exports = { if ( (!utils.isHtmlElementNode(node) && !utils.isSvgElementNode(node)) || utils.isHtmlWellKnownElementName(node.rawName) || - utils.isSvgWellKnownElementName(node.rawName) + utils.isSvgWellKnownElementName(node.rawName) || + utils.isVueTemplateSyntaxName(node.rawName) ) { return false } diff --git a/lib/utils/index.js b/lib/utils/index.js index 8702c6260..75afc7956 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -54,6 +54,7 @@ const VUE2_BUILTIN_COMPONENT_NAMES = new Set( const VUE3_BUILTIN_COMPONENT_NAMES = new Set( require('./vue3-builtin-components') ) +const VUE_TEMPLATE_SYNTAX_NAMES = new Set(require('./vue-template-syntax')) const path = require('path') const vueEslintParser = require('vue-eslint-parser') const { traverseNodes, getFallbackKeys, NS } = vueEslintParser.AST @@ -867,6 +868,15 @@ module.exports = { ) }, + /** + * Check whether the given name is Vue builtin template syntax name or not. + * @param {string} name The name to check. + * @returns {boolean} `true` if the name is a builtin Vue template syntax name + */ + isVueTemplateSyntaxName(name) { + return VUE_TEMPLATE_SYNTAX_NAMES.has(name.toLowerCase()) + }, + /** * Check whether the given name is Vue builtin directive name or not. * @param {string} name The name to check. diff --git a/lib/utils/vue-template-syntax.js b/lib/utils/vue-template-syntax.js new file mode 100644 index 000000000..70ddb6b7d --- /dev/null +++ b/lib/utils/vue-template-syntax.js @@ -0,0 +1 @@ +module.exports = ['template', 'slot', 'component'] diff --git a/tests/lib/rules/component-name-in-template-casing.js b/tests/lib/rules/component-name-in-template-casing.js index 3aa4ee43d..676839534 100644 --- a/tests/lib/rules/component-name-in-template-casing.js +++ b/tests/lib/rules/component-name-in-template-casing.js @@ -86,6 +86,10 @@ tester.run('component-name-in-template-casing', rule, { code: '', options: ['PascalCase', { registeredComponentsOnly: false }] }, + { + code: '', + options: ['PascalCase', { registeredComponentsOnly: false }] + }, // kebab-case { @@ -108,6 +112,10 @@ tester.run('component-name-in-template-casing', rule, { code: '', options: ['kebab-case', { registeredComponentsOnly: false }] }, + { + code: '', + options: ['kebab-case', { registeredComponentsOnly: false }] + }, // ignores { From b3c724a2bf6ac31a1cade01c61c41e064869eaea Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Tue, 24 Oct 2023 11:35:05 +0800 Subject: [PATCH 2/3] chore: rename --- lib/rules/component-name-in-template-casing.js | 2 +- lib/utils/index.js | 10 +++++----- ...{vue-template-syntax.js => vue-builtin-elements.js} | 0 3 files changed, 6 insertions(+), 6 deletions(-) rename lib/utils/{vue-template-syntax.js => vue-builtin-elements.js} (100%) diff --git a/lib/rules/component-name-in-template-casing.js b/lib/rules/component-name-in-template-casing.js index 11a936dcb..487af7714 100644 --- a/lib/rules/component-name-in-template-casing.js +++ b/lib/rules/component-name-in-template-casing.js @@ -124,7 +124,7 @@ module.exports = { (!utils.isHtmlElementNode(node) && !utils.isSvgElementNode(node)) || utils.isHtmlWellKnownElementName(node.rawName) || utils.isSvgWellKnownElementName(node.rawName) || - utils.isVueTemplateSyntaxName(node.rawName) + utils.isVueBuiltInElementName(node.rawName) ) { return false } diff --git a/lib/utils/index.js b/lib/utils/index.js index 75afc7956..22119ae98 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -54,7 +54,7 @@ const VUE2_BUILTIN_COMPONENT_NAMES = new Set( const VUE3_BUILTIN_COMPONENT_NAMES = new Set( require('./vue3-builtin-components') ) -const VUE_TEMPLATE_SYNTAX_NAMES = new Set(require('./vue-template-syntax')) +const VUE_BUILTIN_ELEMENT_NAMES = new Set(require('./vue-builtin-elements')) const path = require('path') const vueEslintParser = require('vue-eslint-parser') const { traverseNodes, getFallbackKeys, NS } = vueEslintParser.AST @@ -869,12 +869,12 @@ module.exports = { }, /** - * Check whether the given name is Vue builtin template syntax name or not. + * Check whether the given name is Vue builtin element name or not. * @param {string} name The name to check. - * @returns {boolean} `true` if the name is a builtin Vue template syntax name + * @returns {boolean} `true` if the name is a builtin Vue element name */ - isVueTemplateSyntaxName(name) { - return VUE_TEMPLATE_SYNTAX_NAMES.has(name.toLowerCase()) + isVueBuiltInElementName(name) { + return VUE_BUILTIN_ELEMENT_NAMES.has(name.toLowerCase()) }, /** diff --git a/lib/utils/vue-template-syntax.js b/lib/utils/vue-builtin-elements.js similarity index 100% rename from lib/utils/vue-template-syntax.js rename to lib/utils/vue-builtin-elements.js From 53d3ba076432e302abd62776c40979d55bb60106 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Tue, 24 Oct 2023 11:45:54 +0800 Subject: [PATCH 3/3] chore: test --- tests/lib/rules/component-name-in-template-casing.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/tests/lib/rules/component-name-in-template-casing.js b/tests/lib/rules/component-name-in-template-casing.js index 676839534..992063808 100644 --- a/tests/lib/rules/component-name-in-template-casing.js +++ b/tests/lib/rules/component-name-in-template-casing.js @@ -867,7 +867,7 @@ tester.run('component-name-in-template-casing', rule, { `, output: ` `, errors: [ @@ -1066,11 +1065,6 @@ tester.run('component-name-in-template-casing', rule, { message: 'Component name "hello-world5" is not PascalCase.', line: 18, column: 17 - }, - { - message: 'Component name "component" is not PascalCase.', - line: 19, - column: 17 } ] }