Skip to content

Commit 5a96558

Browse files
committed
chore: project qa
Signed-off-by: Lexus Drumgold <[email protected]>
1 parent d82b2bf commit 5a96558

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

.eslintrc.base.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ const config = {
463463
'no-array-constructor': 0,
464464
'no-case-declarations': 0,
465465
'no-duplicate-imports': 0,
466+
'no-empty': [2, { allowEmptyCatch: true }],
466467
'no-empty-function': 0,
467468
'no-ex-assign': 0,
468469
'no-invalid-this': 0,

src/internal/__tests__/format-message.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,15 @@ describe('unit:internal/formatMessage', () => {
4848
const cases: Parameters<typeof testSubject>[] = [
4949
[
5050
ErrorCode.ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED,
51-
'Import assertion type "%s" is unsupported'
51+
'Import assertion type "%s" is unsupported',
52+
[]
5253
],
5354
[
5455
ErrorCode.ERR_UNKNOWN_FILE_EXTENSION,
5556
(ext: string, path: string) => {
5657
return `Unknown file extension "${ext}" for ${path}`
57-
}
58+
},
59+
[]
5860
]
5961
]
6062

src/internal/format-message.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,24 @@ import { format } from 'node-inspect-extracted'
1111
/**
1212
* Formats an error message.
1313
*
14+
* [1]: https://nodejs.org/api/util.html#utilformatformat-args
15+
*
1416
* @see https://nodejs.org/api/util.html#utilformatformat-args
1517
*
18+
* @template M - Error message type
19+
*
1620
* @param {ErrorCode} code - Node.js error code
1721
* @param {MessageFn | string} msg - Error message or message function
18-
* @param {any[]} [args=[]] - `util.format` arguments if `msg` is a string, or
19-
* `msg` parameters if `msg` is a function
22+
* @param {any[] | Parameters<M>} args - `msg` params if `msg` is a function;
23+
* [`util.format`][1] arguments if `msg` is a string
2024
* @param {Error} [self=new Error()] - Error used as `this` argument in `msg`
2125
* @return {string} Formatted error message
2226
* @throws {Error} If `args` length is invalid
2327
*/
24-
function formatMessage(
28+
function formatMessage<M extends MessageFn | string = MessageFn | string>(
2529
code: ErrorCode,
26-
msg: MessageFn | string,
27-
args: any[] = [],
30+
msg: M,
31+
args: M extends MessageFn ? Parameters<M> : any[],
2832
self: Error = new Error()
2933
): string {
3034
/**

0 commit comments

Comments
 (0)