Skip to content

Commit

Permalink
fix: add missing type guards
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Dec 17, 2024
1 parent efb1f03 commit 21f9595
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/rules/idMatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ export default createRule<Options, MessageIds>({
// Ignore named import
} else if (
'local' in parent &&
parent.local.type === AST_NODE_TYPES.Identifier &&
parent.local.name === node.name &&
isInvalid(name)
) {
Expand Down
11 changes: 9 additions & 2 deletions src/rules/noReExport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,20 @@ export default createRule<Options, MessageIds>({
}
} else if (node.specifiers) {
for (const specifier of node.specifiers) {
if (node.source && specifier.local.name === 'default') {
if (
node.source &&
specifier.exported.type === AST_NODE_TYPES.Identifier &&
specifier.local.type === AST_NODE_TYPES.Identifier &&
specifier.local.name === 'default'
) {
// export { default as Button } from 'app/CustomButtom';
appendToExports(specifier.exported.name, {
location: specifier.exported.loc,
type: 'DefaultReExport',
});
} else {
} else if (
specifier.local.type === AST_NODE_TYPES.Identifier
) {
// export { Button }
appendToExports(specifier.local.name, {
location: specifier.local.loc,
Expand Down
7 changes: 6 additions & 1 deletion src/rules/noReassignImports.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AST_NODE_TYPES } from '@typescript-eslint/types';
import { createRule } from '../utilities';

type Options = [];
Expand Down Expand Up @@ -77,7 +78,11 @@ export default createRule<Options, keyof typeof messages>({
},
ImportDeclaration(node) {
for (const specifier of node.specifiers) {
if (specifier.type !== 'ImportSpecifier') {
if (specifier.type !== AST_NODE_TYPES.ImportSpecifier) {
continue;
}

if (specifier.imported.type !== AST_NODE_TYPES.Identifier) {
continue;
}

Expand Down
3 changes: 2 additions & 1 deletion src/rules/noRestrictedImports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ export default createRule<Options, keyof typeof messages>({

const importSpecifiers = node.specifiers.filter(
(specifier) =>
specifier.type === 'ImportSpecifier' &&
specifier.type === AST_NODE_TYPES.ImportSpecifier &&
specifier.imported.type === AST_NODE_TYPES.Identifier &&
specifier.imported.name === importName,
);

Expand Down
4 changes: 4 additions & 0 deletions src/rules/preferReactLazy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export default createRule<Options, MessageIds>({
continue;
}

if (specifier.imported.type !== 'Identifier') {
continue;
}

imported.push(specifier.imported.name);
}
},
Expand Down
1 change: 1 addition & 0 deletions src/rules/requireExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ const handleAliasPath = (
}

if (!resolvedImportPath) {
// @ts-expect-error TODO check what's going on here
resolvedImportPath = resolveImport(importPath, context);
}

Expand Down

0 comments on commit 21f9595

Please sign in to comment.