summaryrefslogtreecommitdiff
path: root/cli/js/diagnostics_util.ts
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2020-07-14 15:24:17 -0400
committerGitHub <noreply@github.com>2020-07-14 15:24:17 -0400
commitcde4dbb35132848ffece59ef9cfaccff32347124 (patch)
treecc7830968c6decde704c8cfb83c9185193dc698f /cli/js/diagnostics_util.ts
parent9eca71caa1674c31f9cc5d4e86c03f10b59e0a00 (diff)
Use dprint for internal formatting (#6682)
Diffstat (limited to 'cli/js/diagnostics_util.ts')
-rw-r--r--cli/js/diagnostics_util.ts46
1 files changed, 24 insertions, 22 deletions
diff --git a/cli/js/diagnostics_util.ts b/cli/js/diagnostics_util.ts
index 3e0bfde27..fc2684baf 100644
--- a/cli/js/diagnostics_util.ts
+++ b/cli/js/diagnostics_util.ts
@@ -91,7 +91,7 @@ function transformMessageText(messageText: string, code: number): string {
const suggestion = messageText.match(suggestionMessagePattern);
const replacedMessageText = messageText.replace(
suggestionMessagePattern,
- ""
+ "",
);
if (suggestion && unstableDenoGlobalProperties.includes(property)) {
const suggestedProperty = suggestion[1];
@@ -113,7 +113,7 @@ interface SourceInformation {
}
function fromDiagnosticCategory(
- category: ts.DiagnosticCategory
+ category: ts.DiagnosticCategory,
): DiagnosticCategory {
switch (category) {
case ts.DiagnosticCategory.Error:
@@ -126,7 +126,9 @@ function fromDiagnosticCategory(
return DiagnosticCategory.Warning;
default:
throw new Error(
- `Unexpected DiagnosticCategory: "${category}"/"${ts.DiagnosticCategory[category]}"`
+ `Unexpected DiagnosticCategory: "${category}"/"${
+ ts.DiagnosticCategory[category]
+ }"`,
);
}
}
@@ -134,7 +136,7 @@ function fromDiagnosticCategory(
function getSourceInformation(
sourceFile: ts.SourceFile,
start: number,
- length: number
+ length: number,
): SourceInformation {
const scriptResourceName = sourceFile.fileName;
const {
@@ -142,16 +144,16 @@ function getSourceInformation(
character: startColumn,
} = sourceFile.getLineAndCharacterOfPosition(start);
const endPosition = sourceFile.getLineAndCharacterOfPosition(start + length);
- const endColumn =
- lineNumber === endPosition.line ? endPosition.character : startColumn;
+ const endColumn = lineNumber === endPosition.line
+ ? endPosition.character
+ : startColumn;
const lastLineInFile = sourceFile.getLineAndCharacterOfPosition(
- sourceFile.text.length
+ sourceFile.text.length,
).line;
const lineStart = sourceFile.getPositionOfLineAndCharacter(lineNumber, 0);
- const lineEnd =
- lineNumber < lastLineInFile
- ? sourceFile.getPositionOfLineAndCharacter(lineNumber + 1, 0)
- : sourceFile.text.length;
+ const lineEnd = lineNumber < lastLineInFile
+ ? sourceFile.getPositionOfLineAndCharacter(lineNumber + 1, 0)
+ : sourceFile.text.length;
const sourceLine = sourceFile.text
.slice(lineStart, lineEnd)
.replace(/\s+$/g, "")
@@ -166,7 +168,7 @@ function getSourceInformation(
}
function fromDiagnosticMessageChain(
- messageChain: ts.DiagnosticMessageChain[] | undefined
+ messageChain: ts.DiagnosticMessageChain[] | undefined,
): DiagnosticMessageChain[] | undefined {
if (!messageChain) {
return undefined;
@@ -184,7 +186,7 @@ function fromDiagnosticMessageChain(
}
function parseDiagnostic(
- item: ts.Diagnostic | ts.DiagnosticRelatedInformation
+ item: ts.Diagnostic | ts.DiagnosticRelatedInformation,
): DiagnosticItem {
const {
messageText,
@@ -194,12 +196,12 @@ function parseDiagnostic(
start: startPosition,
length,
} = item;
- const sourceInfo =
- file && startPosition && length
- ? getSourceInformation(file, startPosition, length)
- : undefined;
- const endPosition =
- startPosition && length ? startPosition + length : undefined;
+ const sourceInfo = file && startPosition && length
+ ? getSourceInformation(file, startPosition, length)
+ : undefined;
+ const endPosition = startPosition && length
+ ? startPosition + length
+ : undefined;
const category = fromDiagnosticCategory(sourceCategory);
let message: string;
@@ -224,7 +226,7 @@ function parseDiagnostic(
}
function parseRelatedInformation(
- relatedInformation: readonly ts.DiagnosticRelatedInformation[]
+ relatedInformation: readonly ts.DiagnosticRelatedInformation[],
): DiagnosticItem[] {
const result: DiagnosticItem[] = [];
for (const item of relatedInformation) {
@@ -234,14 +236,14 @@ function parseRelatedInformation(
}
export function fromTypeScriptDiagnostic(
- diagnostics: readonly ts.Diagnostic[]
+ diagnostics: readonly ts.Diagnostic[],
): Diagnostic {
const items: DiagnosticItem[] = [];
for (const sourceDiagnostic of diagnostics) {
const item: DiagnosticItem = parseDiagnostic(sourceDiagnostic);
if (sourceDiagnostic.relatedInformation) {
item.relatedInformation = parseRelatedInformation(
- sourceDiagnostic.relatedInformation
+ sourceDiagnostic.relatedInformation,
);
}
items.push(item);