Skip to content

Commit

Permalink
Fix dotnet build parser to recognize path with space (#161)
Browse files Browse the repository at this point in the history
Co-authored-by: pdujtipiya <[email protected]>
  • Loading branch information
encX and pdujtipiya committed Nov 9, 2023
1 parent 118c078 commit 05a9e89
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/Parser/DotnetBuildParser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ describe('DotnetBuildParser tests', () => {
const cwdUnix = '/dir';

const logWithSource = `1:7>C:\\source\\Broken.cs(6,8): warning AG0030: Prevent use of dynamic [C:\\source\\Broken.csproj]`;
const logWithSourceWithSpace = `1:7>C:\\source\\some dir\\Broken.cs(6,8): warning AG0030: Prevent use of dynamic [C:\\source\\some dir\\Broken.csproj]`;
const logWithNoSource = `1:7>CSC : error CS5001: Program does not contain a static 'Main' method suitable for an entry point [C:\\source\\Broken.csproj]`;
const logWithUnrelatedSource = `9:8>/usr/share/dotnet/sdk/3.1.402/Microsoft.Common.CurrentVersion.targets(2084,5): warning MSB3277: some message [/dir/Tests/project.csproj]`;
const contentWithNoPathAtTheEnd = `13:11>/dir/File.csproj : warning NU1701: This package may not be fully compatible with your project.`;
Expand Down Expand Up @@ -78,4 +79,11 @@ describe('DotnetBuildParser tests', () => {
it('should ignore multiline-part messages', () => {
expect(() => new DotnetBuildParser(cwdUnix).parse(multilinePart)).not.toThrowError();
});

it('should handle path with space', () => {
const items = new DotnetBuildParser(cwdWin).parse(logWithSourceWithSpace);
const result = items[0];

expect(result.source).toBe('some dir/Broken.cs');
});
});
2 changes: 1 addition & 1 deletion src/Parser/DotnetBuildParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class DotnetBuildParser extends Parser {

private toLintItem(log: string): LintItem {
const structureMatch = log.match(
/(?:[\d:>]+)?([^ ()]+)(?:\((\d+),(\d+)\))? *: *(\w+) *(\w+) *: *([^\[]+)(?:\[(.+)])?$/,
/(?:[\d:>]+)?([^>()]+)(?:\((\d+),(\d+)\))? *: *(\w+) *(\w+) *: *([^\[]+)(?:\[(.+)])?$/,
);
if (!structureMatch) {
const message = "DotnetBuildParser Error: log structure doesn't match";
Expand Down

0 comments on commit 05a9e89

Please sign in to comment.