Skip to content

Commit bb22fd8

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 4bde587 commit bb22fd8

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
@@ -342,8 +342,8 @@ function finalizeResolution(resolved, base, preserveSymlinks) {
342342
* @param {URL} packageJSONUrl
343343
* @param {string | URL | undefined} base
344344
*/
345-
function throwImportNotDefined(specifier, packageJSONUrl, base) {
346-
throw new ERR_PACKAGE_IMPORT_NOT_DEFINED(
345+
function importNotDefined(specifier, packageJSONUrl, base) {
346+
return new ERR_PACKAGE_IMPORT_NOT_DEFINED(
347347
specifier, packageJSONUrl && fileURLToPath(new URL('.', packageJSONUrl)),
348348
fileURLToPath(base));
349349
}
@@ -353,8 +353,8 @@ function throwImportNotDefined(specifier, packageJSONUrl, base) {
353353
* @param {URL} packageJSONUrl
354354
* @param {string | URL | undefined} base
355355
*/
356-
function throwExportsNotFound(subpath, packageJSONUrl, base) {
357-
throw new ERR_PACKAGE_PATH_NOT_EXPORTED(
356+
function exportsNotFound(subpath, packageJSONUrl, base) {
357+
return new ERR_PACKAGE_PATH_NOT_EXPORTED(
358358
fileURLToPath(new URL('.', packageJSONUrl)), subpath,
359359
base && fileURLToPath(base));
360360
}
@@ -375,14 +375,14 @@ function throwInvalidSubpath(request, match, packageJSONUrl, internal, base) {
375375
base && fileURLToPath(base));
376376
}
377377

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

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

407420
if (subpath !== '' && !pattern && target[target.length - 1] !== '/')
408-
throwInvalidPackageTarget(match, target, packageJSONUrl, internal, base);
421+
throw invalidPackageTarget(match, target, packageJSONUrl, internal, base);
409422

410423
if (!StringPrototypeStartsWith(target, './')) {
411424
if (internal && !StringPrototypeStartsWith(target, '../') &&
@@ -425,7 +438,7 @@ function resolvePackageTargetString(
425438
exportTarget, packageJSONUrl, conditions);
426439
}
427440
}
428-
throwInvalidPackageTarget(match, target, packageJSONUrl, internal, base);
441+
throw invalidPackageTarget(match, target, packageJSONUrl, internal, base);
429442
}
430443

431444
if (RegExpPrototypeExec(invalidSegmentRegEx, StringPrototypeSlice(target, 2)) !== null) {
@@ -440,7 +453,7 @@ function resolvePackageTargetString(
440453
emitInvalidSegmentDeprecation(resolvedTarget, request, match, packageJSONUrl, internal, base, true);
441454
}
442455
} else {
443-
throwInvalidPackageTarget(match, target, packageJSONUrl, internal, base);
456+
throw invalidPackageTarget(match, target, packageJSONUrl, internal, base);
444457
}
445458
}
446459

@@ -449,7 +462,7 @@ function resolvePackageTargetString(
449462
const packagePath = new URL('.', packageJSONUrl).pathname;
450463

451464
if (!StringPrototypeStartsWith(resolvedPath, packagePath))
452-
throwInvalidPackageTarget(match, target, packageJSONUrl, internal, base);
465+
throw invalidPackageTarget(match, target, packageJSONUrl, internal, base);
453466

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

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

502+
/**
503+
*
504+
* @param {*} packageJSONUrl
505+
* @param {string|[string]} target
506+
* @param {*} subpath
507+
* @param {*} packageSubpath
508+
* @param {*} base
509+
* @param {*} pattern
510+
* @param {*} internal
511+
* @param {*} isPathMap
512+
* @param {*} conditions
513+
* @returns {URL|null}
514+
*/
489515
function resolvePackageTarget(packageJSONUrl, target, subpath, packageSubpath,
490516
base, pattern, internal, isPathMap, conditions) {
491517
if (typeof target === 'string') {
@@ -550,8 +576,8 @@ function resolvePackageTarget(packageJSONUrl, target, subpath, packageSubpath,
550576
} else if (target === null) {
551577
return null;
552578
}
553-
throwInvalidPackageTarget(packageSubpath, target, packageJSONUrl, internal,
554-
base);
579+
throw invalidPackageTarget(packageSubpath, target, packageJSONUrl, internal,
580+
base);
555581
}
556582

557583
/**
@@ -608,7 +634,7 @@ function packageExportsResolve(
608634
);
609635

610636
if (resolveResult == null) {
611-
throwExportsNotFound(packageSubpath, packageJSONUrl, base);
637+
throw exportsNotFound(packageSubpath, packageJSONUrl, base);
612638
}
613639

614640
return resolveResult;
@@ -659,12 +685,12 @@ function packageExportsResolve(
659685
conditions);
660686

661687
if (resolveResult == null) {
662-
throwExportsNotFound(packageSubpath, packageJSONUrl, base);
688+
throw exportsNotFound(packageSubpath, packageJSONUrl, base);
663689
}
664690
return resolveResult;
665691
}
666692

667-
throwExportsNotFound(packageSubpath, packageJSONUrl, base);
693+
throw exportsNotFound(packageSubpath, packageJSONUrl, base);
668694
}
669695

670696
function patternKeyCompare(a, b) {
@@ -744,7 +770,7 @@ function packageImportsResolve(name, base, conditions) {
744770
}
745771
}
746772
}
747-
throwImportNotDefined(name, packageJSONUrl, base);
773+
throw importNotDefined(name, packageJSONUrl, base);
748774
}
749775

750776
/**

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)