From 6173b91c64a973d167ba168b0e740e8b2b843ddb Mon Sep 17 00:00:00 2001 From: Amorites <751809522@qq.com> Date: Wed, 14 Sep 2022 02:58:27 +0800 Subject: [PATCH] Report type-only imports in `no-undef-components` (#1967) Co-authored-by: lihongda03 --- lib/rules/no-undef-components.js | 13 +++- tests/lib/rules/no-undef-components.js | 60 +++++++++++++++++++ tsconfig.json | 2 +- .../util-types/ast/es-ast.ts | 1 + typings/eslint/index.d.ts | 3 + 5 files changed, 75 insertions(+), 4 deletions(-) diff --git a/lib/rules/no-undef-components.js b/lib/rules/no-undef-components.js index f6e66400c..dc58fd2e9 100644 --- a/lib/rules/no-undef-components.js +++ b/lib/rules/no-undef-components.js @@ -50,7 +50,9 @@ module.exports = { } ], messages: { - undef: "The '<{{name}}>' component has been used, but not defined." + undef: "The '<{{name}}>' component has been used, but not defined.", + typeOnly: + "The '<{{name}}>' component has been used, but '{{name}}' only refers to a type." } }, /** @param {RuleContext} context */ @@ -121,6 +123,7 @@ module.exports = { // For + + + `, + parserOptions: { + ecmaVersion: 6, + sourceType: 'module', + parser: require.resolve('@typescript-eslint/parser') + }, + parser: require.resolve('vue-eslint-parser'), + errors: [ + { + message: + "The '' component has been used, but 'Foo' only refers to a type.", + line: 12 + }, + { + message: + "The '' component has been used, but 'HelloWorld1' only refers to a type.", + line: 13 + }, + { + message: + "The '' component has been used, but 'HelloWorld2' only refers to a type.", + line: 14 + }, + { + message: + "The '' component has been used, but 'HelloWorld3' only refers to a type.", + line: 15 + }, + { + message: + "The '' component has been used, but 'HelloWorld4' only refers to a type.", + line: 16 + }, + { + message: + "The '' component has been used, but 'HelloWorld5' only refers to a type.", + line: 17 + } + ] + }, // options API { diff --git a/tsconfig.json b/tsconfig.json index 40f2ceeee..cbaefbd88 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "target": "ES2020", + "target": "ES2019", "module": "commonjs", "lib": ["es2020"], "allowJs": true, diff --git a/typings/eslint-plugin-vue/util-types/ast/es-ast.ts b/typings/eslint-plugin-vue/util-types/ast/es-ast.ts index 16a734d2e..f4dd208c3 100644 --- a/typings/eslint-plugin-vue/util-types/ast/es-ast.ts +++ b/typings/eslint-plugin-vue/util-types/ast/es-ast.ts @@ -268,6 +268,7 @@ export interface ImportDeclaration extends HasParentNode { | ImportNamespaceSpecifier )[] source: Literal & { value: string } + importKind?: 'type' | 'value' } export interface ImportSpecifier extends HasParentNode { type: 'ImportSpecifier' diff --git a/typings/eslint/index.d.ts b/typings/eslint/index.d.ts index 7bfda0245..949d56f6d 100644 --- a/typings/eslint/index.d.ts +++ b/typings/eslint/index.d.ts @@ -54,6 +54,9 @@ export namespace Scope { eslintExplicitGlobal?: boolean | undefined eslintExplicitGlobalComments?: Comment[] | undefined eslintImplicitGlobalSetting?: 'readonly' | 'writable' | undefined + + isTypeVariable?: boolean + isValueVariable?: boolean } interface Reference { identifier: VAST.Identifier