Skip to content

Commit

Permalink
feat: clean base
Browse files Browse the repository at this point in the history
  • Loading branch information
skarab42 committed Jul 10, 2022
1 parent e5f38f9 commit ac9bf40
Show file tree
Hide file tree
Showing 25 changed files with 117 additions and 675 deletions.
36 changes: 0 additions & 36 deletions src/api/tsd/index.ts

This file was deleted.

11 changes: 0 additions & 11 deletions src/api/tssert/index.ts

This file was deleted.

17 changes: 12 additions & 5 deletions src/error.ts → src/common/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,30 @@ export enum ErrorCode {
UNEXPECTED_ERROR,
TSCONFIG_FILE_NOT_FOUND,
TSCONFIG_FILE_NOT_READABLE,
MULTIPLE_ASSERTION_API_IN_SAME_FILE_NOT_ALLOWED,
TSCONFIG_FILE_PARSE_ERROR,
}

export const errorMessages: Record<ErrorCode, string> = {
[ErrorCode.UNEXPECTED_ERROR]: 'Unexpected error: {message}',
[ErrorCode.TSCONFIG_FILE_NOT_FOUND]: 'TS config file not found. File name: {configName} - Search path: {searchPath}',
[ErrorCode.TSCONFIG_FILE_NOT_READABLE]: 'TS config file not readable or empty. File path: {filePath}',
[ErrorCode.MULTIPLE_ASSERTION_API_IN_SAME_FILE_NOT_ALLOWED]:
'The use of multiple type assertion APIs in the same file is not allowed. The APIs detected are [{apiNames}], please review your test.',
[ErrorCode.TSCONFIG_FILE_PARSE_ERROR]: 'An error occurred during the parsing of the TS config file. {message}',
};

export function errorMessage(code: ErrorCode, data?: Record<string, unknown>) {
export function errorMessage(code: ErrorCode, data?: Record<string, unknown>): string {
let message = errorMessages[code];

Object.entries(data ?? {}).forEach(([index, value]) => {
message = message.replace(new RegExp(`{${index}}`, 'g'), String(value));
});

return new Error(message);
return message;
}

export function createError(code: ErrorCode, data?: Record<string, unknown>): Error {
return new Error(errorMessage(code, data));
}

export function throwError(code: ErrorCode, data?: Record<string, unknown>): never {
throw createError(code, data);
}
2 changes: 0 additions & 2 deletions src/plugin/api/index.ts

This file was deleted.

57 changes: 0 additions & 57 deletions src/plugin/api/tsd/assert.ts

This file was deleted.

22 changes: 0 additions & 22 deletions src/plugin/api/tsd/index.ts

This file was deleted.

26 changes: 0 additions & 26 deletions src/plugin/api/tsd/util.ts

This file was deleted.

25 changes: 0 additions & 25 deletions src/plugin/api/tssert/assert.ts

This file was deleted.

27 changes: 0 additions & 27 deletions src/plugin/api/tssert/index.ts

This file was deleted.

52 changes: 0 additions & 52 deletions src/plugin/api/tssert/util.ts

This file was deleted.

26 changes: 0 additions & 26 deletions src/plugin/api/types.ts

This file was deleted.

32 changes: 0 additions & 32 deletions src/plugin/error.ts

This file was deleted.

28 changes: 0 additions & 28 deletions src/plugin/identifiers.ts

This file was deleted.

Loading

0 comments on commit ac9bf40

Please sign in to comment.