Skip to content

Commit

Permalink
Fixes for no-shadowed-variable rule (palantir#1482)
Browse files Browse the repository at this point in the history
  • Loading branch information
IllusionMH authored and jkillian committed Aug 17, 2016
1 parent b12b954 commit 68ce8d5
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/rules/noShadowedVariableRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ class NoShadowedVariableWalker extends Lint.BlockScopeAwareRuleWalker<ScopeInfo,
// don't call super, we don't need to check names in function types
}

public visitConstructorType(node: ts.FunctionOrConstructorTypeNode) {
// don't call super, we don't need to check names in constructor types
}

public visitIndexSignatureDeclaration(node: ts.SignatureDeclaration) {
// don't call super, we don't want to walk index signatures
}

public visitMethodSignature(node: ts.SignatureDeclaration) {
// don't call super, we don't want to walk method signatures either
}
Expand Down
51 changes: 51 additions & 0 deletions test/rules/no-shadowed-variable/test.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,54 @@ function testParameterDestructuring(
function testSimpleBlockVar() {
const simpleBlockVar = 4
}

interface SeparateIndexeSighatures1 {
[separate: string]: any;
}
interface SeparateIndexeSighatures2 {
[separate: number]: any;
}

const external = 1;
interface ExternalIndexSignature1 {
[external: string]: any;
}
interface ExternalIndexSignature2 {
[external: number]: any;
}

interface CombinedIndexeSighatures {
[i: string]: any;
[i: number]: any;
}

function constructorsWithArgs(
derivedCtor: new (...args: any[]) => any,
baseCtors: Array<new (...args: any[]) => any>): void {
// ...
}

function constructorsWithArgsConst(
derivedCtor: new (...args: any[]) => any,
baseCtors: Array<new (...args: any[]) => any>): void {
const args = [];
}

function constructorsWithArgsParamConst(
derivedCtor: new (...args: any[]) => any,
baseCtors: Array<new (...args: any[]) => any>,
args: any[]): void {
const args = [];
~~~~ [Shadowed variable: 'args']
}

class MyClass { };

declare type MyConstructor = new (myVariable: any) => MyClass;
declare type MyFunction = (myParameter: any) => boolean;

function creatorFunction(constructor: MyConstructor, filter: MyFunction): void {
const myVariable = 1;
const myParameter = 1;
console.log(myVariable);
}

0 comments on commit 68ce8d5

Please sign in to comment.