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

Ensure compatibility with older typescript in CI #2893

Merged
merged 4 commits into from
Jun 6, 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 circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dependencies:
- yarn
test:
override:
- case $CIRCLE_NODE_INDEX in [0-2]) yarn verify ;; 3) npm run clean && yarn compile && yarn add typescript@next && yarn test ;; esac:
- case $CIRCLE_NODE_INDEX in 0) npm run clean && yarn compile && yarn add typescript@2.1 && yarn test ;; 1) npm run clean && yarn compile && yarn add typescript@2.2 && yarn test ;; 2) yarn verify ;; 3) npm run clean && yarn compile && yarn add typescript@next && yarn test ;; esac:
parallel: true
deployment:
npm-latest:
Expand Down
6 changes: 6 additions & 0 deletions src/language/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,3 +436,9 @@ export function isNegativeNumberLiteral(node: ts.Node): node is ts.PrefixUnaryEx
node.operator === ts.SyntaxKind.MinusToken &&
node.operand.kind === ts.SyntaxKind.NumericLiteral;
}

/** Wrapper for compatibility with typescript@<2.3.1 */
export function isWhiteSpace(ch: number): boolean {
// tslint:disable-next-line
return (ts.isWhiteSpaceLike || (ts as any).isWhiteSpace)(ch);
}
43 changes: 42 additions & 1 deletion src/rules/deprecationRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { isIdentifier } from "tsutils";
import { getDeclarationOfBindingElement, isBindingElement, isIdentifier, isVariableDeclaration, isVariableDeclarationList } from "tsutils";
import * as ts from "typescript";
import * as Lint from "../index";

Expand Down Expand Up @@ -105,11 +105,52 @@ function getDeprecation(node: ts.Identifier, tc: ts.TypeChecker): string | undef
symbol = tc.getAliasedSymbol(symbol);
}
if (symbol !== undefined) {
return getDeprecationValue(symbol);
}
return undefined;
}

function getDeprecationValue(symbol: ts.Symbol): string | undefined {
if (symbol.getJsDocTags !== undefined) {
for (const tag of symbol.getJsDocTags()) {
if (tag.name === "deprecated") {
return tag.text;
}
}
return undefined;
}
// for compatibility with typescript@<2.3.0
return getDeprecationFromDeclarations(symbol.declarations);
}

function getDeprecationFromDeclarations(declarations?: ts.Declaration[]): string | undefined {
if (declarations === undefined) {
return undefined;
}
let declaration: ts.Node;
for (declaration of declarations) {
if (isBindingElement(declaration)) {
declaration = getDeclarationOfBindingElement(declaration);
}
if (isVariableDeclaration(declaration)) {
declaration = declaration.parent!;
}
if (isVariableDeclarationList(declaration)) {
declaration = declaration.parent!;
}
for (const child of declaration.getChildren()) {
if (child.kind !== ts.SyntaxKind.JSDocComment) {
break;
}
if ((child as ts.JSDoc).tags === undefined) {
continue;
}
for (const tag of (child as ts.JSDoc).tags!) {
if (tag.tagName.text === "deprecated") {
return tag.comment === undefined ? "" : tag.comment;
}
}
}
}
return undefined;
}
2 changes: 1 addition & 1 deletion src/rules/spaceBeforeFunctionParenRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function walk(ctx: Lint.WalkContext<Options>): void {
// openParen may be missing for an async arrow function `async x => ...`.
if (openParen === undefined) { return; }

const hasSpace = ts.isWhiteSpaceLike(sourceFile.text.charCodeAt(openParen.end - 2));
const hasSpace = Lint.isWhiteSpace(sourceFile.text.charCodeAt(openParen.end - 2));

if (hasSpace && option === "never") {
const pos = openParen.getStart() - 1;
Expand Down
2 changes: 1 addition & 1 deletion src/rules/whitespaceRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ function walk(ctx: Lint.WalkContext<Options>) {
}

function checkForTrailingWhitespace(position: number): void {
if (position !== sourceFile.end && !ts.isWhiteSpaceLike(sourceFile.text.charCodeAt(position))) {
if (position !== sourceFile.end && !Lint.isWhiteSpace(sourceFile.text.charCodeAt(position))) {
addMissingWhitespaceErrorAt(position);
}
}
Expand Down
3 changes: 3 additions & 0 deletions test/rules/return-undefined/test.ts.lint
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
class Promise<T> {
then(): Promise<T>;
}
function valueWrong(): number | undefined {
return;
~~~~~~~ [UNDEFINED]
Expand Down