From 2d8b35291dd14f82af0e1d02787e316462ca3918 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Fri, 10 Feb 2023 00:59:56 +0100 Subject: [PATCH] Fix incorrect JSDoc async return annotations The return type of an async function should be documented as a Promise of what the function returns as this is what JSDoc expects. --- packages/lib/command.js | 6 +++--- packages/lib/factorio/export.js | 8 ++++---- packages/lib/factorio/server.js | 10 +++++----- packages/lib/file_ops.js | 6 +++--- packages/lib/helpers.js | 2 +- packages/lib/link/messages.js | 2 +- packages/lib/logging_utils.js | 4 ++-- packages/lib/plugin.js | 2 +- packages/lib/plugin_loader.js | 8 ++++---- packages/master/src/Master.js | 6 +++--- packages/slave/src/Instance.js | 8 ++++---- packages/slave/src/Slave.js | 4 ++-- 12 files changed, 33 insertions(+), 33 deletions(-) diff --git a/packages/lib/command.js b/packages/lib/command.js index f0738e8b..85b0f864 100644 --- a/packages/lib/command.js +++ b/packages/lib/command.js @@ -142,7 +142,7 @@ class CommandTree { * * @param {module:lib/link.Link} client - link to master server to query slave on. * @param {string} slaveName - string with name or id of slave. - * @returns {number} slave ID. + * @returns {Promise} slave ID. * @static */ async function resolveSlave(client, slaveName) { @@ -174,7 +174,7 @@ async function resolveSlave(client, slaveName) { * * @param {module:lib/link.Link} client - link to master server to query instance on. * @param {string} instanceName - string with name or id of instance. - * @returns {number} instance ID. + * @returns {Promise} instance ID. * @static */ async function resolveInstance(client, instanceName) { @@ -239,7 +239,7 @@ async function resolveModPack(client, modPackName) { * * @param {module:lib/link.Link} client - link to master server to query role on. * @param {string} roleName - string with name or id of role. - * @returns {Object} Role info. + * @returns {Promise} Role info. * @static */ async function retrieveRole(client, roleName) { diff --git a/packages/lib/factorio/export.js b/packages/lib/factorio/export.js index 22c74de9..f30d33bf 100644 --- a/packages/lib/factorio/export.js +++ b/packages/lib/factorio/export.js @@ -67,7 +67,7 @@ async function loadZip(server, modVersions, mod) { * The server to load the file from. * @param {Map} modVersions - Mapping of mod to version used. * @param {string} modPath - Factorio style path to the file to load. - * @returns {?Buffer} The content of the file or null if not found. + * @returns {Promise} The content of the file or null if not found. * @memberof module:lib/factorio * @private * @inner @@ -255,7 +255,7 @@ function filterItems(prototypes) { * @param {Map} modVersions - * Mapping of mod name to versions to get icons from. * @param {Array} items - Array of item prototypes. - * @return {{itemSheet: Jimp, itemData: Map}} + * @return {Promise<{itemSheet: Jimp, itemData: Map}>} * Item spritesheet and metadata. * @memberof module:lib/factorio * @private @@ -327,7 +327,7 @@ async function exportItems(server, modVersions, items) { * Mapping of mod name to version to export locale from. * @param {Array} modOrder - Load order of the mods. * @param {string} languageCode - Language to export locale for. - * @returns {Map} merged locale information + * @returns {Promise>} merged locale information * @memberof module:lib/factorio * @private * @inner @@ -379,7 +379,7 @@ async function exportLocale(server, modVersions, modOrder, languageCode) { * * @param {module:lib/factorio.FactorioServer} server - * The server to export the data from. - * @returns {JSZip} zip file with exported data. + * @returns {Promise} zip file with exported data. * @memberof module:lib/factorio */ async function exportData(server) { diff --git a/packages/lib/factorio/server.js b/packages/lib/factorio/server.js index a199f04e..83451086 100644 --- a/packages/lib/factorio/server.js +++ b/packages/lib/factorio/server.js @@ -86,7 +86,7 @@ function versionOrder(a, b) { * @param {string} targetVersion - * Version to look for, supports the special value "latest" for the * latest version available. - * @returns {Array} Array with path to data dir and version found. + * @returns {Promise} Array with path to data dir and version found. * @memberof module:lib/factorio * @private * @inner @@ -163,7 +163,7 @@ function randomDynamicPort() { * the given length. * * @param {number} length - the length of the password to generate. - * @return {string} password of the given length + * @return {Promise} password of the given length * @memberof module:lib/factorio * @private * @inner @@ -902,7 +902,7 @@ class FactorioServer extends events.EventEmitter { * @param {boolean} expectEmpty - * if true throw if the response is not empty. Useful for detecting * errors that might have been sent in response. - * @returns {string} response from server. + * @returns {Promise} response from server. */ async sendRcon(message, expectEmpty) { this._check(["running", "stopping"]); @@ -1036,7 +1036,7 @@ class FactorioServer extends events.EventEmitter { * Ensures achievements are disabled on the save that's running. This is * necessary in order to run any commands at all. * - * @returns {boolean} + * @returns {Promise} * True if acheivements got disabled and false if they already where * disabled. */ @@ -1104,7 +1104,7 @@ class FactorioServer extends events.EventEmitter { * * Loads server-settings.example.json from the data dir. * - * @returns {object} the parsed server-settings. + * @returns {Promise} the parsed server-settings. */ async exampleSettings() { return JSON.parse(await fs.readFile(this.dataPath("server-settings.example.json"), "utf-8")); diff --git a/packages/lib/file_ops.js b/packages/lib/file_ops.js index e0b4639d..0e14b39d 100644 --- a/packages/lib/file_ops.js +++ b/packages/lib/file_ops.js @@ -13,7 +13,7 @@ const crypto = require("crypto"); // needed for getTempFile * @param {function(string): boolean} filter - * Optional function to filter out files to ignore. Should return true * if the file is to be considered. - * @returns {?string} + * @returns {Promise} * Name of the file with the newest timestamp or null if the * directory contains no files. */ @@ -80,8 +80,8 @@ async function directorySize(directory) { * @param {string} directory - directory to check in. * @param {string} name - file name to check for, may have extension. * @param {string} extension - dot extension used for the file name. - * @returns {string} modified name with extension that likely does not exist - * in the folder + * @returns {Promise} modified name with extension that likely does + * not exist in the folder */ async function findUnusedName(directory, name, extension = "") { if (extension && name.endsWith(extension)) { diff --git a/packages/lib/helpers.js b/packages/lib/helpers.js index 3738666e..9069a198 100644 --- a/packages/lib/helpers.js +++ b/packages/lib/helpers.js @@ -63,7 +63,7 @@ async function timeout(promise, time, timeoutResult) { * returns all the data which was read from the stream. * * @param {Readable} stream - byte stream to read to the end. - * @returns {Buffer} content of the stream. + * @returns {Promise} content of the stream. * @static */ async function readStream(stream) { diff --git a/packages/lib/link/messages.js b/packages/lib/link/messages.js index 3da48aec..21a063db 100644 --- a/packages/lib/link/messages.js +++ b/packages/lib/link/messages.js @@ -255,7 +255,7 @@ class Request extends Message { * * @param {module:lib/link.Link} link - Link to send request over. * @param {Object} data - Data to send with the request. - * @returns {object} response data + * @returns {Promise} response data */ async send(link, data = {}) { // XXX validate link target/source? diff --git a/packages/lib/logging_utils.js b/packages/lib/logging_utils.js index 37e818e7..d23a80cb 100644 --- a/packages/lib/logging_utils.js +++ b/packages/lib/logging_utils.js @@ -205,7 +205,7 @@ class LogIndex { * module:lib/logging_utils.LogIndex#save}. * * @param {string} logDirectory - Path to directory to load from. - * @returns {module:lib/logging_utils.LogIndex} loaded or created log index. + * @returns {Promise} loaded or created log index. */ static async load(logDirectory) { try { @@ -391,7 +391,7 @@ function logFilter({ all, master, slave_ids, instance_ids, max_level }) { * Filter to limit logs by. * @param {module:lib/logging_utils.LogIndex=} index - * Index to speed up query with. - * @returns {Array} log entries matching the filter + * @returns {Promise>} log entries matching the filter */ async function queryLog(logDirectory, filter, index) { let files = (await fs.readdir(logDirectory)).filter(entry => logFileGlob.test(entry)); diff --git a/packages/lib/plugin.js b/packages/lib/plugin.js index ac2d3ffb..4b56b976 100644 --- a/packages/lib/plugin.js +++ b/packages/lib/plugin.js @@ -812,7 +812,7 @@ function attachPluginMessages(link, plugin) { * Mapping of plugin names to plugins to invoke the hook on. * @param {string} hook - Name of hook to invoke. * @param {...*} args - Arguments to pass on to the hook. - * @returns {Array} Non-empty return values from the hooks. + * @returns {Promise} Non-empty return values from the hooks. */ async function invokeHook(plugins, hook, ...args) { let results = []; diff --git a/packages/lib/plugin_loader.js b/packages/lib/plugin_loader.js index b5d38eeb..6ec0310a 100644 --- a/packages/lib/plugin_loader.js +++ b/packages/lib/plugin_loader.js @@ -19,7 +19,7 @@ const path = require("path"); * * @param {Map} pluginList - * Mapping of plugin name to require path for the plugins to load. - * @returns {Array} Array of plugin info modules. + * @returns {Promise>} Array of plugin info modules. * @static */ async function loadPluginInfos(pluginList) { @@ -71,7 +71,7 @@ function loadPluginClass(entrypointName, className, pluginClass, pluginInfo) { * @param {Object} pluginInfo - * Plugin info object returned from {@link * module:lib/plugin_loader.loadPluginInfos} to load class from. - * @returns {function} plugin class + * @returns {Promise} plugin class * @static */ async function loadMasterPluginClass(pluginInfo) { @@ -84,7 +84,7 @@ async function loadMasterPluginClass(pluginInfo) { * @param {Object} pluginInfo - * Plugin info object returned from {@link * module:lib/plugin_loader.loadPluginInfos} to load class from. - * @returns {function} plugin class + * @returns {Promise} plugin class * @static */ async function loadInstancePluginClass(pluginInfo) { @@ -97,7 +97,7 @@ async function loadInstancePluginClass(pluginInfo) { * @param {Object} pluginInfo - * Plugin info object returned from {@link * module:lib/plugin_loader.loadPluginInfos} to load class from. - * @returns {function} plugin class + * @returns {Promise} plugin class * @static */ async function loadControlPluginClass(pluginInfo) { diff --git a/packages/master/src/Master.js b/packages/master/src/Master.js index be8b5b2a..6fb10989 100644 --- a/packages/master/src/Master.js +++ b/packages/master/src/Master.js @@ -484,7 +484,7 @@ class Master { * @param {module:lib/logging_utils~QueryLogFilter} filter - * Filter to limit entries with. Note that only the master log can * be queried from this function. - * @returns {Array} log entries matching the filter + * @returns {Promise>} log entries matching the filter */ async queryMasterLog(filter) { return await libLoggingUtils.queryLog( @@ -497,7 +497,7 @@ class Master { * * @param {module:lib/logging_utils~QueryLogFilter} filter - * Filter to limit entries with. - * @returns {Array} log entries matching the filter + * @returns {Promise>} log entries matching the filter */ async queryClusterLog(filter) { return await libLoggingUtils.queryLog( @@ -811,7 +811,7 @@ class Master { * @param {object} data - Data to pass with the request. * @param {number} data.instance_id - * ID of instance to send this request towards - * @returns {object} data returned from the request. + * @returns {Promise} data returned from the request. */ async forwardRequestToInstance(request, data) { let instance = this.getRequestInstance(data.instance_id); diff --git a/packages/slave/src/Instance.js b/packages/slave/src/Instance.js index c698f955..a3909c07 100644 --- a/packages/slave/src/Instance.js +++ b/packages/slave/src/Instance.js @@ -193,7 +193,7 @@ class Instance extends libLink.Link { /** * Mod pack currently running on this instance - * @type {module:lib/data.ModPack>} + * @type {module:lib/data.ModPack} */ this.activeModPack = undefined; @@ -538,7 +538,7 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " "); * entries from the given settings object. * * @param {Object} overrides - Server settings to override. - * @returns {Object} + * @returns {Promise} * server example settings with the given settings applied over it. */ async resolveServerSettings(overrides) { @@ -699,10 +699,10 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " "); * * Creates a new save if no save is passed and patches it with modules. * - * @param {String|null} saveName - + * @param {string|null} saveName - * Save to prepare from the instance saves directory. Creates a new * save if null. - * @returns {String} Name of the save prepared. + * @returns {Promise} Name of the save prepared. */ async prepareSave(saveName) { // Use latest save if no save was specified diff --git a/packages/slave/src/Slave.js b/packages/slave/src/Slave.js index c8b85f57..f3af8dca 100644 --- a/packages/slave/src/Slave.js +++ b/packages/slave/src/Slave.js @@ -41,7 +41,7 @@ function checkRequestSaveName(name) { * instanceInfo objects. * * @param {string} instancesDir - Directory containing instances - * @returns {Map} + * @returns {Promise>} * mapping between instance id and information about this instance. * @private */ @@ -379,7 +379,7 @@ class Slave extends libLink.Link { * Initialize and connect an unloaded instance * * @param {number} instanceId - ID of instance to initialize. - * @returns {module:slave/slave~InstanceConnection} connection to instance. + * @returns {Promise} connection to instance. */ async _connectInstance(instanceId) { let instanceInfo = this.getRequestInstanceInfo(instanceId);