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 dotnet build parser to recognize path with space #161

Merged
merged 1 commit into from
Nov 9, 2023
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
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