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: use :line:col format in webpack errors #489

Merged
merged 3 commits into from
Jul 28, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion src/formatter/WebpackFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function createWebpackFormatter(formatter: Formatter, context: string): Formatte
if (issue.file) {
let location = forwardSlash(path.relative(context, issue.file));
if (issue.location) {
location += ` ${formatIssueLocation(issue.location)}`;
location += `:${formatIssueLocation(issue.location)}`;
}

return [color(`${severity} in ${location}`), formatter(issue), ''].join(os.EOL);
Expand Down
7 changes: 1 addition & 6 deletions src/issue/IssueLocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@ function compareIssueLocations(locationA?: IssueLocation, locationB?: IssueLocat
}

function formatIssueLocation(location: IssueLocation) {
return [
`${location.start.line}:${location.start.column}`,
location.start.line !== location.end.line
? `${location.end.line}:${location.end.column}`
: `${location.end.column}`,
].join('-');
return `${location.start.line}:${location.start.column}`;
}

export { IssueLocation, compareIssueLocations, formatIssueLocation };
9 changes: 5 additions & 4 deletions test/e2e/EsLint.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
WEBPACK_CLI_VERSION,
WEBPACK_DEV_SERVER_VERSION,
} from './sandbox/WebpackDevServerDriver';
import { fileLocation } from './fileLocationHelper';

