Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(eslint-plugin): [no-shadow] support TS4.5 inline import specifiers #4239

Merged
merged 2 commits into from Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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