-
Notifications
You must be signed in to change notification settings - Fork 543
feat: Add Problem Matcher for dotnet-format
#583
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
base: main
Are you sure you want to change the base?
Changes from all commits
bab7b00
c6f6323
4852744
254c86c
9dc70db
e609693
0cc4810
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| { | ||
| "problemMatcher": [ | ||
| { | ||
| "owner": "dotnet-format", | ||
| "pattern": [ | ||
| { | ||
| "regexp": "^\\s*(.*)\\((\\d+),(\\d+)\\):\\s+(error|warning)\\s+(.+):\\s+(.*)\\s+\\[(.+)\\]$", | ||
| "file": 1, | ||
| "line": 2, | ||
| "column": 3, | ||
| "severity": 4, | ||
| "code": 5, | ||
| "message": 6, | ||
| "fromPath": 7 | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import csc from '../.github/csc.json'; | ||
| import dotnetFormat from '../.github/dotnet-format.json'; | ||
|
|
||
| // Unit tests for problem matchers | ||
| // https://github.com/actions/toolkit/blob/main/docs/problem-matchers.md | ||
|
|
||
| describe('/.github/csc.json tests', () => { | ||
| const problemMatcher = csc.problemMatcher[0].pattern[0]; | ||
|
|
||
| it.each([ | ||
| [ | ||
| 'Program.cs(10,79): error CS1002: ; expected [/Users/zacharyeisinger/Documents/repo/setup-dotnet/__tests__/sample-broken-csproj/sample.csproj]', | ||
| { | ||
| file: 'Program.cs', | ||
| line: '10', | ||
| severity: 'error', | ||
| code: 'CS1002', | ||
| message: '; expected', | ||
| fromPath: | ||
| '/Users/zacharyeisinger/Documents/repo/setup-dotnet/__tests__/sample-broken-csproj/sample.csproj' | ||
| } | ||
| ], | ||
| [ | ||
| "S:\\Msbuild\\src\\Build\\Evaluation\\ExpressionShredder.cs(33,7): error CS1003: Syntax error, ',' expected [S:\\msbuild\\src\\Build\\Microsoft.Build.csproj > Properties:prop]", | ||
| { | ||
| file: 'S:\\Msbuild\\src\\Build\\Evaluation\\ExpressionShredder.cs', | ||
| line: '33', | ||
| severity: 'error', | ||
| code: 'CS1003', | ||
| message: "Syntax error, ',' expected", | ||
| fromPath: | ||
| 'S:\\msbuild\\src\\Build\\Microsoft.Build.csproj > Properties:prop' | ||
| } | ||
| ] | ||
| ])('log "%s" matches %o', (logOutput, expected) => { | ||
| const regexp = new RegExp(problemMatcher.regexp); | ||
| const res = logOutput.match(regexp); | ||
|
|
||
| for (const key in expected) { | ||
| expect(res?.[problemMatcher[key]]).toBe(expected[key]); | ||
| } | ||
|
Comment on lines
+39
to
+41
|
||
| }); | ||
| }); | ||
|
|
||
| describe('/.github/dotnet-format.json tests', () => { | ||
| const problemMatcher = dotnetFormat.problemMatcher[0].pattern[0]; | ||
|
|
||
| it.each([ | ||
| [ | ||
| "/home/runner/work/repo/Test.cs(18,6): error WHITESPACE: Fix whitespace formatting. Replace 12 characters with '\\n\\s\\s\\s\\s\\s\\s\\s\\s'. [/home/runner/work/repo/Test.csproj]", | ||
| { | ||
| file: '/home/runner/work/repo/Test.cs', | ||
| line: '18', | ||
| column: '6', | ||
| severity: 'error', | ||
| code: 'WHITESPACE', | ||
| message: | ||
| "Fix whitespace formatting. Replace 12 characters with '\\n\\s\\s\\s\\s\\s\\s\\s\\s'.", | ||
| fromPath: '/home/runner/work/repo/Test.csproj' | ||
| } | ||
| ] | ||
| ])('log "%s" matches %o', (logOutput, expected) => { | ||
| const regexp = new RegExp(problemMatcher.regexp); | ||
| const res = logOutput.match(regexp); | ||
|
|
||
| for (const key in expected) { | ||
| expect(res?.[problemMatcher[key]]).toBe(expected[key]); | ||
| } | ||
|
Comment on lines
+66
to
+68
|
||
| }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The regex pattern for capturing the 'code' field (capture group 5) uses
.+which is too greedy. Based on the test case, the code should matchWHITESPACEbut the pattern will incorrectly capture everything up to the last colon before the message. Consider using([A-Z_]+)or([^:]+)to match the diagnostic code more precisely.