Skip to content

Commit 4ef86b5

Browse files
Trottdanielleadams
authored andcommitted
lib: fix JSDoc issues
Updating ESLint and dependencies will start flagging a few additional JSDoc issues. One or two of these are simple fixes. The ESM stuff requires throwing explicitly in JSDoc'ed functions rather than calling another function to throw. I think this makes the code easier to understand--you don't need to know that a particular function that starts with `throwsIf` *might* throw but something that starts with `throwsAnythingElse` will always throw. Instead, it's right there in the code. This also might make it easier to improve stack traces if that's something we'd like to do at some point. PR-URL: #45243 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Jan Krems <jan.krems@gmail.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com>
1 parent 1ba1809 commit 4ef86b5

File tree

4 files changed

+44
-19
lines changed

4 files changed

+44
-19
lines changed

lib/https.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ function createConnection(port, host, options) {
178178
* maxCachedSessions?: number;
179179
* servername?: string;
180180
* }} [options]
181-
* @returns {Agent}
181+
* @constructor
182182
*/
183183
function Agent(options) {
184184
if (!(this instanceof Agent))

lib/internal/modules/esm/assert.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ function validateAssertions(url, format,
8181
// `type` wasn't specified at all.
8282
throw new ERR_IMPORT_ASSERTION_TYPE_MISSING(url, validType);
8383
}
84-
handleInvalidType(url, importAssertions.type);
84+
return handleInvalidType(url, importAssertions.type);
8585
}
8686
}
8787

lib/internal/modules/esm/resolve.js

