Skip to content

Commit 81ef6e6

Browse files
committed
fix: bring back :line:col format in webpack errors
Reimplements #489 so that file links with locations can be clicked in the terminal.
1 parent f23da17 commit 81ef6e6

11 files changed

+37
-49
lines changed

src/formatter/webpack-formatter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function createWebpackFormatter(formatter: Formatter): Formatter {
1717
if (issue.file) {
1818
let location = chalk.whiteBright.bold(relativeToContext(issue.file, process.cwd()));
1919
if (issue.location) {
20-
location += ` ${chalk.green.bold(formatIssueLocation(issue.location))}`;
20+
location += `:${chalk.green.bold(formatIssueLocation(issue.location))}`;
2121
}
2222

2323
return [`${color(severity)} in ${location}`, formatter(issue), ''].join(os.EOL);

src/issue/issue-location.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,8 @@ function compareIssueLocations(locationA?: IssueLocation, locationB?: IssueLocat
2525
);
2626
}
2727

28-
function formatIssueLocation({ start, end }: IssueLocation) {
29-
if (!end.line || start.line === end.line) {
30-
// the same line
31-
if (!end.column || start.column === end.column) {
32-
// the same column
33-
return `${start.line}:${start.column}`;
34-
} else {
35-
// different column
36-
return `${start.line}:${start.column}-${end.column}`;
37-
}
38-
} else {
39-
// different lines
40-
return `${start.line}:${start.column}-${end.line}:${end.column}`;
41-
}
28+
function formatIssueLocation(location: IssueLocation) {
29+
return `${location.start.line}:${location.start.column}`;
4230
}
4331

4432
export { IssueLocation, compareIssueLocations, formatIssueLocation };

src/issue/issue-webpack-error.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class IssueWebpackError extends webpack.WebpackError {
1919
this.file = relativeToContext(issue.file, process.cwd());
2020

2121
if (issue.location) {
22-
this.file += ` ${chalk.green.bold(formatIssueLocation(issue.location))}`;
22+
this.file += `:${chalk.green.bold(formatIssueLocation(issue.location))}`;
2323
}
2424
}
2525

test/e2e/type-script-context-option.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ describe('TypeScript Context Option', () => {
8989
const errors = await driver.waitForErrors();
9090
expect(errors).toEqual([
9191
[
92-
'ERROR in ../src/model/User.ts 11:16-25',
92+
'ERROR in ../src/model/User.ts:11:16',
9393
"TS2339: Property 'firstName' does not exist on type 'User'.",
9494
' 9 |',
9595
' 10 | function getUserName(user: User): string {',
@@ -100,7 +100,7 @@ describe('TypeScript Context Option', () => {
100100
' 14 | export { User, getUserName };',
101101
].join('\n'),
102102
[
103-
'ERROR in ../src/model/User.ts 11:32-40',
103+
'ERROR in ../src/model/User.ts:11:32',
104104
"TS2339: Property 'lastName' does not exist on type 'User'.",
105105
' 9 |',
106106
' 10 | function getUserName(user: User): string {',

test/e2e/type-script-formatter-option.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ describe('TypeScript Formatter Option', () => {
4141
const errors = await driver.waitForErrors();
4242
expect(errors).toEqual([
4343
[
44-
'ERROR in ./src/model/User.ts 11:16-25',
44+
'ERROR in ./src/model/User.ts:11:16',
4545
"It is the custom issue statement - TS2339: Property 'firstName' does not exist on type 'User'.",
4646
].join('\n'),
4747
[
48-
'ERROR in ./src/model/User.ts 11:32-40',
48+
'ERROR in ./src/model/User.ts:11:32',
4949
"It is the custom issue statement - TS2339: Property 'lastName' does not exist on type 'User'.",
5050
].join('\n'),
5151
]);

test/e2e/type-script-pnp-support.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe('TypeScript PnP Support', () => {
3434
errors = await driver.waitForErrors();
3535
expect(errors).toEqual([
3636
[
37-
'ERROR in ./src/model/User.ts 11:16-25',
37+
'ERROR in ./src/model/User.ts:11:16',
3838
"TS2339: Property 'firstName' does not exist on type 'User'.",
3939
' 9 |',
4040
' 10 | function getUserName(user: User): string {',
@@ -45,7 +45,7 @@ describe('TypeScript PnP Support', () => {
4545
' 14 | export { User, getUserName };',
4646
].join('\n'),
4747
[
48-
'ERROR in ./src/model/User.ts 11:32-40',
48+
'ERROR in ./src/model/User.ts:11:32',
4949
"TS2339: Property 'lastName' does not exist on type 'User'.",
5050
' 9 |',
5151
' 10 | function getUserName(user: User): string {',
@@ -72,7 +72,7 @@ describe('TypeScript PnP Support', () => {
7272
errors = await driver.waitForErrors();
7373
expect(errors).toContain(
7474
[
75-
'ERROR in ./src/index.ts 1:23-39',
75+
'ERROR in ./src/index.ts:1:23',
7676
semver.satisfies(semver.minVersion(dependencies.typescript), '>=4.0.0')
7777
? "TS2307: Cannot find module './authenticate' or its corresponding type declarations."
7878
: "TS2307: Cannot find module './authenticate'.",
@@ -118,7 +118,7 @@ describe('TypeScript PnP Support', () => {
118118
errors = await driver.waitForErrors();
119119
expect(errors).toEqual([
120120
[
121-
'ERROR in ./src/index.ts 34:12-16',
121+
'ERROR in ./src/index.ts:34:12',
122122
"TS2339: Property 'role' does not exist on type 'void'.",
123123
' 32 | const user = await login(email, password);',
124124
' 33 |',
@@ -129,7 +129,7 @@ describe('TypeScript PnP Support', () => {
129129
' 37 | console.log(`Logged in as ${getUserName(user)}`);',
130130
].join('\n'),
131131
[
132-
'ERROR in ./src/index.ts 35:45-49',
132+
'ERROR in ./src/index.ts:35:45',
133133
"TS2345: Argument of type 'void' is not assignable to parameter of type 'User'.",
134134
' 33 |',
135135
" 34 | if (user.role === 'admin') {",
@@ -140,7 +140,7 @@ describe('TypeScript PnP Support', () => {
140140
' 38 | }',
141141
].join('\n'),
142142
[
143-
'ERROR in ./src/index.ts 37:45-49',
143+
'ERROR in ./src/index.ts:37:45',
144144
"TS2345: Argument of type 'void' is not assignable to parameter of type 'User'.",
145145
' 35 | console.log(`Logged in as ${getUserName(user)} [admin].`);',
146146
' 36 | } else {',

test/e2e/type-script-solution-builder-api.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe('TypeScript SolutionBuilder API', () => {
3333
errors = await driver.waitForErrors();
3434
expect(errors).toEqual([
3535
[
36-
'ERROR in ./packages/shared/src/intersect.ts 2:41-49',
36+
'ERROR in ./packages/shared/src/intersect.ts:2:41',
3737
"TS2339: Property 'includes' does not exist on type 'T'.",
3838
' 1 | function intersect<T>(arrayA: T[] = [], arrayB: T): T[] {',
3939
' > 2 | return arrayA.filter((item) => arrayB.includes(item));',
@@ -55,7 +55,7 @@ describe('TypeScript SolutionBuilder API', () => {
5555
errors = await driver.waitForErrors();
5656
expect(errors).toEqual([
5757
[
58-
'ERROR in ./packages/client/src/index.ts 4:42-48',
58+
'ERROR in ./packages/client/src/index.ts:4:42',
5959
"TS2345: Argument of type 'T[]' is not assignable to parameter of type 'T'.",
6060
semver.satisfies(semver.minVersion(typescript), '>=4.0.0')
6161
? " 'T' could be instantiated with an arbitrary type which could be unrelated to 'T[]'."

test/e2e/type-script-vue-extension.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ describe('TypeScript Vue Extension', () => {
6363
errors = await driver.waitForErrors();
6464
expect(errors).toEqual([
6565
[
66-
'ERROR in ./src/component/LoggedIn.vue 27:23-34',
66+
'ERROR in ./src/component/LoggedIn.vue:27:23',
6767
"TS2304: Cannot find name 'getUserName'.",
6868
' 25 | const user: User = this.user;',
6969
' 26 |',
@@ -91,7 +91,7 @@ describe('TypeScript Vue Extension', () => {
9191
errors = await driver.waitForErrors();
9292
expect(errors).toEqual([
9393
[
94-
'ERROR in ./src/component/LoggedIn.vue 27:31-40',
94+
'ERROR in ./src/component/LoggedIn.vue:27:31',
9595
"TS2339: Property 'firstName' does not exist on type 'User'.",
9696
' 25 | const user: User = this.user;',
9797
' 26 |',
@@ -102,7 +102,7 @@ describe('TypeScript Vue Extension', () => {
102102
' 30 | async logout() {',
103103
].join('\n'),
104104
[
105-
'ERROR in ./src/model/User.ts 11:16-25',
105+
'ERROR in ./src/model/User.ts:11:16',
106106
"TS2339: Property 'firstName' does not exist on type 'User'.",
107107
' 9 |',
108108
' 10 | function getUserName(user: User): string {',

test/e2e/type-script-watch-api.spec.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('TypeScript Watch API', () => {
3232
errors = await driver.waitForErrors();
3333
expect(errors).toEqual([
3434
[
35-
'ERROR in ./src/index.ts 34:7-28',
35+
'ERROR in ./src/index.ts:34:7',
3636
`TS2367: This condition will always return 'false' since the types 'Role' and '"admin"' have no overlap.`,
3737
' 32 | const user = await login(email, password);',
3838
' 33 |',
@@ -74,7 +74,7 @@ describe('TypeScript Watch API', () => {
7474
);
7575
expect(errors).toEqual([
7676
[
77-
'ERROR in ./src/model/User.ts 1:22-30',
77+
'ERROR in ./src/model/User.ts:1:22',
7878
"TS2307: Cannot find module './Role' or its corresponding type declarations.",
7979
" > 1 | import { Role } from './Role';",
8080
' | ^^^^^^^^',
@@ -94,7 +94,7 @@ describe('TypeScript Watch API', () => {
9494
errors = await driver.waitForErrors();
9595
expect(errors).toEqual([
9696
[
97-
'ERROR in ./src/index.ts 34:7-31',
97+
'ERROR in ./src/index.ts:34:7',
9898
"TS2367: This condition will always return 'false' since the types 'Role' and '\"provider\"' have no overlap.",
9999
' 32 | const user = await login(email, password);',
100100
' 33 |',
@@ -135,7 +135,7 @@ describe('TypeScript Watch API', () => {
135135
errors = await driver.waitForErrors();
136136
expect(errors).toEqual([
137137
[
138-
'ERROR in ./src/index.ts 34:7-28',
138+
'ERROR in ./src/index.ts:34:7',
139139
`TS2367: This condition will always return 'false' since the types 'Role' and '"admin"' have no overlap.`,
140140
' 32 | const user = await login(email, password);',
141141
' 33 |',
@@ -177,7 +177,7 @@ describe('TypeScript Watch API', () => {
177177
);
178178
expect(errors).toEqual([
179179
[
180-
'ERROR in ./src/model/User.ts 1:22-30',
180+
'ERROR in ./src/model/User.ts:1:22',
181181
"TS2307: Cannot find module './Role' or its corresponding type declarations.",
182182
" > 1 | import { Role } from './Role';",
183183
' | ^^^^^^^^',
@@ -197,7 +197,7 @@ describe('TypeScript Watch API', () => {
197197
errors = await driver.waitForErrors();
198198
expect(errors).toEqual([
199199
[
200-
'ERROR in ./src/index.ts 34:7-31',
200+
'ERROR in ./src/index.ts:34:7',
201201
"TS2367: This condition will always return 'false' since the types 'Role' and '\"provider\"' have no overlap.",
202202
' 32 | const user = await login(email, password);',
203203
' 33 |',
@@ -241,7 +241,7 @@ describe('TypeScript Watch API', () => {
241241
errors = await driver.waitForErrors();
242242
expect(errors).toEqual([
243243
[
244-
'ERROR in ./src/model/User.ts 11:16-25',
244+
'ERROR in ./src/model/User.ts:11:16',
245245
"TS2339: Property 'firstName' does not exist on type 'User'.",
246246
' 9 |',
247247
' 10 | function getUserName(user: User): string {',
@@ -252,7 +252,7 @@ describe('TypeScript Watch API', () => {
252252
' 14 | export { User, getUserName };',
253253
].join('\n'),
254254
[
255-
'ERROR in ./src/model/User.ts 11:32-40',
255+
'ERROR in ./src/model/User.ts:11:32',
256256
"TS2339: Property 'lastName' does not exist on type 'User'.",
257257
' 9 |',
258258
' 10 | function getUserName(user: User): string {',
@@ -279,7 +279,7 @@ describe('TypeScript Watch API', () => {
279279
errors = await driver.waitForErrors();
280280
expect(errors).toContain(
281281
[
282-
'ERROR in ./src/index.ts 1:23-39',
282+
'ERROR in ./src/index.ts:1:23',
283283
semver.satisfies(semver.minVersion(dependencies.typescript), '>=4.0.0')
284284
? "TS2307: Cannot find module './authenticate' or its corresponding type declarations."
285285
: "TS2307: Cannot find module './authenticate'.",
@@ -325,7 +325,7 @@ describe('TypeScript Watch API', () => {
325325
errors = await driver.waitForErrors();
326326
expect(errors).toEqual([
327327
[
328-
'ERROR in ./src/index.ts 34:12-16',
328+
'ERROR in ./src/index.ts:34:12',
329329
"TS2339: Property 'role' does not exist on type 'void'.",
330330
' 32 | const user = await login(email, password);',
331331
' 33 |',
@@ -336,7 +336,7 @@ describe('TypeScript Watch API', () => {
336336
' 37 | console.log(`Logged in as ${getUserName(user)}`);',
337337
].join('\n'),
338338
[
339-
'ERROR in ./src/index.ts 35:45-49',
339+
'ERROR in ./src/index.ts:35:45',
340340
"TS2345: Argument of type 'void' is not assignable to parameter of type 'User'.",
341341
' 33 |',
342342
" 34 | if (user.role === 'admin') {",
@@ -347,7 +347,7 @@ describe('TypeScript Watch API', () => {
347347
' 38 | }',
348348
].join('\n'),
349349
[
350-
'ERROR in ./src/index.ts 37:45-49',
350+
'ERROR in ./src/index.ts:37:45',
351351
"TS2345: Argument of type 'void' is not assignable to parameter of type 'User'.",
352352
' 35 | console.log(`Logged in as ${getUserName(user)} [admin].`);',
353353
' 36 | } else {',
@@ -457,7 +457,7 @@ describe('TypeScript Watch API', () => {
457457

458458
expect(await driver.waitForErrors()).toEqual([
459459
[
460-
'ERROR in ./src/model/User.ts 12:47-59',
460+
'ERROR in ./src/model/User.ts:12:47',
461461
"TS2339: Property 'organization' does not exist on type 'User'.",
462462
' 10 |',
463463
' 11 | function getUserName(user: User): string {',

test/e2e/webpack-production-build.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ describe('Webpack Production Build', () => {
8787
// first error is from the webpack module resolution
8888
expect.anything(),
8989
[
90-
'ERROR in ./src/authenticate.ts 1:22-36',
90+
'ERROR in ./src/authenticate.ts:1:22',
9191
"TS2307: Cannot find module './model/User' or its corresponding type declarations.",
9292
" > 1 | import { User } from './model/User';",
9393
' | ^^^^^^^^^^^^^^',
@@ -96,7 +96,7 @@ describe('Webpack Production Build', () => {
9696
" 4 | const response = await fetch('/login', {",
9797
].join('\n'),
9898
[
99-
'ERROR in ./src/index.ts 2:29-43',
99+
'ERROR in ./src/index.ts:2:29',
100100
"TS2307: Cannot find module './model/User' or its corresponding type declarations.",
101101
" 1 | import { login } from './authenticate';",
102102
" > 2 | import { getUserName } from './model/User';",

0 commit comments

Comments
 (0)