Skip to content

Commit 46071b5

Browse files
Zarellumaxis
andauthored
Fix TypeScript error line/column (#125)
* Fix TypeScript error line/column * Adopt official pattern from VS Code * Minor cleanup * Add tests for tsc problem matcher Co-authored-by: Lukas Spieß <[email protected]>
1 parent 05f0551 commit 46071b5

File tree

3 files changed

+50
-11
lines changed

3 files changed

+50
-11
lines changed

.github/tsc.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
"owner": "tsc",
55
"pattern": [
66
{
7-
"regexp": "^(?:\\s+\\d+\\>)?([^\\s].*)\\((\\d+|\\d+,\\d+|\\d+,\\d+,\\d+,\\d+)\\)\\s*:\\s+(error|warning|info)\\s+(\\w{1,2}\\d+)\\s*:\\s*(.*)$",
7+
"regexp": "^([^\\s].*)[\\(:](\\d+)[,:](\\d+)(?:\\):\\s+|\\s+-\\s+)(error|warning|info)\\s+TS(\\d+)\\s*:\\s*(.*)$",
88
"file": 1,
9-
"location": 2,
10-
"severity": 3,
11-
"code": 4,
12-
"message": 5
9+
"line": 2,
10+
"column": 3,
11+
"severity": 4,
12+
"code": 5,
13+
"message": 6
1314
}
1415
]
1516
}
1617
]
17-
}
18+
}

__tests__/installer.test.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,10 @@ import path from 'path';
88
import * as main from '../src/main';
99
import * as im from '../src/installer';
1010
import * as auth from '../src/authutil';
11-
import {context} from '@actions/github';
1211

1312
let nodeTestManifest = require('./data/versions-manifest.json');
1413
let nodeTestDist = require('./data/node-dist-index.json');
1514

16-
// let matchers = require('../matchers.json');
17-
// let matcherPattern = matchers.problemMatcher[0].pattern[0];
18-
// let matcherRegExp = new RegExp(matcherPattern.regexp);
19-
2015
describe('setup-node', () => {
2116
let inputs = {} as any;
2217
let os = {} as any;

__tests__/problem-matcher.test.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
describe('problem matcher tests', () => {
2+
it('tsc: matches TypeScript "pretty" error message', () => {
3+
const [
4+
{
5+
pattern: [{regexp}]
6+
}
7+
] = require('../.github/tsc.json').problemMatcher;
8+
const exampleErrorMessage =
9+
"lib/index.js:23:42 - error TS2345: Argument of type 'A' is not assignable to parameter of type 'B'.";
10+
11+
const match = exampleErrorMessage.match(new RegExp(regexp));
12+
expect(match).not.toBeNull();
13+
expect(match![1]).toEqual('lib/index.js');
14+
expect(match![2]).toEqual('23');
15+
expect(match![3]).toEqual('42');
16+
expect(match![4]).toEqual('error');
17+
expect(match![5]).toEqual('2345');
18+
expect(match![6]).toEqual(
19+
"Argument of type 'A' is not assignable to parameter of type 'B'."
20+
);
21+
});
22+
23+
it('tsc: matches TypeScript error message from log file', () => {
24+
const [
25+
{
26+
pattern: [{regexp}]
27+
}
28+
] = require('../.github/tsc.json').problemMatcher;
29+
const exampleErrorMessage =
30+
"lib/index.js(23,42): error TS2345: Argument of type 'A' is not assignable to parameter of type 'B'.";
31+
32+
const match = exampleErrorMessage.match(new RegExp(regexp));
33+
expect(match).not.toBeNull();
34+
expect(match![1]).toEqual('lib/index.js');
35+
expect(match![2]).toEqual('23');
36+
expect(match![3]).toEqual('42');
37+
expect(match![4]).toEqual('error');
38+
expect(match![5]).toEqual('2345');
39+
expect(match![6]).toEqual(
40+
"Argument of type 'A' is not assignable to parameter of type 'B'."
41+
);
42+
});
43+
});

0 commit comments

Comments
 (0)