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

Update to typescript@2.6 #3320

Merged
merged 10 commits into from
Oct 31, 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
8 changes: 4 additions & 4 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"request": "launch",
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
"stopOnEntry": false,
"args": ["--reporter", "spec", "--colors", "--no-timeouts", "build/test/**/*Tests.js", "build/test/assert.js"],
"args": ["--reporter", "spec", "--colors", "--no-timeouts", "build/test/**/*Tests.js"],
"cwd": "${workspaceRoot}",
"preLaunchTask": "tsc",
"runtimeExecutable": null,
Expand All @@ -38,7 +38,7 @@
"NODE_ENV": "development"
},
"console": "internalConsole",
"sourceMaps": true,
"sourceMaps": true,
"outFiles": ["${workspaceRoot}/build/**/*.js"]
},
{
Expand All @@ -58,7 +58,7 @@
"NODE_ENV": "development"
},
"console": "internalConsole",
"sourceMaps": true,
"sourceMaps": true,
"outFiles": ["${workspaceRoot}/build/**/*.js"]
},
{
Expand All @@ -78,7 +78,7 @@
"NODE_ENV": "development"
},
"console": "internalConsole",
"sourceMaps": true,
"sourceMaps": true,
"outFiles": ["${workspaceRoot}/build/**/*/js"]
}
]
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@
"minimatch": "^3.0.4",
"resolve": "^1.3.2",
"semver": "^5.3.0",
"tslib": "^1.8",
"tslib": "^1.8.0",
"tsutils": "^2.12.1"
},
"peerDependencies": {
"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"
"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"
},
"devDependencies": {
"@types/babel-code-frame": "^6.20.0",
Expand All @@ -77,7 +77,7 @@
"ts-node": "^3.3.0",
"tslint": "^5.7.0",
"tslint-test-config-non-relative": "file:test/external/tslint-test-config-non-relative",
"typescript": "~2.5.1"
"typescript": "~2.6.1"
},
"license": "Apache-2.0",
"engines": {
Expand Down
7 changes: 4 additions & 3 deletions src/language/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ export function someAncestor(node: ts.Node, predicate: (n: ts.Node) => boolean):
return predicate(node) || (node.parent !== undefined && someAncestor(node.parent, predicate));
}

