Skip to content

Commit

Permalink
prefer-module: Allow module as TSIndexSignature names or TSTypeAl…
Browse files Browse the repository at this point in the history
…iasDeclaration ids (#2209)

Co-authored-by: fisker Cheung <lionkay@gmail.com>
  • Loading branch information
ST-DDT and fisker committed Oct 29, 2023
1 parent 61e6601 commit ea94b3b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
10 changes: 10 additions & 0 deletions rules/ast/is-reference-identifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ function isNotReference(node) {
return parent.id === node;
}

// `type Foo = { [Identifier: string]: string }`
case 'TSIndexSignature': {
return parent.parameters.includes(node);
}

// `type Identifier = Foo`
case 'TSTypeAliasDeclaration': {
return parent.id === node;
}

case 'TSPropertySignature': {
return parent.key === node;
}
Expand Down
2 changes: 1 addition & 1 deletion rules/utils/is-shadowed.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function isShadowed(scope, node) {
const reference = findReference(scope, node);

return (
reference?.resolved
Boolean(reference?.resolved)
&& reference.resolved.defs.length > 0
);
}
Expand Down
11 changes: 11 additions & 0 deletions test/prefer-module.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,17 @@ test.snapshot({
],
});

test.typescript({
valid: [
'type module = number[];',
'type ModuleRegistry = { [module: string]: string };',
'const module = 1; type ModuleRegistry = { [module: string]: string };',
'type module = number[]; type ModuleRegistry = { [module: string]: string };',
'type ModuleRegistry = { [exports: string]: string };',
],
invalid: [],
});

// `.cjs` file
test.snapshot({
valid: [
Expand Down

0 comments on commit ea94b3b

Please sign in to comment.