Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Rewrite no-duplicate-variable #2354

Merged
merged 2 commits into from
Mar 29, 2017

Conversation

andy-hanson
Copy link
Contributor

PR checklist

  • Addresses an existing issue: #0000
  • New feature, bugfix, or enhancement
    • Includes tests
  • Documentation update

Overview of change:

Just refactored the implementation.

Copy link
Contributor

@ajafff ajafff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added some comments. no blocker, but would be nice to have

btw. shouldn't this also handle parameters?

forEachBoundIdentifier(e.name, action);
}
break;
case ts.SyntaxKind.ArrayBindingPattern:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can make this case clause the default clause and handle both binding patterns to avoid duplicated code since both blocks are very similar. you can then drop the case ObjectBindingPattern

if (utils.isVariableDeclaration(node) && !utils.isBlockScopedVariableDeclaration(node)) {
const scope = scopes[scopes.length - 1];
forEachBoundIdentifier(node.name, (id) => {
const { text } = id;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

destructure the parameter directly

({text}) => { ... }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's jused as a node below.

const scopes: Array<Set<string>> = [new Set()];
return ts.forEachChild(ctx.sourceFile, function cb(node: ts.Node): void {
if (utils.isFunctionScopeBoundary(node)) {
scopes.push(new Set());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need a stack. just replace scopes with scope. Save it in a variable here, assign the new Scope and restore it 2 lines below.

@andy-hanson
Copy link
Contributor Author

There's a comment in the tests saying that parameters should be handled by no-shadowed-variable.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants