Skip to content

Commit

Permalink
Resolve palantir#471, add tests for spread operator
Browse files Browse the repository at this point in the history
Turns out we don't need to look at node.dotDotToken for BindingElements.
It's literally just a text token. We don't need it for any linting rule
right now, but might in the future.
adidahiya committed Jul 2, 2015
1 parent 089e38f commit 4392205
Showing 6 changed files with 10 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/rules/noDuplicateVariableRule.ts
Original file line number Diff line number Diff line change
@@ -32,7 +32,6 @@ class NoDuplicateVariableWalker extends Lint.BlockScopeAwareRuleWalker<{}, Scope
}

public visitBindingElement(node: ts.BindingElement) {
// #471: handle node.dotdotToken?
const isSingleVariable = node.name.kind === ts.SyntaxKind.Identifier;
const isBlockScoped = Lint.isBlockScopedBindingElement(node);

1 change: 0 additions & 1 deletion src/rules/noShadowedVariableRule.ts
Original file line number Diff line number Diff line change
@@ -32,7 +32,6 @@ class NoShadowedVariableWalker extends Lint.BlockScopeAwareRuleWalker<ScopeInfo,
}

public visitBindingElement(node: ts.BindingElement) {
// #471: handle node.dotDotDotToken?
const isSingleVariable = node.name.kind === ts.SyntaxKind.Identifier;
const isBlockScoped = Lint.isBlockScopedBindingElement(node);

3 changes: 3 additions & 0 deletions test/files/rules/no-duplicate-variable.test.ts
Original file line number Diff line number Diff line change
@@ -156,4 +156,7 @@ function testDestructuring() {
var a; // not a failure; caught by no-shadowed-variable
return b;
}

var [x, y3] = myFunc(); // failure
var [x3, ...y] = [1, 2, 3, 4]; // failure
}
2 changes: 2 additions & 0 deletions test/files/rules/no-shadowed-variable.test.ts
Original file line number Diff line number Diff line change
@@ -93,5 +93,7 @@ function testDestructuring(x: number) {
function anotherInnerFunc() {
var [{x}] = [{x: 1}]; // failure
let [[y]] = [[2]]; // failure
var [foo, ...bar] = [1, 2, 3, 4];
var [...z] = [1, 2, 3, 4]; // failure
}
}
4 changes: 3 additions & 1 deletion test/rules/noDuplicateVariableRuleTests.ts
Original file line number Diff line number Diff line change
@@ -26,7 +26,9 @@ describe("<no-duplicate-variable>", () => {
createFailure([22, 9], [22, 19]),
createFailure([26, 5], [26, 15]),
Lint.Test.createFailure(fileName, [141, 13], [141, 14], NoDuplicateVariableRule.FAILURE_STRING + "z'"),
Lint.Test.createFailure(fileName, [153, 11], [153, 13], NoDuplicateVariableRule.FAILURE_STRING + "a2'")
Lint.Test.createFailure(fileName, [153, 11], [153, 13], NoDuplicateVariableRule.FAILURE_STRING + "a2'"),
Lint.Test.createFailure(fileName, [160, 10], [160, 11], NoDuplicateVariableRule.FAILURE_STRING + "x'"),
Lint.Test.createFailure(fileName, [161, 17], [161, 18], NoDuplicateVariableRule.FAILURE_STRING + "y'")
];

const actualFailures = Lint.Test.applyRuleOnFile(fileName, NoDuplicateVariableRule);
3 changes: 2 additions & 1 deletion test/rules/noShadowedVariableRuleTests.ts
Original file line number Diff line number Diff line change
@@ -39,7 +39,8 @@ describe("<no-shadowed-variable>", () => {
Lint.Test.createFailure(fileName, [89, 14], [89, 15], NoShadowedVariableRule.FAILURE_STRING + "y'"),
Lint.Test.createFailure(fileName, [90, 16], [90, 17], NoShadowedVariableRule.FAILURE_STRING + "z'"),
Lint.Test.createFailure(fileName, [94, 15], [94, 16], NoShadowedVariableRule.FAILURE_STRING + "x'"),
Lint.Test.createFailure(fileName, [95, 15], [95, 16], NoShadowedVariableRule.FAILURE_STRING + "y'")
Lint.Test.createFailure(fileName, [95, 15], [95, 16], NoShadowedVariableRule.FAILURE_STRING + "y'"),
Lint.Test.createFailure(fileName, [97, 17], [97, 18], NoShadowedVariableRule.FAILURE_STRING + "z'")
];
const actualFailures = Lint.Test.applyRuleOnFile(fileName, NoShadowedVariableRule);

0 comments on commit 4392205

Please sign in to comment.