Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TypeScript error line/column #125

Merged
merged 5 commits into from Feb 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 7 additions & 6 deletions .github/tsc.json
Expand Up @@ -4,14 +4,15 @@
"owner": "tsc",
"pattern": [
{
"regexp": "^(?:\\s+\\d+\\>)?([^\\s].*)\\((\\d+|\\d+,\\d+|\\d+,\\d+,\\d+,\\d+)\\)\\s*:\\s+(error|warning|info)\\s+(\\w{1,2}\\d+)\\s*:\\s*(.*)$",
"regexp": "^([^\\s].*)[\\(:](\\d+)[,:](\\d+)(?:\\):\\s+|\\s+-\\s+)(error|warning|info)\\s+TS(\\d+)\\s*:\\s*(.*)$",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be good to add a unit test that loads the regexp and processes it against a line, asserts expected match groups

I'm worried if this change regresses something, at least we have a baseline unit test suite going forward.

Also i'm curious how this compares to vscode's built-in tsc problem matcher or their tsc-watch problem matcher. I briefly looked, but wan't able to find those built-in regexps in their repo.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ericsciple looks like tests were added below at your request. have a quick look

"file": 1,
"location": 2,
"severity": 3,
"code": 4,
"message": 5
"line": 2,
"column": 3,
"severity": 4,
"code": 5,
"message": 6
}
]
}
]
}
}
5 changes: 0 additions & 5 deletions __tests__/installer.test.ts
Expand Up @@ -8,15 +8,10 @@ import path from 'path';
import * as main from '../src/main';
import * as im from '../src/installer';
import * as auth from '../src/authutil';
import {context} from '@actions/github';

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

// let matchers = require('../matchers.json');
// let matcherPattern = matchers.problemMatcher[0].pattern[0];
// let matcherRegExp = new RegExp(matcherPattern.regexp);

describe('setup-node', () => {
let inputs = {} as any;
let os = {} as any;
Expand Down
43 changes: 43 additions & 0 deletions __tests__/problem-matcher.test.ts
@@ -0,0 +1,43 @@
describe('problem matcher tests', () => {
it('tsc: matches TypeScript "pretty" error message', () => {
const [
{
pattern: [{regexp}]
}
] = require('../.github/tsc.json').problemMatcher;
const exampleErrorMessage =
"lib/index.js:23:42 - error TS2345: Argument of type 'A' is not assignable to parameter of type 'B'.";

const match = exampleErrorMessage.match(new RegExp(regexp));
expect(match).not.toBeNull();
expect(match![1]).toEqual('lib/index.js');
expect(match![2]).toEqual('23');
expect(match![3]).toEqual('42');
expect(match![4]).toEqual('error');
expect(match![5]).toEqual('2345');
expect(match![6]).toEqual(
"Argument of type 'A' is not assignable to parameter of type 'B'."
);
});

it('tsc: matches TypeScript error message from log file', () => {
const [
{
pattern: [{regexp}]
}
] = require('../.github/tsc.json').problemMatcher;
const exampleErrorMessage =
"lib/index.js(23,42): error TS2345: Argument of type 'A' is not assignable to parameter of type 'B'.";

const match = exampleErrorMessage.match(new RegExp(regexp));
expect(match).not.toBeNull();
expect(match![1]).toEqual('lib/index.js');
expect(match![2]).toEqual('23');
expect(match![3]).toEqual('42');
expect(match![4]).toEqual('error');
expect(match![5]).toEqual('2345');
expect(match![6]).toEqual(
"Argument of type 'A' is not assignable to parameter of type 'B'."
);
});
});