From 81f63d6ab06660e4b29fd2ef94e7775443805730 Mon Sep 17 00:00:00 2001 From: Ashriel Date: Wed, 4 Oct 2023 18:19:03 +0530 Subject: [PATCH] Import assertion checks added The linter checks for import assertions before suggesting fixes --- .../src/rules/consistent-type-imports.ts | 36 ++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/packages/eslint-plugin/src/rules/consistent-type-imports.ts b/packages/eslint-plugin/src/rules/consistent-type-imports.ts index 9aaa296a4b0..c23323411c6 100644 --- a/packages/eslint-plugin/src/rules/consistent-type-imports.ts +++ b/packages/eslint-plugin/src/rules/consistent-type-imports.ts @@ -261,17 +261,25 @@ export default util.createRule({ report.unusedSpecifiers.length === 0 && report.node.importKind !== 'type' ) { - context.report({ - node: report.node, - messageId: 'typeOverValue', - *fix(fixer) { - yield* fixToTypeImportDeclaration( - fixer, - report, - sourceImports, - ); - }, - }); + /** checks if import has type assertions + * ``` + * import * as type from 'mod' assert { type: 'json' }; + * ``` + * https://github.com/typescript-eslint/typescript-eslint/issues/7527 + */ + if (report.node.assertions.length === 0) { + context.report({ + node: report.node, + messageId: 'typeOverValue', + *fix(fixer) { + yield* fixToTypeImportDeclaration( + fixer, + report, + sourceImports, + ); + }, + }); + } } else { const isTypeImport = report.node.importKind === 'type'; @@ -612,7 +620,11 @@ export default util.createRule({ if (namespaceSpecifier && !defaultSpecifier) { // import * as types from 'foo' - yield* fixInsertTypeSpecifierForImportDeclaration(fixer, node, false); + + // checks for presence of import assertions + if (node.assertions.length === 0) { + yield* fixInsertTypeSpecifierForImportDeclaration(fixer, node, false); + } return; } else if (defaultSpecifier) { if (