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

Commit 9632094

Browse files
ajafffadidahiya
authored andcommitted
Update to typescript@2.6 (#3320)
1 parent c102450 commit 9632094

File tree

16 files changed

+65
-25
lines changed

16 files changed

+65
-25
lines changed

.vscode/launch.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"request": "launch",
2828
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
2929
"stopOnEntry": false,
30-
"args": ["--reporter", "spec", "--colors", "--no-timeouts", "build/test/**/*Tests.js", "build/test/assert.js"],
30+
"args": ["--reporter", "spec", "--colors", "--no-timeouts", "build/test/**/*Tests.js"],
3131
"cwd": "${workspaceRoot}",
3232
"preLaunchTask": "tsc",
3333
"runtimeExecutable": null,
@@ -38,7 +38,7 @@
3838
"NODE_ENV": "development"
3939
},
4040
"console": "internalConsole",
41-
"sourceMaps": true,
41+
"sourceMaps": true,
4242
"outFiles": ["${workspaceRoot}/build/**/*.js"]
4343
},
4444
{
@@ -58,7 +58,7 @@
5858
"NODE_ENV": "development"
5959
},
6060
"console": "internalConsole",
61-
"sourceMaps": true,
61+
"sourceMaps": true,
6262
"outFiles": ["${workspaceRoot}/build/**/*.js"]
6363
},
6464
{
@@ -78,7 +78,7 @@
7878
"NODE_ENV": "development"
7979
},
8080
"console": "internalConsole",
81-
"sourceMaps": true,
81+
"sourceMaps": true,
8282
"outFiles": ["${workspaceRoot}/build/**/*/js"]
8383
}
8484
]

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@
4646
"minimatch": "^3.0.4",
4747
"resolve": "^1.3.2",
4848
"semver": "^5.3.0",
49-
"tslib": "^1.8",
49+
"tslib": "^1.8.0",
5050
"tsutils": "^2.12.1"
5151
},
5252
"peerDependencies": {
53-
"typescript": ">=2.1.0 || >=2.1.0-dev || >=2.2.0-dev || >=2.3.0-dev || >=2.4.0-dev || >=2.5.0-dev || >=2.6.0-dev || >=2.7.0-dev"
53+
"typescript": ">=2.1.0 || >=2.1.0-dev || >=2.2.0-dev || >=2.3.0-dev || >=2.4.0-dev || >=2.5.0-dev || >=2.6.0-dev || >=2.7.0-dev || >=2.8.0-dev"
5454
},
5555
"devDependencies": {
5656
"@types/babel-code-frame": "^6.20.0",
@@ -77,7 +77,7 @@
7777
"ts-node": "^3.3.0",
7878
"tslint": "^5.7.0",
7979
"tslint-test-config-non-relative": "file:test/external/tslint-test-config-non-relative",
80-
"typescript": "~2.5.1"
80+
"typescript": "~2.6.1"
8181
},
8282
"license": "Apache-2.0",
8383
"engines": {

src/language/utils.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,10 @@ export function someAncestor(node: ts.Node, predicate: (n: ts.Node) => boolean):
9393
return predicate(node) || (node.parent !== undefined && someAncestor(node.parent, predicate));
9494
}
9595

