Skip to content

Commit

Permalink
Import assertion checks added
Browse files Browse the repository at this point in the history
The linter checks for import assertions before suggesting fixes
  • Loading branch information
rielAsh24 committed Oct 11, 2023
1 parent fad89c7 commit 81f63d6
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions packages/eslint-plugin/src/rules/consistent-type-imports.ts
Expand Up @@ -261,17 +261,25 @@ export default util.createRule<Options, MessageIds>({
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';

Expand Down Expand Up @@ -612,7 +620,11 @@ export default util.createRule<Options, MessageIds>({

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 (
Expand Down

0 comments on commit 81f63d6

Please sign in to comment.