Skip to content

Commit 84026c8

Browse files
committed
Remove typescript usage in normalized message
1 parent d6c475b commit 84026c8

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

src/IncrementalChecker.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,12 @@ export class IncrementalChecker {
254254

255255
// normalize and deduplicate diagnostics
256256
return NormalizedMessage.deduplicate(
257-
diagnostics.map(NormalizedMessage.createFromDiagnostic)
257+
diagnostics.map(d =>
258+
NormalizedMessage.createFromDiagnostic(
259+
ts.flattenDiagnosticMessageText,
260+
d
261+
)
262+
)
258263
);
259264
}
260265

src/NormalizedMessage.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import {
2-
Diagnostic,
3-
DiagnosticCategory,
4-
flattenDiagnosticMessageText
5-
} from 'typescript';
1+
import { Diagnostic, DiagnosticMessageChain } from 'typescript';
62
import { RuleFailure } from 'tslint';
73

84
type ErrorType = 'diagnostic' | 'lint';
@@ -45,7 +41,13 @@ export class NormalizedMessage {
4541
}
4642

4743
// message types
48-
static createFromDiagnostic(diagnostic: Diagnostic) {
44+
static createFromDiagnostic(
45+
flattenDiagnosticMessageText: (
46+
messageText: string | DiagnosticMessageChain | undefined,
47+
newLine: string
48+
) => string,
49+
diagnostic: Diagnostic
50+
) {
4951
let file: string;
5052
let line: number;
5153
let character: number;
@@ -61,9 +63,10 @@ export class NormalizedMessage {
6163
return new NormalizedMessage({
6264
type: NormalizedMessage.TYPE_DIAGNOSTIC,
6365
code: diagnostic.code,
64-
severity: DiagnosticCategory[
65-
diagnostic.category
66-
].toLowerCase() as Severity,
66+
// TODO: Keep in sync with TypeScript's DiagnosticCategory.Error or pass in
67+
severity: (diagnostic.category.toString() === '1'
68+
? NormalizedMessage.SEVERITY_ERROR
69+
: NormalizedMessage.SEVERITY_WARNING) as Severity,
6770
content: flattenDiagnosticMessageText(diagnostic.messageText, '\n'),
6871
file,
6972
line,

0 commit comments

Comments
 (0)