96-
export function ancestorWhere<T extends ts.Node>(node: ts.Node, predicate: (n: ts.Node) => n is T): T | undefined;
97-
export function ancestorWhere(node: ts.Node, predicate: (n: ts.Node) => boolean): ts.Node | undefined;
98-
export function ancestorWhere<T extends ts.Node>(node: ts.Node, predicate: (n: ts.Node) => n is T): T | undefined {
96+
export function ancestorWhere<T extends ts.Node = ts.Node>(
97+
node: ts.Node,
98+
predicate: ((n: ts.Node) => n is T) | ((n: ts.Node) => boolean),
99+
): T | undefined {
99100
let cur: ts.Node | undefined = node;
100101
do {
101102
if (predicate(cur)) {

src/linter.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import { IFormatter } from "./language/formatter/formatter";
3737
import { IRule, isTypedRule, Replacement, RuleFailure, RuleSeverity } from "./language/rule/rule";
3838
import * as utils from "./language/utils";
3939
import { loadRules } from "./ruleLoader";
40-
import { arrayify, dedent, flatMap } from "./utils";
40+
import { arrayify, dedent, flatMap, mapDefined } from "./utils";
4141

4242
/**
4343
* Linter that can lint multiple files in consecutive runs.
@@ -76,7 +76,13 @@ class Linter {
7676
* files and excludes declaration (".d.ts") files.
7777
*/
7878
public static getFileNames(program: ts.Program): string[] {
79-
return program.getSourceFiles().map((s) => s.fileName).filter((l) => l.substr(-5) !== ".d.ts");
79+
return mapDefined(
80+
program.getSourceFiles(),
81+
(file) =>
82+
file.fileName.endsWith(".d.ts") || program.isSourceFileFromExternalLibrary(file)
83+
? undefined
84+
: file.fileName,
85+
);
8086
}
8187

8288
constructor(private options: ILinterOptions, private program?: ts.Program) {

src/rules/noImplicitDependenciesRule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ function walk(ctx: Lint.WalkContext<Options>) {
7575
const {options} = ctx;
7676
let dependencies: Set<string> | undefined;
7777
for (const name of findImports(ctx.sourceFile, ImportKind.All)) {
78-
if (!(ts as {} as {isExternalModuleNameRelative(m: string): boolean}).isExternalModuleNameRelative(name.text)) {
78+
if (!ts.isExternalModuleNameRelative(name.text)) {
7979
const packageName = getPackageName(name.text);
8080
if (builtins.indexOf(packageName) === -1 && !hasDependency(packageName)) {
8181
ctx.addFailureAtNode(name, Rule.FAILURE_STRING_FACTORY(packageName));

src/rules/noSubmoduleImportsRule.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ export class Rule extends Lint.Rules.AbstractRule {
5050

5151
function walk(ctx: Lint.WalkContext<string[]>) {
5252
for (const name of findImports(ctx.sourceFile, ImportKind.All)) {
53-
// TODO remove assertion on upgrade to typescript@2.5.2
54-
if (!(ts as any as {isExternalModuleNameRelative(m: string): boolean}).isExternalModuleNameRelative(name.text) &&
53+
if (!ts.isExternalModuleNameRelative(name.text) &&
5554
isSubmodulePath(name.text) &&
5655
!isWhitelisted(name.text, ctx.options)) {
5756
ctx.addFailureAtNode(name, Rule.FAILURE_STRING);

src/rules/noUnnecessaryQualifierRule.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,8 @@ function walk(ctx: Lint.WalkContext<void>, checker: ts.TypeChecker): void {
120120
}
121121

122122
function symbolsAreEqual(accessed: ts.Symbol, inScope: ts.Symbol): boolean {
123-
// TODO remove type assertion on update to typescript@2.6.0
124-
if ((checker as any as {getExportSymbolOfSymbol(s: ts.Symbol): ts.Symbol}).getExportSymbolOfSymbol !== undefined) {
125-
inScope = (checker as any as {getExportSymbolOfSymbol(s: ts.Symbol): ts.Symbol}).getExportSymbolOfSymbol(inScope);
123+
if (checker.getExportSymbolOfSymbol !== undefined) {
124+
inScope = checker.getExportSymbolOfSymbol(inScope);
126125
return accessed === inScope;
127126
}
128127
return accessed === inScope ||

src/rules/orderedImportsRule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ const TRANSFORMS = new Map<string, Transform>([
132132
["lowercase-last", (x) => x],
133133
["full", (x) => x],
134134
["basename", (x) => {
135-
if (!(ts as any as {isExternalModuleNameRelative(m: string): boolean}).isExternalModuleNameRelative(x)) {
135+
if (!ts.isExternalModuleNameRelative(x)) {
136136
return x;
137137
}
138138

src/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"noUnusedParameters": true,
88
"noUnusedLocals": true,
99
"strictNullChecks": true,
10+
"strictFunctionTypes": true,
1011
"importHelpers": true,
1112
"declaration": true,
1213
"sourceMap": false,

test/executable/executableTests.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ describe("Executable", function(this: Mocha.ISuiteCallbackContext) {
423423
});
424424
});
425425

426-
it("can handles 'allowJs' correctly", (done) => {
426+
it("handles 'allowJs' correctly", (done) => {
427427
execCli(
428428
[ "-p", "test/files/tsconfig-allow-js/tsconfig.json"],
429429
(err) => {
@@ -433,6 +433,15 @@ describe("Executable", function(this: Mocha.ISuiteCallbackContext) {
433433
});
434434
});
435435

436+
it("doesn't lint external dependencies with 'allowJs'", (done) => {
437+
execCli(
438+
[ "-p", "test/files/allow-js-exclude-node-modules/tsconfig.json"],
439+
(err) => {
440+
assert.isNull(err, "process should exit without error");
441+
done();
442+
});
443+
});
444+
436445
it("works with '--exclude'", (done) => {
437446
execCli(
438447
[ "-p", "test/files/tsconfig-allow-js/tsconfig.json", "-e", "'test/files/tsconfig-allow-js/testfile.test.js'"],
@@ -566,7 +575,7 @@ function execCli(args: string[], options: cp.ExecFileOptions | ExecFileCallback,
566575
});
567576
}
568577

569-
function isFunction(fn: any): fn is (...args: any[]) => any {
578+
function isFunction(fn: any): fn is Function { // tslint:disable-line:ban-types
570579
return ({}).toString.call(fn) === "[object Function]";
571580
}
572581

0 commit comments

Comments
 (0)