export function ancestorWhere<T extends ts.Node>(node: ts.Node, predicate: (n: ts.Node) => n is T): T | undefined;
export function ancestorWhere(node: ts.Node, predicate: (n: ts.Node) => boolean): ts.Node | undefined;
export function ancestorWhere<T extends ts.Node>(node: ts.Node, predicate: (n: ts.Node) => n is T): T | undefined {
export function ancestorWhere<T extends ts.Node = ts.Node>(
node: ts.Node,
predicate: ((n: ts.Node) => n is T) | ((n: ts.Node) => boolean),
): T | undefined {
let cur: ts.Node | undefined = node;
do {
if (predicate(cur)) {
Expand Down
10 changes: 8 additions & 2 deletions src/linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { IFormatter } from "./language/formatter/formatter";
import { IRule, isTypedRule, Replacement, RuleFailure, RuleSeverity } from "./language/rule/rule";
import * as utils from "./language/utils";
import { loadRules } from "./ruleLoader";
import { arrayify, dedent, flatMap } from "./utils";
import { arrayify, dedent, flatMap, mapDefined } from "./utils";

/**
* Linter that can lint multiple files in consecutive runs.
Expand Down Expand Up @@ -76,7 +76,13 @@ class Linter {
* files and excludes declaration (".d.ts") files.
*/
public static getFileNames(program: ts.Program): string[] {
return program.getSourceFiles().map((s) => s.fileName).filter((l) => l.substr(-5) !== ".d.ts");
return mapDefined(
program.getSourceFiles(),
(file) =>
file.fileName.endsWith(".d.ts") || program.isSourceFileFromExternalLibrary(file)
? undefined
: file.fileName,
);
}

constructor(private options: ILinterOptions, private program?: ts.Program) {
Expand Down
2 changes: 1 addition & 1 deletion src/rules/noImplicitDependenciesRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function walk(ctx: Lint.WalkContext<Options>) {
const {options} = ctx;
let dependencies: Set<string> | undefined;
for (const name of findImports(ctx.sourceFile, ImportKind.All)) {
if (!(ts as {} as {isExternalModuleNameRelative(m: string): boolean}).isExternalModuleNameRelative(name.text)) {
if (!ts.isExternalModuleNameRelative(name.text)) {
const packageName = getPackageName(name.text);
if (builtins.indexOf(packageName) === -1 && !hasDependency(packageName)) {
ctx.addFailureAtNode(name, Rule.FAILURE_STRING_FACTORY(packageName));
Expand Down
3 changes: 1 addition & 2 deletions src/rules/noSubmoduleImportsRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ export class Rule extends Lint.Rules.AbstractRule {

function walk(ctx: Lint.WalkContext<string[]>) {
for (const name of findImports(ctx.sourceFile, ImportKind.All)) {
// TODO remove assertion on upgrade to typescript@2.5.2
if (!(ts as any as {isExternalModuleNameRelative(m: string): boolean}).isExternalModuleNameRelative(name.text) &&
if (!ts.isExternalModuleNameRelative(name.text) &&
isSubmodulePath(name.text) &&
!isWhitelisted(name.text, ctx.options)) {
ctx.addFailureAtNode(name, Rule.FAILURE_STRING);
Expand Down
5 changes: 2 additions & 3 deletions src/rules/noUnnecessaryQualifierRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,8 @@ function walk(ctx: Lint.WalkContext<void>, checker: ts.TypeChecker): void {
}

function symbolsAreEqual(accessed: ts.Symbol, inScope: ts.Symbol): boolean {
// TODO remove type assertion on update to typescript@2.6.0
if ((checker as any as {getExportSymbolOfSymbol(s: ts.Symbol): ts.Symbol}).getExportSymbolOfSymbol !== undefined) {
inScope = (checker as any as {getExportSymbolOfSymbol(s: ts.Symbol): ts.Symbol}).getExportSymbolOfSymbol(inScope);
if (checker.getExportSymbolOfSymbol !== undefined) {
inScope = checker.getExportSymbolOfSymbol(inScope);
return accessed === inScope;
}
return accessed === inScope ||
Expand Down
2 changes: 1 addition & 1 deletion src/rules/orderedImportsRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ const TRANSFORMS = new Map<string, Transform>([
["lowercase-last", (x) => x],
["full", (x) => x],
["basename", (x) => {
if (!(ts as any as {isExternalModuleNameRelative(m: string): boolean}).isExternalModuleNameRelative(x)) {
if (!ts.isExternalModuleNameRelative(x)) {
return x;
}

Expand Down
1 change: 1 addition & 0 deletions src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"noUnusedParameters": true,
"noUnusedLocals": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"importHelpers": true,
"declaration": true,
"sourceMap": false,
Expand Down
13 changes: 11 additions & 2 deletions test/executable/executableTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ describe("Executable", function(this: Mocha.ISuiteCallbackContext) {
});
});

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

it("doesn't lint external dependencies with 'allowJs'", (done) => {
execCli(
[ "-p", "test/files/allow-js-exclude-node-modules/tsconfig.json"],
(err) => {
assert.isNull(err, "process should exit without error");
done();
});
});

it("works with '--exclude'", (done) => {
execCli(
[ "-p", "test/files/tsconfig-allow-js/tsconfig.json", "-e", "'test/files/tsconfig-allow-js/testfile.test.js'"],
Expand Down Expand Up @@ -566,7 +575,7 @@ function execCli(args: string[], options: cp.ExecFileOptions | ExecFileCallback,
});
}

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

Expand Down
2 changes: 2 additions & 0 deletions test/files/allow-js-exclude-node-modules/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import * as dependency from 'dependency';
console.log(dependency);
6 changes: 6 additions & 0 deletions test/files/allow-js-exclude-node-modules/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"allowJs": true,
"maxNodeModuleJsDepth": 1
}
}
12 changes: 12 additions & 0 deletions test/files/allow-js-exclude-node-modules/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"rules": {
"semicolon": [
true, "always"
]
},
"jsRules": {
"semicolon": [
true, "always"
]
}
}
2 changes: 1 addition & 1 deletion test/rules/deprecation/test.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const A = 1, B = 2;

A + B;
~ [err % ('A')]
#if typescript < 2.7.0
#if typescript < 2.6.1
~ [err % ('B')]
#endif

Expand Down
1 change: 1 addition & 0 deletions test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"noUnusedParameters": true,
"noUnusedLocals": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"sourceMap": true,
"target": "es5",
"lib": ["es6"],
Expand Down
10 changes: 7 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1566,6 +1566,10 @@ tslib@^1.7.1:
version "1.7.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.7.1.tgz#bc8004164691923a79fe8378bbeb3da2017538ec"

tslib@^1.8.0:
version "1.8.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.8.0.tgz#dc604ebad64bcbf696d613da6c954aa0e7ea1eb6"

"tslint-test-config-non-relative@file:test/external/tslint-test-config-non-relative":
version "0.0.1"

Expand Down Expand Up @@ -1604,9 +1608,9 @@ type-detect@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-1.0.0.tgz#762217cc06db258ec48908a1298e8b95121e8ea2"

typescript@~2.5.1:
version "2.5.1"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.5.1.tgz#ce7cc93ada3de19475cc9d17e3adea7aee1832aa"
typescript@~2.6.1:
version "2.6.1"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.6.1.tgz#ef39cdea27abac0b500242d6726ab90e0c846631"

uglify-js@^2.6:
version "2.8.28"
Expand Down