I have a custom problemMatcher for an ant task that calls Microsoft JScript to lint JavaScript files (which I can not change to something modern like ESHint or similar).
JScript has error messages that itself reports as "This error can be ignored...", which looks like the following in the build output:
[echo] c:\Users\D064766\Work\Perforce\tc1\lightspeed\dev\src\_javascript\jsgen\js\dbg\lightspeed.js(20, 4) Microsoft JScript runtime error: 'document' is undefined
[echo]
[echo] This error can be ignored...
My problemMatcher looks is as follows:
"problemMatcher": [{
"owner": "javascript",
"fileLocation": ["absolute"],
"pattern": [{
"regexp": " \\[echo\\] ([^\\(\\)]*)\\((\\d+), (\\d+)\\) Microsoft JScript (runtime error|compilation error): (.*)",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}]
}]
It correctly finds the first line of the error report. I however want that errors that can be ignored occur as warnings rather than errors in the error reporting.
Is there a way to map error messages to severity levels?
E.g. map "runtime error"
to "warning"
and "compilation error"
to "error"
(short-sighted, I know -- would be enough for the moment).
There are two options you can use:
Either use a multi line problem matcher and match all three lines. However this requires that if a error message can't be ignored something is printed as well. For example 'This error is severe'. See https://code.visualstudio.com/Docs/editor/tasks#_defining-a-problem-matcher
Define two problem matcher and have a severity property on the matcher itself and not on the pattern. Something like this (not tested)
"problemMatcher": [{
"owner": "javascript",
"fileLocation": ["absolute"],
"severity": "warning",
"pattern": {
"regexp": " \\[echo\\] ([^\\(\\)]*)\\((\\d+), (\\d+)\\) Microsoft JScript runtime error): (.*)",
"file": 1,
"line": 2,
"column": 3,
"message": 4
}
},
{
"owner": "javascript",
"fileLocation": ["absolute"],
"severity": "error",
"pattern": {
"regexp": " \\[echo\\] ([^\\(\\)]*)\\((\\d+), (\\d+)\\) Microsoft JScript compilation error: (.*)",
"file": 1,
"line": 2,
"column": 3,
"message": 4
}
}]
For the full schema of task.json see https://code.visualstudio.com/Docs/editor/tasks_appendix