Skip to content

Commit

Permalink
fix(eslint-plugin): [no-shadow] ignore type-only imports properly
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelss95 committed Sep 12, 2021
1 parent 4a88de2 commit c235bc4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
10 changes: 6 additions & 4 deletions packages/eslint-plugin/src/rules/no-shadow.ts
@@ -1,9 +1,9 @@
import {
TSESTree,
TSESLint,
AST_NODE_TYPES,
TSESLint,
TSESTree,
} from '@typescript-eslint/experimental-utils';
import { ScopeType } from '@typescript-eslint/scope-manager';
import { DefinitionType, ScopeType } from '@typescript-eslint/scope-manager';
import * as util from '../util';

type MessageIds = 'noShadow';
Expand Down Expand Up @@ -99,7 +99,9 @@ export default util.createRule<Options, MessageIds>({
}

const isShadowedValue =
'isValueVariable' in shadowed ? shadowed.isValueVariable : true;
!('isValueVariable' in shadowed) ||
(shadowed.defs[0]?.type !== DefinitionType.ImportBinding &&
shadowed.isValueVariable);
return variable.isValueVariable !== isShadowedValue;
}

Expand Down
14 changes: 13 additions & 1 deletion packages/eslint-plugin/tests/rules/no-shadow.test.ts
@@ -1,6 +1,6 @@
import { AST_NODE_TYPES } from '@typescript-eslint/experimental-utils';
import rule from '../../src/rules/no-shadow';
import { RuleTester } from '../RuleTester';
import { AST_NODE_TYPES } from '@typescript-eslint/experimental-utils';

const ruleTester = new RuleTester({
parserOptions: {
Expand Down Expand Up @@ -172,6 +172,18 @@ export class Wrapper<Wrapped> {
}
}
`,
{
// https://github.com/typescript-eslint/typescript-eslint/issues/3862
code: `
import type { foo } from './foo';
type bar = number;
// 'foo' is already declared in the upper scope
// 'bar' is fine
function doThing(foo: number, bar: number) {}
`,
options: [{ ignoreTypeValueShadow: true }],
},
],
invalid: [
{
Expand Down

0 comments on commit c235bc4

Please sign in to comment.