Skip to content

Commit 2e8acaa

Browse files
Copilotdmichon-msft
andcommitted
fix: line mandatory (defaults to 1), column optional in FileError.getFormattedErrorMessage
Co-authored-by: dmichon-msft <26827560+dmichon-msft@users.noreply.github.com> Agent-Logs-Url: https://github.com/microsoft/rushstack/sessions/e0b803db-46de-4bf5-a531-31105741fbf8
1 parent 3fe471a commit 2e8acaa

2 files changed

Lines changed: 22 additions & 22 deletions

File tree

libraries/node-core-library/src/FileError.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const uuidFileError: string = '37a4c772-2dc8-4c66-89ae-262f8cc1f0c1';
5050
const baseFolderEnvVar: string = 'RUSHSTACK_FILE_ERROR_BASE_FOLDER';
5151

5252
const unixProblemMatcherPattern: IProblemPattern = {
53-
regexp: '^\\[[^\\]]+\\]\\s+(Error|Warning):\\s+([^:]+):(\\d+):(\\d+)\\s+-\\s+(?:\\(([^)]+)\\)\\s+)?(.*)$',
53+
regexp: '^\\[[^\\]]+\\]\\s+(Error|Warning):\\s+([^:]+):(\\d+)(?::(\\d+))?\\s+-\\s+(?:\\(([^)]+)\\)\\s+)?(.*)$',
5454
severity: 1,
5555
file: 2,
5656
line: 3,
@@ -61,7 +61,7 @@ const unixProblemMatcherPattern: IProblemPattern = {
6161

6262
const vsProblemMatcherPattern: IProblemPattern = {
6363
regexp:
64-
'^\\[[^\\]]+\\]\\s+(Error|Warning):\\s+([^\\(]+)\\((\\d+),(\\d+)\\)\\s+-\\s+(?:\\(([^)]+)\\)\\s+)?(.*)$',
64+
'^\\[[^\\]]+\\]\\s+(Error|Warning):\\s+([^\\(]+)\\((\\d+)(?:,(\\d+))?\\)\\s+-\\s+(?:\\(([^)]+)\\)\\s+)?(.*)$',
6565
severity: 1,
6666
file: 2,
6767
line: 3,
@@ -146,7 +146,7 @@ export class FileError extends Error {
146146
pathToFormat: this.absolutePath,
147147
message: this.message,
148148
line: this.line ?? 1,
149-
column: this.column ?? 1
149+
column: this.column
150150
});
151151
}
152152

libraries/node-core-library/src/test/FileError.test.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe(FileError.name, () => {
2929
absolutePath: `/path/to/project/path/to/file`,
3030
projectFolder: '/path/to/project'
3131
});
32-
expect(error1.toString()).toMatchInlineSnapshot(`"path/to/file:1:1 - message"`);
32+
expect(error1.toString()).toMatchInlineSnapshot(`"path/to/file:1 - message"`);
3333
});
3434

