Uh oh!
There was an error while loading. Please reload this page.
Fix TypeScript error line/column - #125
Conversation
Zarel
commented
Apr 9, 2020
Zarel
commented
Apr 9, 2020
@ericsciple you self-assigned the bug this PR fixes; would you be interested in reviewing this? |
bryanmacfarlane
commented
May 2, 2020
Sorry. Been busy on some other changes. I'll have a look soon. |
| "regexp": "^(?:\\s+\\d+\\>)?([^\\s].*)\\((\\d+)(?:,(\\d+)(?:,\\d+(?:,\\d+)?)?)?\\)\\s*:\\s+(error|warning|info)\\s+(\\w{1,2}\\d+)\\s*:\\s*(.*)$", | ||
| "file": 1, | ||
| "location": 2, | ||
| "severity": 3, | ||
| "code": 4, | ||
| "message": 5 | ||
| "line": 2, | ||
| "column": 3, | ||
| "severity": 4, | ||
| "code": 5, | ||
| "message": 6 |
There was a problem hiding this comment.
I cannot human-parse this regex, but maybe this should just use the official $tsc pattern from vscode? Source: https://github.com/microsoft/vscode/blob/master/extensions/typescript-language-features/package.json#L974-L981 (it is not the same as this one)
There was a problem hiding this comment.
I have tested the official regex and can confirm that it works:
// commit this file to .github/tsc.json{"problemMatcher": [{"owner": "tsc","pattern": [{"name": "tsc","regexp": "^([^\\s].*)[\\(:](\\d+)[,:](\\d+)(?:\\):\\s+|\\s+-\\s+)(error|warning|info)\\s+TS(\\d+)\\s*:\\s*(.*)$","file": 1,"line": 2,"column": 3,"severity": 4,"code": 5,"message": 6}]}]}- name: Set up Nodeuses: actions/setup-node@v1# Run this _after_ setup-node
- name: Set up tsc problem matcherrun: echo "::add-matcher::${GITHUB_WORKSPACE}/.github/tsc.json"There was a problem hiding this comment.
Here is my regex, free-spaced and syntax highlighted:
Here is the official pattern from TypeScript, free-spaced and syntax-highlighted:
A TypeScript error message looks like this:
lib/net.ts(48,26): error TS1005: '}' expected.
Both regexes support that pattern. Mine is modified from the old one in this repository, which supported a variable number of commas.
In "fancy" mode, a TypeScript error message looks like this:
lib/net.ts:48:26 - error TS1005: '}' expected.
48 out += `${key}=${enc odeURIComponent('' + body[key])}`;
~~~~~~~~~~~~~~~
The official regex also supports this format (although it should never be passed to GitHub Actions in this format, in practice).
There was a problem hiding this comment.
In conclusion, the official pattern is probably better.
Do you think the free-spaced annotated version should be put somewhere, for readability?
^
# filename
([^\s].*)
# line number in "(1,2)" or ":1:2 -" format
[\(:]
(\d+) [,:] (\d+)
(?:\):\s+|\s+-\s+)
# severity
(error|warning|info)
# error code
\s+ TS(\d+)
# ":"
\s* :
# error message
\s* (.*)
$
(It can be compiled into the version in the repository with https://zarel.github.io/regexfree/ )
There was a problem hiding this comment.
(One other difference is that the official pattern doesn't consider "TS" part of the error code. There's an argument that it should be kept, for googleability.)
Uh oh!
There was an error while loading. Please reload this page.
TimWolla
commented
Oct 27, 2020
@bryanmacfarlane Is this one still on your radar? |
bryanmacfarlane
commented
Jan 20, 2021
@Zarel any interest in changing the PR to target main instead of master? |
Zarel
commented
Jan 20, 2021
@bryanmacfarlane Sure! I just did. Does this mean you're planning to merge this? |
bryanmacfarlane
commented
Feb 16, 2021
LGTM. @ericsciple can you have a quick look? Also, side question - I think that regex was pulled (or created from) the one that VS Code uses in it's problem matchers. Anyone know what VS Code is currently using and how this PR compares to it? |
@bryanmacfarlane As somebody mentioned in one of the comments above, this is the exact same regex that VS Code is currently using: https://github.com/microsoft/vscode/blob/8d9002679558432eca926b6bb4f767eaae6b1068/extensions/typescript-language-features/package.json#L1095-L1106 |
| "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*(.*)$", |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@ericsciple looks like tests were added below at your request. have a quick look
bryanmacfarlane
commented
Feb 16, 2021
@lumaxis are you ok to add unit test(s) per @ericsciple comment? I think we're good to merge after that. |
lumaxis
commented
Feb 16, 2021
@bryanmacfarlane Yea, that sounds like a great idea 👍🏼 Added tests in Zarel#1 |
Add tests for tsc problem matcher
Zarel
commented
Feb 17, 2021
I merged your PR directly. I'm glad to see this is finally getting looked at! :) |
bryanmacfarlane
commented
Feb 17, 2021
LGTM. any objections @ericsciple ? (if not, I'll merge tomorrow) |
This reverts commit a6ad5c9. The `tsc` problem matcher is now properly included in `setup-node` (actions/setup-node#125).
* chore(docs): Update explanation for token input * docs: move token info to dedicated paragraph * Fix typos Co-authored-by: Federico Grandi <fgrandi30@gmail.com>
This allegedly will result in annotations in GitHub on the specific files and linenumbers where the compilation fails. See: actions/setup-node#125 (comment)
This allegedly will result in annotations in GitHub on the specific files and linenumbers where the compilation fails. See: actions/setup-node#125 (comment)




Fixes#97