Skip to content

Commit 4e8c6f9

Browse files
prevostcjohnnyreilly
authored andcommitted
feat: apply clickable filename format to codeframeFormatter (#320)
When an error message is shown on an IDE console, most IDEs will allow you to ctrl+click the file name to go directly to the proper file, line and character. In order for this to work properly, the error filename, line and character must have a specific format: "filename.js(line,col)". The codeFormatter already follows this format, this commit applies this format to the codeframeFormatter.
1 parent 39fbffb commit 4e8c6f9

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/formatter/codeframeFormatter.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ export function createCodeframeFormatter(options: any) {
2424

2525
if (message.code === NormalizedMessage.ERROR_CODE_INTERNAL) {
2626
return (
27-
messageColor(`INTERNAL ${message.severity.toUpperCase()}: `) +
27+
messageColor(
28+
`INTERNAL ${message.severity.toUpperCase()}(${message.line},${
29+
message.character
30+
}) `
31+
) +
2832
message.content +
2933
(message.stack
3034
? os.EOL + 'stack trace:' + os.EOL + colors.gray(message.stack)
@@ -53,7 +57,11 @@ export function createCodeframeFormatter(options: any) {
5357
}
5458

5559
return (
56-
messageColor(message.severity.toUpperCase() + ' in ' + message.file) +
60+
messageColor(
61+
message.severity.toUpperCase() +
62+
' in ' +
63+
`${message.file}(${message.line},${message.character}):`
64+
) +
5765
os.EOL +
5866
positionColor(message.line + ':' + message.character) +
5967
' ' +

test/unit/codeframeFormatter.spec.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe('[UNIT] formatter/codeframeFormatter', () => {
4242
var formattedMessage = formatter(message, false);
4343

4444
expect(formattedMessage).toBe(
45-
'ERROR in some/file.ts' +
45+
'ERROR in some/file.ts(1,7):' +
4646
os.EOL +
4747
'1:7 Some diagnostic content' +
4848
os.EOL +
@@ -71,7 +71,7 @@ describe('[UNIT] formatter/codeframeFormatter', () => {
7171
var formattedMessage = formatter(message, false);
7272

7373
expect(formattedMessage).toBe(
74-
'WARNING in some/file.ts' +
74+
'WARNING in some/file.ts(2,11):' +
7575
os.EOL +
7676
'2:11 Some lint content' +
7777
os.EOL +
@@ -102,7 +102,9 @@ describe('[UNIT] formatter/codeframeFormatter', () => {
102102
var formattedMessage = formatter(message, false);
103103

104104
expect(formattedMessage).toBe(
105-
'WARNING in some/unknown-file.ts' + os.EOL + '2:11 Some lint content'
105+
'WARNING in some/unknown-file.ts(2,11):' +
106+
os.EOL +
107+
'2:11 Some lint content'
106108
);
107109
});
108110
});

0 commit comments

Comments
 (0)