3535
it('correctly performs Unix-style relative file path formatting', () => {
@@ -49,7 +49,7 @@ describe(FileError.name, () => {
4949
line: 5
5050
});
5151
expect(error2.getFormattedErrorMessage({ format: 'Unix' })).toMatchInlineSnapshot(
52-
`"path/to/file:5:1 - message"`
52+
`"path/to/file:5 - message"`
5353
);
5454

5555
const error3: FileError = new FileError('message', {
@@ -59,15 +59,15 @@ describe(FileError.name, () => {
5959
column: 12
6060
});
6161
expect(error3.getFormattedErrorMessage({ format: 'Unix' })).toMatchInlineSnapshot(
62-
`"path/to/file:1:1 - message"`
62+
`"path/to/file:1:12 - message"`
6363
);
6464

6565
const error4: FileError = new FileError('message', {
6666
absolutePath: '/path/to/project/path/to/file',
6767
projectFolder: '/path/to/project'
6868
});
6969
expect(error4.getFormattedErrorMessage({ format: 'Unix' })).toMatchInlineSnapshot(
70-
`"path/to/file:1:1 - message"`
70+
`"path/to/file:1 - message"`
7171
);
7272
});
7373

@@ -93,8 +93,8 @@ describe(FileError.name, () => {
9393
// Because the file path is resolved on disk, the output will vary based on platform.
9494
// Only check that it ends as expected and is an absolute path.
9595
const error2Message: string = error2.getFormattedErrorMessage({ format: 'Unix' });
96-
expect(error2Message).toMatch(/.+:5:1 - message$/);
97-
const error2Path: string = error2Message.slice(0, error2Message.length - ':5:1 - message'.length);
96+
expect(error2Message).toMatch(/.+:5 - message$/);
97+
const error2Path: string = error2Message.slice(0, error2Message.length - ':5 - message'.length);
9898
expect(path.isAbsolute(error2Path)).toEqual(true);
9999

100100
const error3: FileError = new FileError('message', {
@@ -106,8 +106,8 @@ describe(FileError.name, () => {
106106
// Because the file path is resolved on disk, the output will vary based on platform.
107107
// Only check that it ends as expected and is an absolute path.
108108
const error3Message: string = error3.getFormattedErrorMessage({ format: 'Unix' });
109-
expect(error3Message).toMatch(/.+:1:1 - message$/);
110-
const error3Path: string = error3Message.slice(0, error3Message.length - ':1:1 - message'.length);
109+
expect(error3Message).toMatch(/.+:1:12 - message$/);
110+
const error3Path: string = error3Message.slice(0, error3Message.length - ':1:12 - message'.length);
111111
expect(path.isAbsolute(error3Path)).toEqual(true);
112112

113113
const error4: FileError = new FileError('message', {
@@ -117,8 +117,8 @@ describe(FileError.name, () => {
117117
// Because the file path is resolved on disk, the output will vary based on platform.
118118
// Only check that it ends as expected and is an absolute path.
119119
const error4Message: string = error4.getFormattedErrorMessage({ format: 'Unix' });
120-
expect(error4Message).toMatch(/.+:1:1 - message$/);
121-
const error4Path: string = error4Message.slice(0, error4Message.length - ':1:1 - message'.length);
120+
expect(error4Message).toMatch(/.+:1 - message$/);
121+
const error4Path: string = error4Message.slice(0, error4Message.length - ':1 - message'.length);
122122
expect(path.isAbsolute(error4Path)).toEqual(true);
123123
});
124124

@@ -139,7 +139,7 @@ describe(FileError.name, () => {
139139
line: 5
140140
});
141141
expect(error2.getFormattedErrorMessage({ format: 'VisualStudio' })).toMatchInlineSnapshot(
142-
`"path/to/file(5,1) - message"`
142+
`"path/to/file(5) - message"`
143143
);
144144

145145
const error3: FileError = new FileError('message', {
@@ -149,15 +149,15 @@ describe(FileError.name, () => {
149149
column: 12
150150
});
151151
expect(error3.getFormattedErrorMessage({ format: 'VisualStudio' })).toMatchInlineSnapshot(
152-
`"path/to/file(1,1) - message"`
152+
`"path/to/file(1,12) - message"`
153153
);
154154

155155
const error4: FileError = new FileError('message', {
156156
absolutePath: '/path/to/project/path/to/file',
157157
projectFolder: '/path/to/project'
158158
});
159159
expect(error4.getFormattedErrorMessage({ format: 'VisualStudio' })).toMatchInlineSnapshot(
160-
`"path/to/file(1,1) - message"`
160+
`"path/to/file(1) - message"`
161161
);
162162
});
163163

@@ -183,8 +183,8 @@ describe(FileError.name, () => {
183183
// Because the file path is resolved on disk, the output will vary based on platform.
184184
// Only check that it ends as expected and is an absolute path.
185185
const error2Message: string = error2.getFormattedErrorMessage({ format: 'VisualStudio' });
186-
expect(error2Message).toMatch(/.+\(5,1\) - message$/);
187-
const error2Path: string = error2Message.slice(0, error2Message.length - '(5,1) - message'.length);
186+
expect(error2Message).toMatch(/.+\(5\) - message$/);
187+
const error2Path: string = error2Message.slice(0, error2Message.length - '(5) - message'.length);
188188
expect(path.isAbsolute(error2Path)).toEqual(true);
189189

190190
const error3: FileError = new FileError('message', {
@@ -196,8 +196,8 @@ describe(FileError.name, () => {
196196
// Because the file path is resolved on disk, the output will vary based on platform.
197197
// Only check that it ends as expected and is an absolute path.
198198
const error3Message: string = error3.getFormattedErrorMessage({ format: 'VisualStudio' });
199-
expect(error3Message).toMatch(/.+\(1,1\) - message$/);
200-
const error3Path: string = error3Message.slice(0, error3Message.length - '(1,1) - message'.length);
199+
expect(error3Message).toMatch(/.+\(1,12\) - message$/);
200+
const error3Path: string = error3Message.slice(0, error3Message.length - '(1,12) - message'.length);
201201
expect(path.isAbsolute(error3Path)).toEqual(true);
202202

203203
const error4: FileError = new FileError('message', {
@@ -207,8 +207,8 @@ describe(FileError.name, () => {
207207
// Because the file path is resolved on disk, the output will vary based on platform.
208208
// Only check that it ends as expected and is an absolute path.
209209
const error4Message: string = error4.getFormattedErrorMessage({ format: 'VisualStudio' });
210-
expect(error4Message).toMatch(/.+\(1,1\) - message$/);
211-
const error4Path: string = error4Message.slice(0, error4Message.length - '(1,1) - message'.length);
210+
expect(error4Message).toMatch(/.+\(1\) - message$/);
211+
const error4Path: string = error4Message.slice(0, error4Message.length - '(1) - message'.length);
212212
expect(path.isAbsolute(error4Path)).toEqual(true);
213213
});
214214
});

0 commit comments

Comments
 (0)