Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat(eslint-plugin): [no-shadow] support TS4.5 inline import specifie…
…rs (#4239)
  • Loading branch information
bradzacher committed Dec 6, 2021
1 parent 3c72e13 commit 96b7e8e
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/eslint-plugin/src/rules/no-shadow.ts
Expand Up @@ -98,7 +98,9 @@ export default util.createRule<Options, MessageIds>({
): definition is ImportBindingDefinition {
return (
definition?.type === DefinitionType.ImportBinding &&
definition.parent.importKind === 'type'
(definition.parent.importKind === 'type' ||
(definition.node.type === AST_NODE_TYPES.ImportSpecifier &&
definition.node.importKind === 'type'))
);
}

Expand Down
85 changes: 84 additions & 1 deletion packages/eslint-plugin/tests/rules/no-shadow.test.ts
Expand Up @@ -193,6 +193,15 @@ function doThing(foo: number, bar: number) {}
`,
options: [{ ignoreTypeValueShadow: true }],
},
{
code: `
import { type foo } from './foo';
// 'foo' is already declared in the upper scope
function doThing(foo: number) {}
`,
options: [{ ignoreTypeValueShadow: true }],
},
],
invalid: [
{
Expand Down Expand Up @@ -1422,7 +1431,23 @@ function foo(cb) {
{
code: `
import type { foo } from './foo';
function doThing(foo: number, bar: number) {}
function doThing(foo: number) {}
`,
options: [{ ignoreTypeValueShadow: false }],
errors: [
{
messageId: 'noShadow',
data: { name: 'foo' },
type: AST_NODE_TYPES.Identifier,
line: 3,
column: 18,
},
],
},
{
code: `
import { type foo } from './foo';
function doThing(foo: number) {}
`,
options: [{ ignoreTypeValueShadow: false }],
errors: [
Expand Down Expand Up @@ -1513,6 +1538,64 @@ declare module 'bar' {
code: `
import type { Foo } from 'bar';
declare module 'bar' {
interface Foo {
x: string;
}
}
`,
errors: [
{
messageId: 'noShadow',
data: { name: 'Foo' },
type: AST_NODE_TYPES.Identifier,
line: 5,
column: 13,
},
],
},
{
code: `
import { type Foo } from 'bar';
declare module 'baz' {
export interface Foo {
x: string;
}
}
`,
errors: [
{
messageId: 'noShadow',
data: { name: 'Foo' },
type: AST_NODE_TYPES.Identifier,
line: 5,
column: 20,
},
],
},
{
code: `
import { type Foo } from 'bar';
declare module 'bar' {
export type Foo = string;
}
`,
errors: [
{
messageId: 'noShadow',
data: { name: 'Foo' },
type: AST_NODE_TYPES.Identifier,
line: 5,
column: 15,
},
],
},
{
code: `
import { type Foo } from 'bar';
declare module 'bar' {
interface Foo {
x: string;
Expand Down

0 comments on commit 96b7e8e

Please sign in to comment.