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

no-unnecessary-qualifier: Stop using symbolsAreEqual #2418

Merged
merged 1 commit into from
Mar 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}