From a53d86ab127d05433e67d21ce7d32b376a2c8721 Mon Sep 17 00:00:00 2001 From: Ashu Date: Thu, 6 Aug 2026 11:53:11 +0530 Subject: [PATCH 1/2] chore: fix JavaScript lint errors (issue #11147) --- .../_tools/github/org-repos/lib/validate.js | 4 +- .../@stdlib/_tools/scripts/transform.js | 143 +++++++++--------- 2 files changed, 75 insertions(+), 72 deletions(-) diff --git a/lib/node_modules/@stdlib/_tools/github/org-repos/lib/validate.js b/lib/node_modules/@stdlib/_tools/github/org-repos/lib/validate.js index 6676d503d2ba..627eff876546 100644 --- a/lib/node_modules/@stdlib/_tools/github/org-repos/lib/validate.js +++ b/lib/node_modules/@stdlib/_tools/github/org-repos/lib/validate.js @@ -56,13 +56,13 @@ function validate( opts, options ) { if ( hasOwnProp( options, 'token' ) ) { opts.token = options.token; if ( !isString( opts.token ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'token', opts.token ) ); + return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'token', opts.token ) ); } } if ( hasOwnProp( options, 'useragent' ) ) { opts.useragent = options.useragent; if ( !isString( opts.useragent ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'useragent', opts.useragent ) ); + return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'useragent', opts.useragent ) ); } } return null; diff --git a/lib/node_modules/@stdlib/_tools/scripts/transform.js b/lib/node_modules/@stdlib/_tools/scripts/transform.js index 7692af0f366f..79f7994f75de 100644 --- a/lib/node_modules/@stdlib/_tools/scripts/transform.js +++ b/lib/node_modules/@stdlib/_tools/scripts/transform.js @@ -48,6 +48,79 @@ var ERROR_NAMES = [ ]; +// FUNCTIONS // + +/** +* Tests whether a variable declaration is for the `@stdlib/string-format` require. +* +* @private +* @param {Object} path - AST node path +* @returns {boolean} boolean indicating whether a variable declaration is for the `@stdlib/string-format` require +*/ +function onStringFormat( path ) { + var node = path.node; + return node.init && + node.init.type === 'CallExpression' && + node.init.callee.name === 'require' && + node.init.arguments[0].value === '@stdlib/string-format'; +} + +/** +* Returns false if the node index is equal to zero and true otherwise. +* +* @private +* @param {Object} path - AST node path +* @param {number} idx - node index +* @returns {boolean} boolean indicating whether to keep the node +*/ +function dropFirst( path, idx ) { + return idx !== 0; +} + +/** +* Deletes the comments associated with a given node. +* +* @private +* @param {Object} path - AST node path +* @returns {void} +*/ +function deleteComment( path ) { + var i; + if ( path.node.comments ) { + for ( i = 0; i < path.node.comments.length; i++ ) { + if ( contains( path.node.comments[ i ].value, '@license Apache-2.0' ) ) { + path.node.comments[ i ].value = '* @license Apache-2.0 '; + } + } + } +} + +/** +* Rewrites a `require` statement to include the `/dist` directory if the module being required starts with `@stdlib`. +* +* @private +* @param {Object} path - AST node path +* @returns {void} +*/ +function rewriteRequire( path ) { + if ( startsWith( path.value.arguments[0].value, '@stdlib' ) ) { + path.value.arguments[0].value += '/dist'; + } +} + +/** +* Tests whether a path is a require call for `@stdlib/error-tools-fmtprodmsg`. +* +* @private +* @param {Object} path - AST node path +* @returns {boolean} boolean indicating whether a path is a require call for `@stdlib/error-tools-fmtprodmsg` +*/ +function hasRequire( path ) { + return path.value.callee.name === 'require' && + path.value.arguments[ 0 ].value === '@stdlib/error-tools-fmtprodmsg'; +} + + // MAIN // /** @@ -121,21 +194,6 @@ function transformer( fileInfo, api ) { return replace( out, RE_INDENT, '\n' ); - /** - * Tests whether a variable declaration is for the `@stdlib/string-format` require. - * - * @private - * @param {Object} path - AST node path - * @returns {boolean} boolean indicating whether a variable declaration is for the `@stdlib/string-format` require - */ - function onStringFormat( path ) { - var node = path.node; - return node.init && - node.init.type === 'CallExpression' && - node.init.callee.name === 'require' && - node.init.arguments[0].value === '@stdlib/string-format'; - } - /** * Assigns the variable name for the `@stdlib/string-format` require. * @@ -147,49 +205,6 @@ function transformer( fileInfo, api ) { formatVar = path.node.id.name; } - /** - * Returns false if the node index is equal to zero and true otherwise. - * - * @private - * @param {Object} path - AST node path - * @param {number} idx - node index - * @returns {boolean} boolean indicating whether to keep the node - */ - function dropFirst( path, idx ) { - return idx !== 0; - } - - /** - * Deletes the comments associated with a given node. - * - * @private - * @param {Object} path - AST node path - * @returns {void} - */ - function deleteComment( path ) { - var i; - if ( path.node.comments ) { - for ( i = 0; i < path.node.comments.length; i++ ) { - if ( contains( path.node.comments[ i ].value, '@license Apache-2.0' ) ) { - path.node.comments[ i ].value = '* @license Apache-2.0 '; - } - } - } - } - - /** - * Rewrites a `require` statement to include the `/dist` directory if the module being required starts with `@stdlib`. - * - * @private - * @param {Object} path - AST node path - * @returns {void} - */ - function rewriteRequire( path ) { - if ( startsWith( path.value.arguments[0].value, '@stdlib' ) ) { - path.value.arguments[0].value += '/dist'; - } - } - /** * Callback invoked upon finding a string literal. * @@ -248,18 +263,6 @@ function transformer( fileInfo, api ) { } } } - - /** - * Tests whether a path is a require call for `@stdlib/error-tools-fmtprodmsg`. - * - * @private - * @param {Object} path - AST node path - * @returns {boolean} boolean indicating whether a path is a require call for `@stdlib/error-tools-fmtprodmsg` - */ - function hasRequire( path ) { - return path.value.callee.name === 'require' && - path.value.arguments[ 0 ].value === '@stdlib/error-tools-fmtprodmsg'; - } } From 5facdc1cde4b7934f196b722a96e37f9b9217e85 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 6 Aug 2026 00:33:14 -0700 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../@stdlib/_tools/scripts/transform.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/_tools/scripts/transform.js b/lib/node_modules/@stdlib/_tools/scripts/transform.js index 79f7994f75de..eb5d885e21b3 100644 --- a/lib/node_modules/@stdlib/_tools/scripts/transform.js +++ b/lib/node_modules/@stdlib/_tools/scripts/transform.js @@ -59,10 +59,12 @@ var ERROR_NAMES = [ */ function onStringFormat( path ) { var node = path.node; - return node.init && + return ( + node.init && node.init.type === 'CallExpression' && node.init.callee.name === 'require' && - node.init.arguments[0].value === '@stdlib/string-format'; + node.init.arguments[0].value === '@stdlib/string-format' + ); } /** @@ -103,8 +105,8 @@ function deleteComment( path ) { * @returns {void} */ function rewriteRequire( path ) { - if ( startsWith( path.value.arguments[0].value, '@stdlib' ) ) { - path.value.arguments[0].value += '/dist'; + if ( startsWith( path.value.arguments[ 0 ].value, '@stdlib' ) ) { + path.value.arguments[ 0 ].value += '/dist'; } } @@ -116,8 +118,10 @@ function rewriteRequire( path ) { * @returns {boolean} boolean indicating whether a path is a require call for `@stdlib/error-tools-fmtprodmsg` */ function hasRequire( path ) { - return path.value.callee.name === 'require' && - path.value.arguments[ 0 ].value === '@stdlib/error-tools-fmtprodmsg'; + return ( + path.value.callee.name === 'require' && + path.value.arguments[ 0 ].value === '@stdlib/error-tools-fmtprodmsg' + ); }