From 77b24aec839501c709d3c37be6626e399cb7fd97 Mon Sep 17 00:00:00 2001 From: Andy Date: Mon, 6 Nov 2017 18:38:03 -0800 Subject: [PATCH] Apply 'unified-signatures' tslint rule (#19738) * Apply 'unified-signatures' tslint rule * Fix new failure --- src/compiler/factory.ts | 7 +++--- src/harness/fourslash.ts | 23 ++++++------------- src/services/types.ts | 2 ++ .../reference/api/tsserverlibrary.d.ts | 5 ++-- tests/baselines/reference/api/typescript.d.ts | 5 ++-- tslint.json | 1 - 6 files changed, 17 insertions(+), 26 deletions(-) diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index c9e0fec5927..6a56b6da049 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -70,11 +70,10 @@ namespace ts { // Literals - export function createLiteral(value: string): StringLiteral; + /** If a node is passed, creates a string literal whose source text is read from a source node during emit. */ + export function createLiteral(value: string | StringLiteral | NumericLiteral | Identifier): StringLiteral; export function createLiteral(value: number): NumericLiteral; export function createLiteral(value: boolean): BooleanLiteral; - /** Create a string literal whose source text is read from a source node during emit. */ - export function createLiteral(sourceNode: StringLiteral | NumericLiteral | Identifier): StringLiteral; export function createLiteral(value: string | number | boolean): PrimaryExpression; export function createLiteral(value: string | number | boolean | StringLiteral | NumericLiteral | Identifier): PrimaryExpression { if (typeof value === "number") { @@ -113,6 +112,7 @@ namespace ts { export function createIdentifier(text: string): Identifier; /* @internal */ + // tslint:disable-next-line unified-signatures export function createIdentifier(text: string, typeArguments: ReadonlyArray): Identifier; export function createIdentifier(text: string, typeArguments?: ReadonlyArray): Identifier { const node = createSynthesizedNode(SyntaxKind.Identifier); @@ -166,6 +166,7 @@ namespace ts { /** Create a unique name generated for a node. */ export function getGeneratedNameForNode(node: Node): Identifier; + // tslint:disable-next-line unified-signatures /*@internal*/ export function getGeneratedNameForNode(node: Node, shouldSkipNameGenerationScope?: boolean): Identifier; export function getGeneratedNameForNode(node: Node, shouldSkipNameGenerationScope?: boolean): Identifier { const name = createIdentifier(""); diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 85011525d52..91e22689fcf 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -483,9 +483,7 @@ namespace FourSlash { } // Opens a file given its 0-based index or fileName - public openFile(index: number, content?: string, scriptKindName?: string): void; - public openFile(name: string, content?: string, scriptKindName?: string): void; - public openFile(indexOrName: any, content?: string, scriptKindName?: string) { + public openFile(indexOrName: number | string, content?: string, scriptKindName?: string): void { const fileToOpen: FourSlashFile = this.findFile(indexOrName); fileToOpen.fileName = ts.normalizeSlashes(fileToOpen.fileName); this.activeFile = fileToOpen; @@ -3093,7 +3091,7 @@ Actual: ${stringify(fullActual)}`); this.raiseError(`Expected "${stringify({ entryId, text, documentation, kind })}" to be in list [${itemsString}]`); } - private findFile(indexOrName: any) { + private findFile(indexOrName: string | number) { let result: FourSlashFile; if (typeof indexOrName === "number") { const index = indexOrName; @@ -3745,9 +3743,7 @@ namespace FourSlashInterface { this.state.goToImplementation(); } - public position(position: number, fileIndex?: number): void; - public position(position: number, fileName?: string): void; - public position(position: number, fileNameOrIndex?: any): void { + public position(position: number, fileNameOrIndex?: string | number): void { if (fileNameOrIndex !== undefined) { this.file(fileNameOrIndex); } @@ -3757,9 +3753,7 @@ namespace FourSlashInterface { // Opens a file, given either its index as it // appears in the test source, or its filename // as specified in the test metadata - public file(index: number, content?: string, scriptKindName?: string): void; - public file(name: string, content?: string, scriptKindName?: string): void; - public file(indexOrName: any, content?: string, scriptKindName?: string): void { + public file(indexOrName: number | string, content?: string, scriptKindName?: string): void { this.state.openFile(indexOrName, content, scriptKindName); } @@ -3966,17 +3960,14 @@ namespace FourSlashInterface { this.state.verifyGoToDefinitionIs(endMarkers); } - public goToDefinition(startMarkerName: string | string[], endMarkerName: string | string[]): void; - public goToDefinition(startMarkerName: string | string[], endMarkerName: string | string[], range: FourSlash.Range): void; - public goToDefinition(startsAndEnds: [string | string[], string | string[]][]): void; - public goToDefinition(startsAndEnds: { [startMarkerName: string]: string | string[] }): void; + public goToDefinition(startMarkerName: string | string[], endMarkerName: string | string[], range?: FourSlash.Range): void; + public goToDefinition(startsAndEnds: [string | string[], string | string[]][] | { [startMarkerName: string]: string | string[] }): void; public goToDefinition(arg0: any, endMarkerName?: string | string[]) { this.state.verifyGoToDefinition(arg0, endMarkerName); } public goToType(startMarkerName: string | string[], endMarkerName: string | string[]): void; - public goToType(startsAndEnds: [string | string[], string | string[]][]): void; - public goToType(startsAndEnds: { [startMarkerName: string]: string | string[] }): void; + public goToType(startsAndEnds: [string | string[], string | string[]][] | { [startMarkerName: string]: string | string[] }): void; public goToType(arg0: any, endMarkerName?: string | string[]) { this.state.verifyGoToType(arg0, endMarkerName); } diff --git a/src/services/types.ts b/src/services/types.ts index e93ae9686d7..a9244982fbb 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -5,9 +5,11 @@ namespace ts { getChildAt(index: number, sourceFile?: SourceFile): Node; getChildren(sourceFile?: SourceFile): Node[]; /* @internal */ + // tslint:disable-next-line unified-signatures getChildren(sourceFile?: SourceFileLike): Node[]; getStart(sourceFile?: SourceFile, includeJsDocComment?: boolean): number; /* @internal */ + // tslint:disable-next-line unified-signatures getStart(sourceFile?: SourceFileLike, includeJsDocComment?: boolean): number; getFullStart(): number; getEnd(): number; diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 415565a6fa1..9b2270d29e5 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -3271,11 +3271,10 @@ declare namespace ts { } declare namespace ts { function createNodeArray(elements?: ReadonlyArray, hasTrailingComma?: boolean): NodeArray; - function createLiteral(value: string): StringLiteral; + /** If a node is passed, creates a string literal whose source text is read from a source node during emit. */ + function createLiteral(value: string | StringLiteral | NumericLiteral | Identifier): StringLiteral; function createLiteral(value: number): NumericLiteral; function createLiteral(value: boolean): BooleanLiteral; - /** Create a string literal whose source text is read from a source node during emit. */ - function createLiteral(sourceNode: StringLiteral | NumericLiteral | Identifier): StringLiteral; function createLiteral(value: string | number | boolean): PrimaryExpression; function createNumericLiteral(value: string): NumericLiteral; function createIdentifier(text: string): Identifier; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index fd58e72181a..6ef259ddc8f 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -3218,11 +3218,10 @@ declare namespace ts { } declare namespace ts { function createNodeArray(elements?: ReadonlyArray, hasTrailingComma?: boolean): NodeArray; - function createLiteral(value: string): StringLiteral; + /** If a node is passed, creates a string literal whose source text is read from a source node during emit. */ + function createLiteral(value: string | StringLiteral | NumericLiteral | Identifier): StringLiteral; function createLiteral(value: number): NumericLiteral; function createLiteral(value: boolean): BooleanLiteral; - /** Create a string literal whose source text is read from a source node during emit. */ - function createLiteral(sourceNode: StringLiteral | NumericLiteral | Identifier): StringLiteral; function createLiteral(value: string | number | boolean): PrimaryExpression; function createNumericLiteral(value: string): NumericLiteral; function createIdentifier(text: string): Identifier; diff --git a/tslint.json b/tslint.json index 2d7c702b8aa..658beb14d16 100644 --- a/tslint.json +++ b/tslint.json @@ -100,7 +100,6 @@ "radix": false, "space-before-function-paren": false, "trailing-comma": false, - "unified-signatures": false, // These should be done automatically by a formatter. https://github.com/Microsoft/TypeScript/issues/18340 "align": false,