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

Fix failures on typescript@next #2789

Merged
merged 2 commits into from
May 20, 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"resolve": "^1.3.2",
"semver": "^5.3.0",
"tslib": "^1.6.0",
"tsutils": "^1.9.1"
"tsutils": "^2.0.0"
},
"peerDependencies": {
"typescript": ">=2.1.0 || >=2.1.0-dev || >=2.2.0-dev || >=2.3.0-dev || >=2.4.0-dev"
Expand Down
5 changes: 3 additions & 2 deletions src/rules/completedDocsRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,8 @@ class CompletedDocsWalker extends Lint.ProgramAwareRuleWalker {
}

private checkNode(node: ts.Declaration, nodeType: DocType): void {
if (node.name === undefined) {
const { name } = node;
if (name === undefined) {
return;
}

Expand All @@ -398,7 +399,7 @@ class CompletedDocsWalker extends Lint.ProgramAwareRuleWalker {
return;
}

const symbol = this.getTypeChecker().getSymbolAtLocation(node.name);
const symbol = this.getTypeChecker().getSymbolAtLocation(name);
if (symbol === undefined) {
return;
}
Expand Down
9 changes: 7 additions & 2 deletions src/rules/matchDefaultExportNameRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,14 @@ function walk(ctx: Lint.WalkContext<void>, tc: ts.TypeChecker) {
continue;
}
const defaultImport = statement.importClause.name;
const {declarations} = tc.getAliasedSymbol(tc.getSymbolAtLocation(defaultImport));
const symbol = tc.getSymbolAtLocation(defaultImport);
if (symbol === undefined || !Lint.isSymbolFlagSet(symbol, ts.SymbolFlags.Alias)) {
continue;
}

const {declarations} = tc.getAliasedSymbol(symbol);
if (declarations !== undefined && declarations.length !== 0) {
const [{name}] = declarations;
const { name } = declarations[0];
if (name !== undefined && name.kind === ts.SyntaxKind.Identifier && name.text !== defaultImport.text) {
ctx.addFailureAtNode(defaultImport, Rule.FAILURE_STRING(defaultImport.text, name.text));
}
Expand Down
18 changes: 12 additions & 6 deletions src/rules/noInferredEmptyObjectTypeRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,18 @@ class NoInferredEmptyObjectTypeRule extends Lint.AbstractWalker<void> {
}

private checkCallExpression(node: ts.CallExpression): void {
if (node.typeArguments === undefined) {
const callSig = this.checker.getResolvedSignature(node);
const retType = this.checker.getReturnTypeOfSignature(callSig) as ts.TypeReference;
if (this.isEmptyObjectInterface(retType)) {
this.addFailureAtNode(node, Rule.EMPTY_INTERFACE_FUNCTION);
}
if (node.typeArguments !== undefined) {
return;
}

const callSig = this.checker.getResolvedSignature(node);
if (callSig === undefined) {
return;
}

const retType = this.checker.getReturnTypeOfSignature(callSig) as ts.TypeReference;
if (this.isEmptyObjectInterface(retType)) {
this.addFailureAtNode(node, Rule.EMPTY_INTERFACE_FUNCTION);
}
}

Expand Down
13 changes: 7 additions & 6 deletions src/rules/noUnusedVariableRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ function walk(ctx: Lint.WalkContext<void>, program: ts.Program, { checkParameter
const failure = ts.flattenDiagnosticMessageText(diag.messageText, "\n");

if (kind === UnusedKind.VARIABLE_OR_PARAMETER) {
const importName = findImport(diag.start, sourceFile);
const importName = findImport(diag.start!, sourceFile);
if (importName !== undefined) {
if (isImportUsed(importName, sourceFile, checker)) {
continue;
Expand All @@ -138,7 +138,7 @@ function walk(ctx: Lint.WalkContext<void>, program: ts.Program, { checkParameter
}
}

ctx.addFailureAt(diag.start, diag.length, failure);
ctx.addFailureAt(diag.start!, diag.length!, failure);
}

if (importSpecifierFailures.size !== 0) {
Expand Down Expand Up @@ -251,12 +251,12 @@ function addImportSpecifierFailures(ctx: Lint.WalkContext<void>, failures: Map<t
* Workround for https://github.com/Microsoft/TypeScript/issues/9944
*/
function isImportUsed(importSpecifier: ts.Identifier, sourceFile: ts.SourceFile, checker: ts.TypeChecker): boolean {
let symbol = checker.getSymbolAtLocation(importSpecifier);
if (symbol === undefined) {
const importedSymbol = checker.getSymbolAtLocation(importSpecifier);
if (importedSymbol === undefined) {
return false;
}

symbol = checker.getAliasedSymbol(symbol);
const symbol = checker.getAliasedSymbol(importedSymbol);
if (!Lint.isSymbolFlagSet(symbol, ts.SymbolFlags.Type)) {
return false;
}
Expand All @@ -280,7 +280,8 @@ function getImplicitType(node: ts.Node, checker: ts.TypeChecker): ts.Type | unde
if ((utils.isPropertyDeclaration(node) || utils.isVariableDeclaration(node)) && node.type === undefined) {
return checker.getTypeAtLocation(node);
} else if (utils.isSignatureDeclaration(node) && node.type === undefined) {
return checker.getSignatureFromDeclaration(node).getReturnType();
const sig = checker.getSignatureFromDeclaration(node);
return sig === undefined ? undefined : sig.getReturnType();
} else {
return undefined;
}
Expand Down
7 changes: 4 additions & 3 deletions src/rules/restrictPlusOperandsRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { isBinaryExpression, isEnumLiteralType, isUnionType } from "tsutils";
import { isBinaryExpression, isUnionType } from "tsutils";
import * as ts from "typescript";

import * as Lint from "../index";
Expand Down Expand Up @@ -63,8 +63,9 @@ function getBaseTypeOfLiteralType(type: ts.Type): "string" | "number" | "invalid
} else if (isUnionType(type) && !Lint.isTypeFlagSet(type, ts.TypeFlags.Enum)) {
const types = type.types.map(getBaseTypeOfLiteralType);
return allSame(types) ? types[0] : "invalid";
} else if (isEnumLiteralType(type)) {
return getBaseTypeOfLiteralType(type.baseType);
} else if (Lint.isTypeFlagSet(type, (ts.TypeFlags as { EnumLiteral: ts.TypeFlags }).EnumLiteral)) {
// Compatibility for TypeScript pre-2.4, which used EnumLiteralType instead of LiteralType
getBaseTypeOfLiteralType((type as any as { baseType: ts.LiteralType }).baseType);
}
return "invalid";
}
Expand Down
12 changes: 10 additions & 2 deletions src/rules/strictBooleanExpressionsRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,9 @@ function getKind(type: ts.Type): TypeKind {
: is(ts.TypeFlags.Undefined | ts.TypeFlags.Void) ? TypeKind.Undefined // tslint:disable-line:no-bitwise
: is(ts.TypeFlags.EnumLike) ? TypeKind.Enum
: is(ts.TypeFlags.NumberLiteral) ?
((type as ts.LiteralType).text === "0" ? TypeKind.FalseNumberLiteral : TypeKind.AlwaysTruthy)
(numberLiteralIsZero(type as ts.LiteralType) ? TypeKind.FalseNumberLiteral : TypeKind.AlwaysTruthy)
: is(ts.TypeFlags.StringLiteral) ?
((type as ts.LiteralType).text === "" ? TypeKind.FalseStringLiteral : TypeKind.AlwaysTruthy)
(stringLiteralIsEmpty(type as ts.LiteralType) ? TypeKind.FalseStringLiteral : TypeKind.AlwaysTruthy)
: is(ts.TypeFlags.BooleanLiteral) ?
((type as ts.IntrinsicType).intrinsicName === "true" ? TypeKind.AlwaysTruthy : TypeKind.FalseBooleanLiteral)
: TypeKind.AlwaysTruthy;
Expand All @@ -321,6 +321,14 @@ function getKind(type: ts.Type): TypeKind {
}
}

function numberLiteralIsZero(type: ts.LiteralType): boolean {
// Uses 'value' in TypeScript>=2.4.
return (type as any).value !== undefined ? (type as any).value === 0 : type.text === "0";
}
function stringLiteralIsEmpty(type: ts.LiteralType): boolean {
return ((type as any).value !== undefined ? (type as any).value : type.text) === "";
}

/** Matches `&&` and `||` operators. */
function isBooleanBinaryExpression(node: ts.Expression): boolean {
return node.kind === ts.SyntaxKind.BinaryExpression && binaryBooleanExpressionKind(node as ts.BinaryExpression) !== undefined;
Expand Down
2 changes: 1 addition & 1 deletion src/rules/unifiedSignaturesRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ function signatureUsesTypeParameter(sig: ts.SignatureDeclaration, isTypeParamete
return true;
}
}
return !!ts.forEachChild(type, typeContainsTypeParameter);
return ts.forEachChild(type, typeContainsTypeParameter);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export class Runner {
// emit any error messages
let message = ts.DiagnosticCategory[diag.category];
if (diag.file) {
const { line, character } = diag.file.getLineAndCharacterOfPosition(diag.start);
const { line, character } = diag.file.getLineAndCharacterOfPosition(diag.start!);
let file: string;
const currentDirectory = program!.getCurrentDirectory();
file = this.options.outputAbsolutePaths
Expand Down
73 changes: 44 additions & 29 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-2.2.41.tgz#e27cf0817153eb9f2713b2d3f6c68f1e1c3ca608"

"@types/node@*", "@types/node@^7.0.16":
version "7.0.18"
resolved "https://registry.yarnpkg.com/@types/node/-/node-7.0.18.tgz#cd67f27d3dc0cfb746f0bdd5e086c4c5d55be173"
version "7.0.21"
resolved "https://registry.yarnpkg.com/@types/node/-/node-7.0.21.tgz#22a890f19b26cff9b6699b493dea1bcee4410da1"

"@types/optimist@0.0.29":
version "0.0.29"
Expand Down Expand Up @@ -204,14 +204,14 @@ babel-types@^6.18.0, babel-types@^6.24.1:
to-fast-properties "^1.0.1"

babylon@^6.11.0, babylon@^6.13.0, babylon@^6.15.0:
version "6.17.0"
resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.17.0.tgz#37da948878488b9c4e3c4038893fa3314b3fc932"
version "6.17.1"
resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.17.1.tgz#17f14fddf361b695981fe679385e4f1c01ebd86f"

balanced-match@^0.4.1:
version "0.4.2"
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-0.4.2.tgz#cb3f3e3c732dc0f01ee70b403f302e61d7709838"

brace-expansion@^1.0.0:
brace-expansion@^1.1.7:
version "1.1.7"
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.7.tgz#3effc3c50e000531fb720eaff80f0ae8ef23cf59"
dependencies:
Expand Down Expand Up @@ -343,10 +343,10 @@ debug@2, debug@2.6.0, debug@^2.2.0:
ms "0.7.2"

debug@^2.6.3:
version "2.6.6"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.6.tgz#a9fa6fbe9ca43cf1e79f73b75c0189cbb7d6db5a"
version "2.6.8"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.8.tgz#e731531ca2ede27d188222427da17821d68ff4fc"
dependencies:
ms "0.7.3"
ms "2.0.0"

decamelize@^1.0.0, decamelize@^1.1.1:
version "1.2.0"
Expand Down Expand Up @@ -555,7 +555,7 @@ glob-parent@^2.0.0:
dependencies:
is-glob "^2.0.0"

glob@7.1.1, glob@^7.0.5, glob@^7.0.6, glob@^7.1.1:
glob@7.1.1:
version "7.1.1"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.1.tgz#805211df04faaf1c63a3600306cdf5ade50b2ec8"
dependencies:
Expand All @@ -566,6 +566,17 @@ glob@7.1.1, glob@^7.0.5, glob@^7.0.6, glob@^7.1.1:
once "^1.3.0"
path-is-absolute "^1.0.0"

glob@^7.0.5, glob@^7.0.6, glob@^7.1.1:
version "7.1.2"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.2.tgz#c19c9df9a028702d678612384a6552404c636d15"
dependencies:
fs.realpath "^1.0.0"
inflight "^1.0.4"
inherits "2"
minimatch "^3.0.4"
once "^1.3.0"
path-is-absolute "^1.0.0"

glob@~5.0.0:
version "5.0.15"
resolved "https://registry.yarnpkg.com/glob/-/glob-5.0.15.tgz#1bc936b9e02f4a603fcc222ecf7633d30b8b93b1"
Expand Down Expand Up @@ -811,8 +822,8 @@ js-tokens@^3.0.0:
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.1.tgz#08e9f132484a2c45a30907e9dc4d5567b7f114d7"

js-yaml@^3.7.0:
version "3.8.3"
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.8.3.tgz#33a05ec481c850c8875929166fe1beb61c728766"
version "3.8.4"
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.8.4.tgz#520b4564f86573ba96662af85a8cafa7b4b5a6f6"
dependencies:
argparse "^1.0.7"
esprima "^3.1.1"
Expand All @@ -834,8 +845,8 @@ jsonify@~0.0.0:
resolved "https://registry.yarnpkg.com/jsonify/-/jsonify-0.0.0.tgz#2c74b6ee41d93ca51b7b5aaee8f503631d252a73"

kind-of@^3.0.2:
version "3.2.0"
resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-3.2.0.tgz#b58abe4d5c044ad33726a8c1525b48cf891bff07"
version "3.2.2"
resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-3.2.2.tgz#31ea21a734bab9bbb0f32466d893aea51e4a3c64"
dependencies:
is-buffer "^1.1.5"

Expand Down Expand Up @@ -972,14 +983,14 @@ micromatch@^2.3.11:
regex-cache "^0.4.2"

mime@^1.2.11:
version "1.3.4"
resolved "https://registry.yarnpkg.com/mime/-/mime-1.3.4.tgz#115f9e3b6b3daf2959983cb38f149a2d40eb5d53"
version "1.3.6"
resolved "https://registry.yarnpkg.com/mime/-/mime-1.3.6.tgz#591d84d3653a6b0b4a3b9df8de5aa8108e72e5e0"

"minimatch@2 || 3", minimatch@^3.0.2:
version "3.0.3"
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.3.tgz#2a4e4090b96b2db06a9d7df01055a62a77c9b774"
"minimatch@2 || 3", minimatch@^3.0.2, minimatch@^3.0.4:
version "3.0.4"
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083"
dependencies:
brace-expansion "^1.0.0"
brace-expansion "^1.1.7"

minimist@0.0.8:
version "0.0.8"
Expand All @@ -996,8 +1007,8 @@ mkdirp@0.5.1, mkdirp@^0.5.0, mkdirp@^0.5.1:
minimist "0.0.8"

mocha@^3.2.0:
version "3.3.0"
resolved "https://registry.yarnpkg.com/mocha/-/mocha-3.3.0.tgz#d29b7428d3f52c82e2e65df1ecb7064e1aabbfb5"
version "3.4.1"
resolved "https://registry.yarnpkg.com/mocha/-/mocha-3.4.1.tgz#a3802b4aa381934cacb38de70cf771621da8f9af"
dependencies:
browser-stdout "1.3.0"
commander "2.9.0"
Expand All @@ -1015,9 +1026,9 @@ ms@0.7.2:
version "0.7.2"
resolved "https://registry.yarnpkg.com/ms/-/ms-0.7.2.tgz#ae25cf2512b3885a1d95d7f037868d8431124765"

ms@0.7.3:
version "0.7.3"
resolved "https://registry.yarnpkg.com/ms/-/ms-0.7.3.tgz#708155a5e44e33f5fd0fc53e81d0d40a91be1fff"
ms@2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"

netrc@^0.1.4:
version "0.1.4"
Expand Down Expand Up @@ -1447,8 +1458,8 @@ trim-right@^1.0.1:
resolved "https://registry.yarnpkg.com/trim-right/-/trim-right-1.0.1.tgz#cb2e1203067e0c8de1f614094b9fe45704ea6003"

tslib@^1.6.0:
version "1.7.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.7.0.tgz#6e8366695f72961252b35167b0dd4fbeeafba491"
version "1.7.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.7.1.tgz#bc8004164691923a79fe8378bbeb3da2017538ec"

"tslint-test-config-non-relative@file:test/external/tslint-test-config-non-relative":
version "0.0.1"
Expand All @@ -1468,10 +1479,14 @@ tslint@latest:
tslib "^1.6.0"
tsutils "^1.8.0"

tsutils@^1.8.0, tsutils@^1.9.1:
tsutils@^1.8.0:
version "1.9.1"
resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-1.9.1.tgz#b9f9ab44e55af9681831d5f28d0aeeaf5c750cb0"

tsutils@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-2.0.0.tgz#ae0ca48a4b431b5c04e4f711a9227aa2e37e2e04"

type-detect@0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-0.1.1.tgz#0ba5ec2a885640e470ea4e8505971900dac58822"
Expand All @@ -1485,8 +1500,8 @@ typescript@^2.3.0:
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.3.2.tgz#f0f045e196f69a72f06b25fd3bd39d01c3ce9984"

uglify-js@^2.6:
version "2.8.22"
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-2.8.22.tgz#d54934778a8da14903fa29a326fb24c0ab51a1a0"
version "2.8.27"
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-2.8.27.tgz#47787f912b0f242e5b984343be8e35e95f694c9c"
dependencies:
source-map "~0.5.1"
yargs "~3.10.0"
Expand Down