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

Commit

Permalink
no-unnecessary-qualifier: Stop using symbolsAreEqual (#2418)
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-hanson authored and adidahiya committed Mar 28, 2017
1 parent 864a3bc commit 624510c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 15 deletions.
15 changes: 2 additions & 13 deletions src/rules/noUnnecessaryQualifierRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import * as utils from "tsutils";
import * as ts from "typescript";

import * as Lint from "../index";
import { arraysAreEqual } from "../utils";

export class Rule extends Lint.Rules.TypedRule {
/* tslint:disable:object-literal-sort-keys */
Expand Down Expand Up @@ -101,7 +100,7 @@ class Walker extends Lint.ProgramAwareRuleWalker {

// If the symbol in scope is different, the qualifier is necessary.
const fromScope = this.getSymbolInScope(qualifier, accessedSymbol.flags, name.text);
return fromScope === undefined || symbolsAreEqual(fromScope, accessedSymbol);
return fromScope === undefined || fromScope === accessedSymbol;
}

private getSymbolInScope(node: ts.Node, flags: ts.SymbolFlags, name: string): ts.Symbol | undefined {
Expand All @@ -115,7 +114,7 @@ class Walker extends Lint.ProgramAwareRuleWalker {
}

private symbolIsNamespaceInScope(symbol: ts.Symbol): boolean {
if (symbol.getDeclarations().some((decl) => this.namespacesInScope.some((ns) => nodesAreEqual(ns, decl)))) {
if (symbol.getDeclarations().some((decl) => this.namespacesInScope.some((ns) => ns === decl))) {
return true;
}
const alias = this.tryGetAliasedSymbol(symbol);
Expand All @@ -126,13 +125,3 @@ class Walker extends Lint.ProgramAwareRuleWalker {
return Lint.isSymbolFlagSet(symbol, ts.SymbolFlags.Alias) ? this.getTypeChecker().getAliasedSymbol(symbol) : undefined;
}
}

// TODO: Should just be `===`. See https://github.com/palantir/tslint/issues/1969
function nodesAreEqual(a: ts.Node, b: ts.Node) {
return a.pos === b.pos;
}

// Only needed in global files. Likely due to https://github.com/palantir/tslint/issues/1969. See `test.global.ts.lint`.
function symbolsAreEqual(a: ts.Symbol, b: ts.Symbol): boolean {
return arraysAreEqual(a.declarations, b.declarations, nodesAreEqual);
}
4 changes: 4 additions & 0 deletions test/rules/no-unnecessary-qualifier/test-global-2.ts.lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace M {
// Used in test-global.ts
export type T = number;
}
2 changes: 1 addition & 1 deletion test/rules/no-unnecessary-qualifier/test-global.ts.fix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// We need `symbolsAreEqual` in global files.
namespace N {
export type T = number;
export const x: T = 0;
export const x: M.T = 0;
}
2 changes: 1 addition & 1 deletion test/rules/no-unnecessary-qualifier/test-global.ts.lint
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// We need `symbolsAreEqual` in global files.
namespace N {
export type T = number;
export const x: N.T = 0;
~ [Qualifier is unnecessary since 'N' is in scope.]
export const x: M.T = 0;
}

0 comments on commit 624510c

Please sign in to comment.