From bf6a876f5c24b5f5c53311d8e921eb9f2faaf3a3 Mon Sep 17 00:00:00 2001 From: TO Date: Sun, 1 Jan 2023 11:21:12 +0900 Subject: [PATCH 1/4] fix: component-name-in-template-casing rule --- .../component-name-in-template-casing.js | 3 +- lib/utils/vue2-builtin-components.js | 4 ++- .../component-name-in-template-casing.js | 32 ++----------------- 3 files changed, 7 insertions(+), 32 deletions(-) diff --git a/lib/rules/component-name-in-template-casing.js b/lib/rules/component-name-in-template-casing.js index df06a0b1c..3c07c56a4 100644 --- a/lib/rules/component-name-in-template-casing.js +++ b/lib/rules/component-name-in-template-casing.js @@ -93,7 +93,8 @@ module.exports = { if ( (!utils.isHtmlElementNode(node) && !utils.isSvgElementNode(node)) || utils.isHtmlWellKnownElementName(node.rawName) || - utils.isSvgWellKnownElementName(node.rawName) + utils.isSvgWellKnownElementName(node.rawName) || + utils.isBuiltInComponentName(node.rawName) ) { return false } diff --git a/lib/utils/vue2-builtin-components.js b/lib/utils/vue2-builtin-components.js index 54acbc9e8..a9dbe42e4 100644 --- a/lib/utils/vue2-builtin-components.js +++ b/lib/utils/vue2-builtin-components.js @@ -8,5 +8,7 @@ module.exports = [ 'transition-group', 'TransitionGroup', 'keep-alive', - 'KeepAlive' + 'KeepAlive', + 'client-only', + 'ClientOnly' ] diff --git a/tests/lib/rules/component-name-in-template-casing.js b/tests/lib/rules/component-name-in-template-casing.js index d57a5ffbf..e9beb1bc5 100644 --- a/tests/lib/rules/component-name-in-template-casing.js +++ b/tests/lib/rules/component-name-in-template-casing.js @@ -159,7 +159,8 @@ tester.run('component-name-in-template-casing', rule, { - ` + `, + options: ['PascalCase', { registeredComponentsOnly: false }] }, { @@ -811,35 +812,6 @@ tester.run('component-name-in-template-casing', rule, { 'Component name "FooBar_Baz-qux" is not kebab-case.' ] }, - { - // built-in components (behave the same way as other components) - code: ` - - `, - output: ` - - `, - options: ['PascalCase', { registeredComponentsOnly: false }], - errors: [ - 'Component name "component" is not PascalCase.', - 'Component name "suspense" is not PascalCase.', - 'Component name "teleport" is not PascalCase.', - 'Component name "client-only" is not PascalCase.', - 'Component name "keep-alive" is not PascalCase.' - ] - }, { code: ` - `, - options: ['PascalCase', { registeredComponentsOnly: false }] + ` }, { @@ -812,6 +811,35 @@ tester.run('component-name-in-template-casing', rule, { 'Component name "FooBar_Baz-qux" is not kebab-case.' ] }, + { + // built-in components (behave the same way as other components) + code: ` + + `, + output: ` + + `, + options: ['PascalCase', { registeredComponentsOnly: false }], + errors: [ + 'Component name "component" is not PascalCase.', + 'Component name "suspense" is not PascalCase.', + 'Component name "teleport" is not PascalCase.', + 'Component name "client-only" is not PascalCase.', + 'Component name "keep-alive" is not PascalCase.' + ] + }, { code: ` `, options: ['kebab-case', { globals: ['RouterView', 'router-link'] }] + }, + + // type-only imports + { + code: ` + + + + `, + options: ['PascalCase', { registeredComponentsOnly: true }], + parserOptions: { + parser: require.resolve('@typescript-eslint/parser') + } } ], invalid: [ @@ -939,6 +968,92 @@ tester.run('component-name-in-template-casing', rule, { column: 11 } ] + }, + // type-only imports + { + code: ` + + + + `, + options: ['PascalCase', { registeredComponentsOnly: false }], + parserOptions: { + parser: require.resolve('@typescript-eslint/parser') + }, + output: ` + + + + `, + errors: [ + { + message: 'Component name "foo" is not PascalCase.', + line: 13, + column: 11 + }, + { + message: 'Component name "hello-world1" is not PascalCase.', + line: 14, + column: 11 + }, + { + message: 'Component name "hello-world2" is not PascalCase.', + line: 15, + column: 11 + }, + { + message: 'Component name "hello-world3" is not PascalCase.', + line: 16, + column: 11 + }, + { + message: 'Component name "hello-world4" is not PascalCase.', + line: 17, + column: 11 + }, + { + message: 'Component name "hello-world5" is not PascalCase.', + line: 18, + column: 11 + }, + { + message: 'Component name "component" is not PascalCase.', + line: 19, + column: 11 + } + ] } ] }) From 1aac59c34a53afd25a48422239d23afffecc56f0 Mon Sep 17 00:00:00 2001 From: TO Date: Sat, 7 Jan 2023 15:00:44 +0900 Subject: [PATCH 4/4] fix: test failure in ts-eslint-v4 --- .../component-name-in-template-casing.js | 233 ++++++++++-------- 1 file changed, 124 insertions(+), 109 deletions(-) diff --git a/tests/lib/rules/component-name-in-template-casing.js b/tests/lib/rules/component-name-in-template-casing.js index ccd7792d1..7b3f012c8 100644 --- a/tests/lib/rules/component-name-in-template-casing.js +++ b/tests/lib/rules/component-name-in-template-casing.js @@ -4,6 +4,7 @@ 'use strict' const rule = require('../../../lib/rules/component-name-in-template-casing') +const semver = require('semver') const RuleTester = require('eslint').RuleTester const tester = new RuleTester({ @@ -196,33 +197,40 @@ tester.run('component-name-in-template-casing', rule, { }, // type-only imports - { - code: ` - + ...(semver.gte( + require('@typescript-eslint/parser/package.json').version, + '5.0.0' + ) + ? [ + { + code: ` + - - `, - options: ['PascalCase', { registeredComponentsOnly: true }], - parserOptions: { - parser: require.resolve('@typescript-eslint/parser') - } - } + + `, + options: ['PascalCase', { registeredComponentsOnly: true }], + parserOptions: { + parser: require.resolve('@typescript-eslint/parser') + } + } + ] + : []) ], invalid: [ { @@ -970,90 +978,97 @@ tester.run('component-name-in-template-casing', rule, { ] }, // type-only imports - { - code: ` - + ...(semver.gte( + require('@typescript-eslint/parser/package.json').version, + '5.0.0' + ) + ? [ + { + code: ` + - - `, - options: ['PascalCase', { registeredComponentsOnly: false }], - parserOptions: { - parser: require.resolve('@typescript-eslint/parser') - }, - output: ` - + + `, + options: ['PascalCase', { registeredComponentsOnly: false }], + parserOptions: { + parser: require.resolve('@typescript-eslint/parser') + }, + output: ` + - - `, - errors: [ - { - message: 'Component name "foo" is not PascalCase.', - line: 13, - column: 11 - }, - { - message: 'Component name "hello-world1" is not PascalCase.', - line: 14, - column: 11 - }, - { - message: 'Component name "hello-world2" is not PascalCase.', - line: 15, - column: 11 - }, - { - message: 'Component name "hello-world3" is not PascalCase.', - line: 16, - column: 11 - }, - { - message: 'Component name "hello-world4" is not PascalCase.', - line: 17, - column: 11 - }, - { - message: 'Component name "hello-world5" is not PascalCase.', - line: 18, - column: 11 - }, - { - message: 'Component name "component" is not PascalCase.', - line: 19, - column: 11 - } - ] - } + + `, + errors: [ + { + message: 'Component name "foo" is not PascalCase.', + line: 13, + column: 17 + }, + { + message: 'Component name "hello-world1" is not PascalCase.', + line: 14, + column: 17 + }, + { + message: 'Component name "hello-world2" is not PascalCase.', + line: 15, + column: 17 + }, + { + message: 'Component name "hello-world3" is not PascalCase.', + line: 16, + column: 17 + }, + { + message: 'Component name "hello-world4" is not PascalCase.', + line: 17, + column: 17 + }, + { + message: 'Component name "hello-world5" is not PascalCase.', + line: 18, + column: 17 + }, + { + message: 'Component name "component" is not PascalCase.', + line: 19, + column: 17 + } + ] + } + ] + : []) ] })