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

task: fix problem matcher failed when kind is file #11190

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions packages/task/src/node/task-abstract-line-matcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,7 @@ export abstract class AbstractLineMatcher {
const regexp = new RegExp(this.activePattern.regexp);
const regexMatches = regexp.exec(line);
if (regexMatches) {
if (this.activePattern.kind !== undefined && this.cachedProblemData.kind !== undefined) {
this.cachedProblemData.kind = this.activePattern.kind;
}
this.cachedProblemData.kind ??= this.activePattern.kind;
return this.fillProblemData(this.cachedProblemData, this.activePattern, regexMatches);
}
}
Expand Down
78 changes: 78 additions & 0 deletions packages/task/src/node/task-problem-collector.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,28 @@ const startStopMatcher2: ProblemMatcher = {
severity: Severity.Error
};

const startStopMatcher3: ProblemMatcher = {
owner: 'test2',
source: 'test2',
applyTo: ApplyToKind.allDocuments,
fileLocation: FileLocationKind.Absolute,
pattern: [
{
regexp: /^([^\s].*)$/.source,
kind: ProblemLocationKind.File,
file: 1
},
{
regexp: /^\s+(\d+):(\d+)\s+(error|warning|info)\s+(.+?)(?:\s\s+(.*))?$/.source,
severity: 3,
message: 4,
code: 5,
loop: true
}
],
severity: Severity.Error
};

const watchMatcher: ProblemMatcher = {
owner: 'test3',
applyTo: ApplyToKind.closedDocuments,
Expand Down Expand Up @@ -189,6 +211,62 @@ describe('ProblemCollector', () => {
});
});

it('should find problems from start-stop task when problem matcher is associated with more than one problem pattern and kind is file', () => {
collector = new ProblemCollector([startStopMatcher3]);
collectMatches([
'> [email protected] lint /home/test',
'> eslint .',
'',
'',
'/home/test/test-dir.js',
' 14:21 warning Missing semicolon semi',
' 15:23 warning Missing semicolon semi',
' 103:9 error Parsing error: Unexpected token inte',
'',
'/home/test/more-test.js',
' 13:9 error Parsing error: Unexpected token 1000',
'',
'✖ 3 problems (1 error, 2 warnings)',
' 0 errors and 2 warnings potentially fixable with the `--fix` option.'
]);

expect(allMatches.length).to.eq(4);

expect((allMatches[0] as ProblemMatchData).resource?.path).eq('/home/test/test-dir.js');
expect((allMatches[0] as ProblemMatchData).marker).deep.equal({
range: { start: { line: 0, character: 0 }, end: { line: 0, character: 0 } },
severity: DiagnosticSeverity.Warning,
source: 'test2',
message: 'Missing semicolon',
code: 'semi'
});

expect((allMatches[1] as ProblemMatchData).resource?.path).eq('/home/test/test-dir.js');
expect((allMatches[1] as ProblemMatchData).marker).deep.equal({
range: { start: { line: 0, character: 0 }, end: { line: 0, character: 0 } },
severity: DiagnosticSeverity.Warning,
source: 'test2',
message: 'Missing semicolon',
code: 'semi'
});

expect((allMatches[2] as ProblemMatchData).resource?.path).eq('/home/test/test-dir.js');
expect((allMatches[2] as ProblemMatchData).marker).deep.equal({
range: { start: { line: 0, character: 0 }, end: { line: 0, character: 0 } },
severity: DiagnosticSeverity.Error,
source: 'test2',
message: 'Parsing error: Unexpected token inte'
});

expect((allMatches[3] as ProblemMatchData).resource?.path).eq('/home/test/more-test.js');
expect((allMatches[3] as ProblemMatchData).marker).deep.equal({
range: { start: { line: 0, character: 0 }, end: { line: 0, character: 0 } },
severity: DiagnosticSeverity.Error,
source: 'test2',
message: 'Parsing error: Unexpected token 1000'
});
});

it('should search and find defined problems from watch task\'s output', () => {
collector = new ProblemCollector([watchMatcher]);

Expand Down