describe('EsLint', () => {
let sandbox: Sandbox;
Expand Down Expand Up @@ -59,7 +60,7 @@ describe('EsLint', () => {
errors = await driver.waitForErrors();
expect(errors).toEqual([
[
'WARNING in src/authenticate.ts 14:34-37',
fileLocation('WARNING in src/authenticate.ts', '14:34', async),
piotr-oles marked this conversation as resolved.
Show resolved Hide resolved
'@typescript-eslint/no-explicit-any: Unexpected any. Specify a different type.',
' 12 | }',
' 13 | ',
Expand All @@ -70,7 +71,7 @@ describe('EsLint', () => {
' 17 | {',
].join('\n'),
[
'WARNING in src/index.ts 31:44-49',
fileLocation('WARNING in src/index.ts', '31:44', async),
"@typescript-eslint/no-unused-vars: 'event' is defined but never used.",
' 29 | }',
' 30 | });',
Expand Down Expand Up @@ -126,7 +127,7 @@ describe('EsLint', () => {
errors = await driver.waitForErrors();
expect(errors).toEqual([
[
'WARNING in src/model/User.ts 11:5-19',
fileLocation('WARNING in src/model/User.ts', '11:5', async),
"@typescript-eslint/no-unused-vars: 'temporary' is defined but never used.",
' 9 | }',
' 10 | ',
Expand All @@ -137,7 +138,7 @@ describe('EsLint', () => {
' 14 | function getUserName(user: User): string {',
].join('\n'),
[
'WARNING in src/model/User.ts 11:16-19',
fileLocation('WARNING in src/model/User.ts', '11:16', async),
'@typescript-eslint/no-explicit-any: Unexpected any. Specify a different type.',
' 9 | }',
' 10 | ',
Expand Down
5 changes: 3 additions & 2 deletions test/e2e/TypeScriptContextOption.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
WEBPACK_CLI_VERSION,
WEBPACK_DEV_SERVER_VERSION,
} from './sandbox/WebpackDevServerDriver';
import { fileLocation } from './fileLocationHelper';

describe('TypeScript Context Option', () => {
let sandbox: Sandbox;
Expand Down Expand Up @@ -102,7 +103,7 @@ describe('TypeScript Context Option', () => {
const errors = await driver.waitForErrors();
expect(errors).toEqual([
[
'ERROR in src/model/User.ts 11:16-25',
fileLocation('ERROR in src/model/User.ts', '11:16', async),
"TS2339: Property 'firstName' does not exist on type 'User'.",
' 9 | ',
' 10 | function getUserName(user: User): string {',
Expand All @@ -113,7 +114,7 @@ describe('TypeScript Context Option', () => {
' 14 | }',
].join('\n'),
[
'ERROR in src/model/User.ts 11:32-40',
fileLocation('ERROR in src/model/User.ts', '11:32', async),
"TS2339: Property 'lastName' does not exist on type 'User'.",
' 9 | ',
' 10 | function getUserName(user: User): string {',
Expand Down
13 changes: 7 additions & 6 deletions test/e2e/TypeScriptPnpSupport.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
WEBPACK_CLI_VERSION,
WEBPACK_DEV_SERVER_VERSION,
} from './sandbox/WebpackDevServerDriver';
import { fileLocation } from './fileLocationHelper';

describe('TypeScript PnP Support', () => {
let sandbox: Sandbox;
Expand Down Expand Up @@ -67,7 +68,7 @@ describe('TypeScript PnP Support', () => {
errors = await driver.waitForErrors();
expect(errors).toEqual([
[
'ERROR in src/model/User.ts 11:16-25',
fileLocation('ERROR in src/model/User.ts', '11:16', async),
"TS2339: Property 'firstName' does not exist on type 'User'.",
' 9 | ',
' 10 | function getUserName(user: User): string {',
Expand All @@ -78,7 +79,7 @@ describe('TypeScript PnP Support', () => {
' 14 | }',
].join('\n'),
[
'ERROR in src/model/User.ts 11:32-40',
fileLocation('ERROR in src/model/User.ts', '11:32', async),
"TS2339: Property 'lastName' does not exist on type 'User'.",
' 9 | ',
' 10 | function getUserName(user: User): string {',
Expand Down Expand Up @@ -109,7 +110,7 @@ describe('TypeScript PnP Support', () => {
errors = await driver.waitForErrors();
expect(errors).toEqual([
[
'ERROR in src/index.ts 1:23-39',
fileLocation('ERROR in src/index.ts', '1:23', async),
"TS2307: Cannot find module './authenticate'.",
" > 1 | import { login } from './authenticate';",
' | ^^^^^^^^^^^^^^^^',
Expand Down Expand Up @@ -153,7 +154,7 @@ describe('TypeScript PnP Support', () => {
errors = await driver.waitForErrors();
expect(errors).toEqual([
[
'ERROR in src/index.ts 34:12-16',
fileLocation('ERROR in src/index.ts', '34:12', async),
"TS2339: Property 'role' does not exist on type 'void'.",
' 32 | const user = await login(email, password);',
' 33 | ',
Expand All @@ -164,7 +165,7 @@ describe('TypeScript PnP Support', () => {
' 37 | console.log(`Logged in as ${getUserName(user)}`);',
].join('\n'),
[
'ERROR in src/index.ts 35:45-49',
fileLocation('ERROR in src/index.ts', '35:45', async),
"TS2345: Argument of type 'void' is not assignable to parameter of type 'User'.",
' 33 | ',
" 34 | if (user.role === 'admin') {",
Expand All @@ -175,7 +176,7 @@ describe('TypeScript PnP Support', () => {
' 38 | }',
].join('\n'),
[
'ERROR in src/index.ts 37:45-49',
fileLocation('ERROR in src/index.ts', '37:45', async),
"TS2345: Argument of type 'void' is not assignable to parameter of type 'User'.",
' 35 | console.log(`Logged in as ${getUserName(user)} [admin].`);',
' 36 | } else {',
Expand Down
5 changes: 3 additions & 2 deletions test/e2e/TypeScriptSolutionBuilderApi.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
WEBPACK_CLI_VERSION,
WEBPACK_DEV_SERVER_VERSION,
} from './sandbox/WebpackDevServerDriver';
import { fileLocation } from './fileLocationHelper';

describe('TypeScript SolutionBuilder API', () => {
let sandbox: Sandbox;
Expand Down Expand Up @@ -56,7 +57,7 @@ describe('TypeScript SolutionBuilder API', () => {
errors = await driver.waitForErrors();
expect(errors).toEqual([
[
'ERROR in packages/shared/src/intersect.ts 2:41-49',
fileLocation('ERROR in packages/shared/src/intersect.ts', '2:41', async),
"TS2339: Property 'includes' does not exist on type 'T'.",
' 1 | function intersect<T>(arrayA: T[] = [], arrayB: T): T[] {',
' > 2 | return arrayA.filter((item) => arrayB.includes(item));',
Expand All @@ -78,7 +79,7 @@ describe('TypeScript SolutionBuilder API', () => {
errors = await driver.waitForErrors();
expect(errors).toEqual([
[
'ERROR in packages/client/src/index.ts 4:42-48',
fileLocation('ERROR in packages/client/src/index.ts', '4:42', async),
"TS2345: Argument of type 'T[]' is not assignable to parameter of type 'T'.",
" 'T[]' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.",
' 2 | ',
Expand Down
7 changes: 4 additions & 3 deletions test/e2e/TypeScriptVueExtension.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
WEBPACK_CLI_VERSION,
WEBPACK_DEV_SERVER_VERSION,
} from './sandbox/WebpackDevServerDriver';
import { fileLocation } from './fileLocationHelper';

describe('TypeScript Vue Extension', () => {
let sandbox: Sandbox;
Expand Down Expand Up @@ -94,7 +95,7 @@ describe('TypeScript Vue Extension', () => {
errors = await driver.waitForErrors();
expect(errors).toEqual([
[
'ERROR in src/component/LoggedIn.vue 27:21-32',
fileLocation('ERROR in src/component/LoggedIn.vue', '27:21', async),
"TS2304: Cannot find name 'getUserName'.",
' 25 | const user: User = this.user;',
' 26 | ',
Expand Down Expand Up @@ -122,7 +123,7 @@ describe('TypeScript Vue Extension', () => {
errors = await driver.waitForErrors();
expect(errors).toEqual([
[
'ERROR in src/component/LoggedIn.vue 27:29-38',
fileLocation('ERROR in src/component/LoggedIn.vue', '27:29', async),
"TS2339: Property 'firstName' does not exist on type 'User'.",
' 25 | const user: User = this.user;',
' 26 | ',
Expand All @@ -133,7 +134,7 @@ describe('TypeScript Vue Extension', () => {
' 30 | async logout() {',
].join('\n'),
[
'ERROR in src/model/User.ts 11:16-25',
fileLocation('ERROR in src/model/User.ts', '11:16', async),
"TS2339: Property 'firstName' does not exist on type 'User'.",
' 9 | ',
' 10 | function getUserName(user: User): string {',
Expand Down
25 changes: 13 additions & 12 deletions test/e2e/TypeScriptWatchApi.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
WEBPACK_CLI_VERSION,
WEBPACK_DEV_SERVER_VERSION,
} from './sandbox/WebpackDevServerDriver';
import { fileLocation } from './fileLocationHelper';

describe('TypeScript Watch API', () => {
let sandbox: Sandbox;
Expand Down Expand Up @@ -73,7 +74,7 @@ describe('TypeScript Watch API', () => {
errors = await driver.waitForErrors();
expect(errors).toEqual([
[
'ERROR in src/index.ts 34:7-28',
fileLocation('ERROR in src/index.ts', '34:7', async),
`TS2367: This condition will always return 'false' since the types 'Role' and '"admin"' have no overlap.`,
' 32 | const user = await login(email, password);',
' 33 | ',
Expand Down Expand Up @@ -115,7 +116,7 @@ describe('TypeScript Watch API', () => {
);
expect(errors).toEqual([
[
'ERROR in src/model/User.ts 1:22-30',
fileLocation('ERROR in src/model/User.ts', '1:22', async),
"TS2307: Cannot find module './Role'.",
" > 1 | import { Role } from './Role';",
' | ^^^^^^^^',
Expand All @@ -135,7 +136,7 @@ describe('TypeScript Watch API', () => {
errors = await driver.waitForErrors();
expect(errors).toEqual([
[
'ERROR in src/index.ts 34:7-31',
fileLocation('ERROR in src/index.ts', '34:7', async),
"TS2367: This condition will always return 'false' since the types 'Role' and '\"provider\"' have no overlap.",
' 32 | const user = await login(email, password);',
' 33 | ',
Expand Down Expand Up @@ -194,7 +195,7 @@ describe('TypeScript Watch API', () => {
errors = await driver.waitForErrors();
expect(errors).toEqual([
[
'ERROR in src/index.ts 34:7-28',
fileLocation('ERROR in src/index.ts', '34:7', async),
`TS2367: This condition will always return 'false' since the types 'Role' and '"admin"' have no overlap.`,
' 32 | const user = await login(email, password);',
' 33 | ',
Expand Down Expand Up @@ -236,7 +237,7 @@ describe('TypeScript Watch API', () => {
);
expect(errors).toEqual([
[
'ERROR in src/model/User.ts 1:22-30',
fileLocation('ERROR in src/model/User.ts', '1:22', async),
"TS2307: Cannot find module './Role'.",
" > 1 | import { Role } from './Role';",
' | ^^^^^^^^',
Expand All @@ -256,7 +257,7 @@ describe('TypeScript Watch API', () => {
errors = await driver.waitForErrors();
expect(errors).toEqual([
[
'ERROR in src/index.ts 34:7-31',
fileLocation('ERROR in src/index.ts', '34:7', async),
"TS2367: This condition will always return 'false' since the types 'Role' and '\"provider\"' have no overlap.",
' 32 | const user = await login(email, password);',
' 33 | ',
Expand Down Expand Up @@ -308,7 +309,7 @@ describe('TypeScript Watch API', () => {
errors = await driver.waitForErrors();
expect(errors).toEqual([
[
'ERROR in src/model/User.ts 11:16-25',
fileLocation('ERROR in src/model/User.ts', '11:16', async),
"TS2339: Property 'firstName' does not exist on type 'User'.",
' 9 | ',
' 10 | function getUserName(user: User): string {',
Expand All @@ -319,7 +320,7 @@ describe('TypeScript Watch API', () => {
' 14 | }',
].join('\n'),
[
'ERROR in src/model/User.ts 11:32-40',
fileLocation('ERROR in src/model/User.ts', '11:32', async),
"TS2339: Property 'lastName' does not exist on type 'User'.",
' 9 | ',
' 10 | function getUserName(user: User): string {',
Expand Down Expand Up @@ -350,7 +351,7 @@ describe('TypeScript Watch API', () => {
errors = await driver.waitForErrors();
expect(errors).toEqual([
[
'ERROR in src/index.ts 1:23-39',
fileLocation('ERROR in src/index.ts', '1:23', async),
"TS2307: Cannot find module './authenticate'.",
" > 1 | import { login } from './authenticate';",
' | ^^^^^^^^^^^^^^^^',
Expand Down Expand Up @@ -394,7 +395,7 @@ describe('TypeScript Watch API', () => {
errors = await driver.waitForErrors();
expect(errors).toEqual([
[
'ERROR in src/index.ts 34:12-16',
fileLocation('ERROR in src/index.ts', '34:12', async),
"TS2339: Property 'role' does not exist on type 'void'.",
' 32 | const user = await login(email, password);',
' 33 | ',
Expand All @@ -405,7 +406,7 @@ describe('TypeScript Watch API', () => {
' 37 | console.log(`Logged in as ${getUserName(user)}`);',
].join('\n'),
[
'ERROR in src/index.ts 35:45-49',
fileLocation('ERROR in src/index.ts', '35:45', async),
"TS2345: Argument of type 'void' is not assignable to parameter of type 'User'.",
' 33 | ',
" 34 | if (user.role === 'admin') {",
Expand All @@ -416,7 +417,7 @@ describe('TypeScript Watch API', () => {
' 38 | }',
].join('\n'),
[
'ERROR in src/index.ts 37:45-49',
fileLocation('ERROR in src/index.ts', '37:45', async),
"TS2345: Argument of type 'void' is not assignable to parameter of type 'User'.",
' 35 | console.log(`Logged in as ${getUserName(user)} [admin].`);',
' 36 | } else {',
Expand Down
5 changes: 3 additions & 2 deletions test/e2e/WebpackIssueScope.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
WEBPACK_CLI_VERSION,
WEBPACK_DEV_SERVER_VERSION,
} from './sandbox/WebpackDevServerDriver';
import { fileLocation } from './fileLocationHelper';

describe('Webpack Issue Scope', () => {
let sandbox: Sandbox;
Expand Down Expand Up @@ -81,7 +82,7 @@ describe('Webpack Issue Scope', () => {
const errors = await driver.waitForErrors();
expect(errors).toEqual([
[
'ERROR in src/notUsedFile.ts 1:7-8',
fileLocation('ERROR in src/notUsedFile.ts', '1:7', async),
"TS2322: Type '\"1\"' is not assignable to type 'number'.",
' > 1 | const x: number = "1";',
' | ^',
Expand All @@ -96,7 +97,7 @@ describe('Webpack Issue Scope', () => {
const errors = await driver.waitForErrors();
expect(errors).toEqual([
[
'ERROR in src/notUsedFile.ts 1:7-8',
fileLocation('ERROR in src/notUsedFile.ts', '1:7', async),
"TS2322: Type '\"1\"' is not assignable to type 'number'.",
' > 1 | const x: number = "1";',
' | ^',
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/WebpackProductionBuild.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ describe('Webpack Production Build', () => {
// first error is from the webpack module resolution
expect.anything(),
[
'ERROR in src/authenticate.ts 1:22-36',
'ERROR in src/authenticate.ts 1:22',
"TS2307: Cannot find module './model/User'.",
" > 1 | import { User } from './model/User';",
' | ^^^^^^^^^^^^^^',
Expand All @@ -129,7 +129,7 @@ describe('Webpack Production Build', () => {
' 4 | const response = await fetch(',
].join('\n'),
[
'ERROR in src/index.ts 2:29-43',
'ERROR in src/index.ts 2:29',
robcrocombe marked this conversation as resolved.
Show resolved Hide resolved
"TS2307: Cannot find module './model/User'.",
" 1 | import { login } from './authenticate';",
" > 2 | import { getUserName } from './model/User';",
Expand Down
8 changes: 8 additions & 0 deletions test/e2e/fileLocationHelper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export function fileLocation(file: string, location: string, async: boolean): string {
// async: true uses our own WebpackFormatter which
// separates file and location with a colon
const locationSeperator = async ? ':' : ' ';

// e.g. `/a/b/c.ts:2:10` or `/a/b/c.ts 2:10`
return `${file}${locationSeperator}${location}`;
}
Loading