+42-16
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,8 @@ function finalizeResolution(resolved, base, preserveSymlinks) {
343343
* @param {URL} packageJSONUrl
344344
* @param {string | URL | undefined} base
345345
*/
346-
function throwImportNotDefined(specifier, packageJSONUrl, base) {
347-
throw new ERR_PACKAGE_IMPORT_NOT_DEFINED(
346+
function importNotDefined(specifier, packageJSONUrl, base) {
347+
return new ERR_PACKAGE_IMPORT_NOT_DEFINED(
348348
specifier, packageJSONUrl && fileURLToPath(new URL('.', packageJSONUrl)),
349349
fileURLToPath(base));
350350
}
@@ -354,8 +354,8 @@ function throwImportNotDefined(specifier, packageJSONUrl, base) {
354354
* @param {URL} packageJSONUrl
355355
* @param {string | URL | undefined} base
356356
*/
357-
function throwExportsNotFound(subpath, packageJSONUrl, base) {
358-
throw new ERR_PACKAGE_PATH_NOT_EXPORTED(
357+
function exportsNotFound(subpath, packageJSONUrl, base) {
358+
return new ERR_PACKAGE_PATH_NOT_EXPORTED(
359359
fileURLToPath(new URL('.', packageJSONUrl)), subpath,
360360
base && fileURLToPath(base));
361361
}
@@ -376,14 +376,14 @@ function throwInvalidSubpath(request, match, packageJSONUrl, internal, base) {
376376
base && fileURLToPath(base));
377377
}
378378

379-
function throwInvalidPackageTarget(
379+
function invalidPackageTarget(
380380
subpath, target, packageJSONUrl, internal, base) {
381381
if (typeof target === 'object' && target !== null) {
382382
target = JSONStringify(target, null, '');
383383
} else {
384384
target = `${target}`;
385385
}
386-
throw new ERR_INVALID_PACKAGE_TARGET(
386+
return new ERR_INVALID_PACKAGE_TARGET(
387387
fileURLToPath(new URL('.', packageJSONUrl)), subpath, target,
388388
internal, base && fileURLToPath(base));
389389
}
@@ -393,6 +393,19 @@ const deprecatedInvalidSegmentRegEx = /(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o
393393
const invalidPackageNameRegEx = /^\.|%|\\/;
394394
const patternRegEx = /\*/g;
395395

396+
/**
397+
*
398+
* @param {string} target
399+
* @param {*} subpath
400+
* @param {*} match
401+
* @param {*} packageJSONUrl
402+
* @param {*} base
403+
* @param {*} pattern
404+
* @param {*} internal
405+
* @param {*} isPathMap
406+
* @param {*} conditions
407+
* @returns {URL}
408+
*/
396409
function resolvePackageTargetString(
397410
target,
398411
subpath,
@@ -406,7 +419,7 @@ function resolvePackageTargetString(
406419
) {
407420

408421
if (subpath !== '' && !pattern && target[target.length - 1] !== '/')
409-
throwInvalidPackageTarget(match, target, packageJSONUrl, internal, base);
422+
throw invalidPackageTarget(match, target, packageJSONUrl, internal, base);
410423

411424
if (!StringPrototypeStartsWith(target, './')) {
412425
if (internal && !StringPrototypeStartsWith(target, '../') &&
@@ -426,7 +439,7 @@ function resolvePackageTargetString(
426439
exportTarget, packageJSONUrl, conditions);
427440
}
428441
}
429-
throwInvalidPackageTarget(match, target, packageJSONUrl, internal, base);
442+
throw invalidPackageTarget(match, target, packageJSONUrl, internal, base);
430443
}
431444

432445
if (RegExpPrototypeExec(invalidSegmentRegEx, StringPrototypeSlice(target, 2)) !== null) {
@@ -441,7 +454,7 @@ function resolvePackageTargetString(
441454
emitInvalidSegmentDeprecation(resolvedTarget, request, match, packageJSONUrl, internal, base, true);
442455
}
443456
} else {
444-
throwInvalidPackageTarget(match, target, packageJSONUrl, internal, base);
457+
throw invalidPackageTarget(match, target, packageJSONUrl, internal, base);
445458
}
446459
}
447460

@@ -450,7 +463,7 @@ function resolvePackageTargetString(
450463
const packagePath = new URL('.', packageJSONUrl).pathname;
451464

452465
if (!StringPrototypeStartsWith(resolvedPath, packagePath))
453-
throwInvalidPackageTarget(match, target, packageJSONUrl, internal, base);
466+
throw invalidPackageTarget(match, target, packageJSONUrl, internal, base);
454467

455468
if (subpath === '') return resolved;
456469

@@ -487,6 +500,19 @@ function isArrayIndex(key) {
487500
return keyNum >= 0 && keyNum < 0xFFFF_FFFF;
488501
}
489502

503+
/**
504+
*
505+
* @param {*} packageJSONUrl
506+
* @param {string|[string]} target
507+
* @param {*} subpath
508+
* @param {*} packageSubpath
509+
* @param {*} base
510+
* @param {*} pattern
511+
* @param {*} internal
512+
* @param {*} isPathMap
513+
* @param {*} conditions
514+
* @returns {URL|null}
515+
*/
490516
function resolvePackageTarget(packageJSONUrl, target, subpath, packageSubpath,
491517
base, pattern, internal, isPathMap, conditions) {
492518
if (typeof target === 'string') {
@@ -551,8 +577,8 @@ function resolvePackageTarget(packageJSONUrl, target, subpath, packageSubpath,
551577
} else if (target === null) {
552578
return null;
553579
}
554-
throwInvalidPackageTarget(packageSubpath, target, packageJSONUrl, internal,
555-
base);
580+
throw invalidPackageTarget(packageSubpath, target, packageJSONUrl, internal,
581+
base);
556582
}
557583

558584
/**
@@ -609,7 +635,7 @@ function packageExportsResolve(
609635
);
610636

611637
if (resolveResult == null) {
612-
throwExportsNotFound(packageSubpath, packageJSONUrl, base);
638+
throw exportsNotFound(packageSubpath, packageJSONUrl, base);
613639
}
614640

615641
return resolveResult;
@@ -660,12 +686,12 @@ function packageExportsResolve(
660686
conditions);
661687

662688
if (resolveResult == null) {
663-
throwExportsNotFound(packageSubpath, packageJSONUrl, base);
689+
throw exportsNotFound(packageSubpath, packageJSONUrl, base);
664690
}
665691
return resolveResult;
666692
}
667693

668-
throwExportsNotFound(packageSubpath, packageJSONUrl, base);
694+
throw exportsNotFound(packageSubpath, packageJSONUrl, base);
669695
}
670696

671697
function patternKeyCompare(a, b) {
@@ -745,7 +771,7 @@ function packageImportsResolve(name, base, conditions) {
745771
}
746772
}
747773
}
748-
throwImportNotDefined(name, packageJSONUrl, base);
774+
throw importNotDefined(name, packageJSONUrl, base);
749775
}
750776

751777
/**

lib/internal/validators.js

-1
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,6 @@ function validateBooleanArray(value, name) {
325325
}
326326
}
327327

328-
// eslint-disable-next-line jsdoc/require-returns-check
329328
/**
330329
* @param {*} signal
331330
* @param {string} [name='signal']

0 commit comments

Comments
 (0)