From ff9c7e498e69ed675e6670eaebbd387477d758a3 Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Tue, 20 Aug 2019 14:32:43 -0400 Subject: [PATCH 1/2] Prepare release v5.19.0 --- CHANGELOG.md | 31 +++++++++++++++++++++++++++++++ package.json | 2 +- src/linter.ts | 2 +- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2042217e9d8..f542dcc4359 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,36 @@ # Change Log +## v5.19.0 + +- [bugfix] relax [`promise-function-async`](https://palantir.github.io/tslint/rules/promise-function-async/) for short parenthesized arrow functions (#4765) +- [bugfix] fix [`no-async-without-await`](https://palantir.github.io/tslint/rules/no-async-without-await/) false positive for abstract methods (#4782) +- [bugfix] fix [`strict-comparison`](https://palantir.github.io/tslint/rules/strict-comparison/) false positive for `null` and `undefined` literals (#4786) +- [bugfix] improve [`no-angle-bracket-type-assertion`](https://palantir.github.io/tslint/rules/no-angle-bracket-type-assertion/) autofix semantics with more parentheses (#4823) +- [enhancement] add BigInt support to [`restrict-plus-operands`](https://palantir.github.io/tslint/rules/restrict-plus-operands/) rule (#4814) +- [enhancement] [`await-promise`](https://palantir.github.io/tslint/rules/await-promise/) now supports new TypeScript 3.6 AST API symbols for async iterators (#4800) +- [new-rule-option] `check-strings` and `check-regex` options for [`max-line-length`](https://palantir.github.io/tslint/rules/max-line-length/) rule (#4798) +- [new-rule-option] `variable-declaration-ignore-function` option for [`typedef`](https://palantir.github.io/tslint/rules/typedef/) rule (#4769) +- [new-rule-option] `ignore-blank-lines` option for [`object-literal-sort-keys`](https://palantir.github.io/tslint/rules/object-literal-sort-keys/) rule (#4808) +- [new-rule] [`no-for-in`](https://palantir.github.io/tslint/rules/no-for-in/) (#4747) +- [new-rule] [`no-invalid-void`](https://palantir.github.io/tslint/rules/no-invalid-void/) (#4736) +- [new-rule] [`strict-string-expressions`](https://palantir.github.io/tslint/rules/strict-string-expressions/) reports errors on type coercions found in string expressions (#4807) +- [new-rule] ['no-promise-as-boolean'](https://palantir.github.io/tslint/rules/no-promise-as-boolean/) (#4790) +- [docs] link to OSS fellowship medium post in README (#4821) + +Thanks to our contributors! + +- Josh Pike +- Tanmoy Bhowmik +- Michael Withagen +- Evgeniy Timokhov +- Vitalij Krotov +- Josh Goldberg +- Veda +- Guido +- Robert Fink +- Max Sysoev + + ## v5.18.0 - [feature] New `--print-config` CLI flag (#4744) diff --git a/package.json b/package.json index 2f6235496a3..0ee00f47bb7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tslint", - "version": "5.18.0", + "version": "5.19.0", "description": "An extensible static analysis linter for the TypeScript language", "bin": { "tslint": "./bin/tslint" diff --git a/src/linter.ts b/src/linter.ts index 5a86ae92772..1d7bc285469 100644 --- a/src/linter.ts +++ b/src/linter.ts @@ -42,7 +42,7 @@ import { arrayify, dedent, flatMap, mapDefined } from "./utils"; * Linter that can lint multiple files in consecutive runs. */ export class Linter { - public static VERSION = "5.18.0"; + public static VERSION = "5.19.0"; public static findConfiguration = findConfiguration; public static findConfigurationPath = findConfigurationPath; From c5dcc67500785fcfb8da6a3874e20e5034fb132e Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Tue, 20 Aug 2019 15:32:10 -0400 Subject: [PATCH 2/2] Fix testNext failures for return-undefined rule --- src/rules/returnUndefinedRule.ts | 29 +++++++++++-------- .../{ => default}/test.ts.lint | 4 --- .../{ => default}/tsconfig.json | 0 .../{ => default}/tslint.json | 0 .../return-undefined/pre-ts-3.6/test.ts.lint | 9 ++++++ .../return-undefined/pre-ts-3.6/tsconfig.json | 5 ++++ .../return-undefined/pre-ts-3.6/tslint.json | 5 ++++ 7 files changed, 36 insertions(+), 16 deletions(-) rename test/rules/return-undefined/{ => default}/test.ts.lint (94%) rename test/rules/return-undefined/{ => default}/tsconfig.json (100%) rename test/rules/return-undefined/{ => default}/tslint.json (100%) create mode 100644 test/rules/return-undefined/pre-ts-3.6/test.ts.lint create mode 100644 test/rules/return-undefined/pre-ts-3.6/tsconfig.json create mode 100644 test/rules/return-undefined/pre-ts-3.6/tslint.json diff --git a/src/rules/returnUndefinedRule.ts b/src/rules/returnUndefinedRule.ts index 5e8ff40c6fa..5c6cb98318a 100644 --- a/src/rules/returnUndefinedRule.ts +++ b/src/rules/returnUndefinedRule.ts @@ -61,7 +61,7 @@ function walk(ctx: Lint.WalkContext, checker: ts.TypeChecker) { }); function check(node: ts.ReturnStatement): void { - const actualReturnKind = returnKindFromReturn(node); + const actualReturnKind = getReturnKindFromReturnStatement(node); if (actualReturnKind === undefined) { return; } @@ -72,7 +72,7 @@ function walk(ctx: Lint.WalkContext, checker: ts.TypeChecker) { return; } - const returnKindFromType = getReturnKind(functionReturningFrom, checker); + const returnKindFromType = getReturnKindFromFunction(functionReturningFrom, checker); if (returnKindFromType !== undefined && returnKindFromType !== actualReturnKind) { ctx.addFailureAtNode( node, @@ -84,7 +84,7 @@ function walk(ctx: Lint.WalkContext, checker: ts.TypeChecker) { } } -function returnKindFromReturn(node: ts.ReturnStatement): ReturnKind | undefined { +function getReturnKindFromReturnStatement(node: ts.ReturnStatement): ReturnKind | undefined { if (node.expression === undefined) { return ReturnKind.Void; } else if (isIdentifier(node.expression) && node.expression.text === "undefined") { @@ -94,9 +94,9 @@ function returnKindFromReturn(node: ts.ReturnStatement): ReturnKind | undefined } } -enum ReturnKind { - Void, - Value, +const enum ReturnKind { + Void = "void", + Value = "value", } type FunctionLike = @@ -108,7 +108,10 @@ type FunctionLike = | ts.GetAccessorDeclaration | ts.SetAccessorDeclaration; -function getReturnKind(node: FunctionLike, checker: ts.TypeChecker): ReturnKind | undefined { +function getReturnKindFromFunction( + node: FunctionLike, + checker: ts.TypeChecker, +): ReturnKind | undefined { switch (node.kind) { case ts.SyntaxKind.Constructor: case ts.SyntaxKind.SetAccessor: @@ -134,13 +137,15 @@ function getReturnKind(node: FunctionLike, checker: ts.TypeChecker): ReturnKind if (returnType === undefined || isTypeFlagSet(returnType, ts.TypeFlags.Any)) { return undefined; } - if ( - (hasModifier(node.modifiers, ts.SyntaxKind.AsyncKeyword) - ? isEffectivelyVoidPromise - : isEffectivelyVoid)(returnType) - ) { + + const effectivelyVoidChecker = hasModifier(node.modifiers, ts.SyntaxKind.AsyncKeyword) + ? isEffectivelyVoidPromise + : isEffectivelyVoid; + + if (effectivelyVoidChecker(returnType)) { return ReturnKind.Void; } + return ReturnKind.Value; } diff --git a/test/rules/return-undefined/test.ts.lint b/test/rules/return-undefined/default/test.ts.lint similarity index 94% rename from test/rules/return-undefined/test.ts.lint rename to test/rules/return-undefined/default/test.ts.lint index b646595ecab..e672954f38d 100644 --- a/test/rules/return-undefined/test.ts.lint +++ b/test/rules/return-undefined/default/test.ts.lint @@ -66,10 +66,6 @@ async function promiseValue(): Promise { ~~~~~~~ [UNDEFINED] } -declare function f(action: () => T | undefined): void; -f(() => { return undefined; }); - ~~~~~~~~~~~~~~~~~ [VOID] - declare function test(cb: () => Promise | void): void; test(async () => { diff --git a/test/rules/return-undefined/tsconfig.json b/test/rules/return-undefined/default/tsconfig.json similarity index 100% rename from test/rules/return-undefined/tsconfig.json rename to test/rules/return-undefined/default/tsconfig.json diff --git a/test/rules/return-undefined/tslint.json b/test/rules/return-undefined/default/tslint.json similarity index 100% rename from test/rules/return-undefined/tslint.json rename to test/rules/return-undefined/default/tslint.json diff --git a/test/rules/return-undefined/pre-ts-3.6/test.ts.lint b/test/rules/return-undefined/pre-ts-3.6/test.ts.lint new file mode 100644 index 00000000000..b58b43f5719 --- /dev/null +++ b/test/rules/return-undefined/pre-ts-3.6/test.ts.lint @@ -0,0 +1,9 @@ +[typescript]: <= 3.6.0 + +// in TS 3.6 and later, the type checker infers this anonymous function as returning 'unknown' +declare function f(action: () => T | undefined): void; +f(() => { return undefined; }); + ~~~~~~~~~~~~~~~~~ [VOID] + +[VOID]: `void` function should use `return;`, not `return undefined;`. +[UNDEFINED]: Value-returning function should use `return undefined;`, not just `return;`. diff --git a/test/rules/return-undefined/pre-ts-3.6/tsconfig.json b/test/rules/return-undefined/pre-ts-3.6/tsconfig.json new file mode 100644 index 00000000000..1cc3bc85ee9 --- /dev/null +++ b/test/rules/return-undefined/pre-ts-3.6/tsconfig.json @@ -0,0 +1,5 @@ +{ + "compilerOptions": { + "strictNullChecks": true + } +} \ No newline at end of file diff --git a/test/rules/return-undefined/pre-ts-3.6/tslint.json b/test/rules/return-undefined/pre-ts-3.6/tslint.json new file mode 100644 index 00000000000..475b28dc589 --- /dev/null +++ b/test/rules/return-undefined/pre-ts-3.6/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "return-undefined": true + } +}