From 759d63bc914d288a011d7c5ac9842ff232cfa204 Mon Sep 17 00:00:00 2001 From: Kunal Nagpal Date: Mon, 16 Jul 2018 06:07:44 +0530 Subject: [PATCH] Corrected lint errors in singleton lib files :shirt: --- lib/constants.js | 10 +++++----- lib/index.js | 46 +++++++++++++++++++++++----------------------- lib/url.js | 11 ++++++++--- lib/util.js | 23 +++++++++++------------ 4 files changed, 47 insertions(+), 43 deletions(-) diff --git a/lib/constants.js b/lib/constants.js index 4fbffb63..c84e351a 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -1,5 +1,5 @@ -module.exports.SCHEMA_V2_URL = 'https://schema.getpostman.com/json/collection/v2.0.0/collection.json'; -module.exports.SCHEMA_V2_1_0_URL = 'https://schema.getpostman.com/json/collection/v2.1.0/collection.json'; -module.exports.SCHEMA_V1_URL = 'https://schema.getpostman.com/json/collection/v1.0.0/collection.json'; -module.exports.PREREQUEST_EXT = '_preRequestScript'; -module.exports.TESTS_EXT = '_tests'; +exports.SCHEMA_V2_URL = 'https://schema.getpostman.com/json/collection/v2.0.0/collection.json'; +exports.SCHEMA_V2_1_0_URL = 'https://schema.getpostman.com/json/collection/v2.1.0/collection.json'; +exports.SCHEMA_V1_URL = 'https://schema.getpostman.com/json/collection/v1.0.0/collection.json'; +exports.PREREQUEST_EXT = '_preRequestScript'; +exports.TESTS_EXT = '_tests'; diff --git a/lib/index.js b/lib/index.js index d6bb96fe..a62dbadc 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,19 +1,19 @@ -var converter = require('./converters'), - normalizers = require('./normalizers'), +var semver = require('semver'), + util = require('./util'), - semver = require('semver'); + converter = require('./converters'), + normalizers = require('./normalizers'); module.exports = { /** * Converts a Collection between different versions, based on the given input. * - * @param collection - * @param options - * @param options.outputVersion - * @param options.inputVersion - * @param {Function=} callback - * @returns {*} + * @param {Object} collection - The collection object to be converted. + * @param {Object} options - The set of conversion options. + * @param {String} options.outputVersion - The version to convert to. + * @param {String} options.inputVersion - The version to convert from. + * @param {Function} callback - The function invoked to mark the completion of the conversion process. */ convert: function (collection, options, callback) { if (!options.outputVersion || !semver.valid(options.outputVersion, true)) { @@ -38,8 +38,8 @@ module.exports = { /** * Checks whether the given object is a v1 collection * - * @param object - * @returns {Boolean} + * @param {Object} object - The Object to check for v1 collection compliance. + * @returns {Boolean} - A boolean result indicating whether or not the passed object was a v1 collection. */ isv1: function (object) { return Boolean(object.name && object.order && object.requests); @@ -48,8 +48,8 @@ module.exports = { /** * Checks whether the given object is a v2 collection * - * @param object - * @returns {Boolean} + * @param {Object} object - The Object to check for v2 collection compliance. + * @returns {Boolean} - A boolean result indicating whether or not the passed object was a v2 collection. */ isv2: function (object) { return Boolean(object && object.info && object.info.schema); @@ -58,11 +58,11 @@ module.exports = { /** * Converts a single V1 request to a V2 Item, or a V2 item to a single V1 request. * - * @param object - A V1 request or a V2 item. - * @param options - * @param options.outputVersion - * @param options.inputVersion - * @param callback + * @param {Object} object - A V1 request or a V2 item. + * @param {Object} options - The set of options for response conversion. + * @param {String} options.outputVersion - The version to convert to. + * @param {String} options.inputVersion - The version to convert from. + * @param {Function} callback - The function invoked to mark the completion of the conversion process. */ convertSingle: function (object, options, callback) { if (!options.outputVersion || !semver.valid(options.outputVersion, true)) { @@ -78,11 +78,11 @@ module.exports = { /** * Converts a single V1 request to a V2 Item, or a V2 item to a single V1 request. * - * @param object - A V1 request or a V2 item. - * @param options - * @param options.outputVersion - * @param options.inputVersion - * @param callback + * @param {Object} object - A V1 request or a V2 item. + * @param {Object} options - The set of options for response conversion. + * @param {String} options.outputVersion - The version to convert to. + * @param {String} options.inputVersion - The version to convert from. + * @param {Function} callback - The function invoked to mark the completion of the conversion process. */ convertResponse: function (object, options, callback) { if (!options.outputVersion || !semver.valid(options.outputVersion, true)) { diff --git a/lib/url.js b/lib/url.js index 48a57e80..7f395ada 100644 --- a/lib/url.js +++ b/lib/url.js @@ -10,8 +10,8 @@ var _ = require('lodash').noConflict(), /** * Unparses a single query param into a string. * - * @param param - * @returns {string} + * @param {Object} param - The query parameter object to be unparsed. + * @returns {String} - The unparsed query string. */ unparseQueryParam = function (param) { if (!param || param.disabled) { return ''; } @@ -21,6 +21,7 @@ var _ = require('lodash').noConflict(), // @note - The "param.value != null" check is basically !_.isNil(). (isNil is not available in lodash v3.x) // This is the right thing to use here. (param.value !== null) && (unparsed += ('=' + (param.value || ''))); + return unparsed; }, @@ -45,6 +46,7 @@ var _ = require('lodash').noConflict(), splitDomain: /\.(?![^{]*\}{2})/g }; +/* eslint-disable object-shorthand */ module.exports = { parse: function (url) { url = _.trim(url); @@ -85,7 +87,8 @@ module.exports = { url = url.substr(p.path.length); p.path && (p.path = p.path.replace(regexes.trimPath, MATCH_1)); // remove leading slash for valid path // if path is blank string, we set it to undefined, if '/' then single blank string array - p.path = !p.path ? undefined : (p.path === PATH_SEPARATOR ? [E] : p.path.split(PATH_SEPARATOR)); + // eslint-disable-next-line no-nested-ternary + p.path = p.path ? (p.path === PATH_SEPARATOR ? [E] : p.path.split(PATH_SEPARATOR)) : undefined; } // extract the query string @@ -103,6 +106,7 @@ module.exports = { // extract the hash p.hash = _.get(url.match(regexes.extractSearch), GET_1); + return p; }, @@ -141,6 +145,7 @@ module.exports = { accumulator += '&'; } accumulator += unparsed; + return accumulator; }, ''); diff --git a/lib/util.js b/lib/util.js index 4ac560b0..4af3d896 100644 --- a/lib/util.js +++ b/lib/util.js @@ -1,9 +1,9 @@ +/* eslint-disable object-shorthand */ var _ = require('lodash'), url = require('./url'), - rnd = Math.random, - util; + rnd = Math.random; -util = { +module.exports = { // @todo: Add support for a `json` type once it becomes available typeMap: { string: 'string', @@ -30,6 +30,7 @@ util = { // in other cases (if "n" is 9,14,19,24) insert "-" // eslint-disable-next-line curly for (r = n = E; n++ < 36; r += n * 51 & 52 ? (n ^ 15 ? 8 ^ rnd() * (n ^ 20 ? 16 : 4) : 4).toString(16) : H); + return r; }, @@ -52,7 +53,7 @@ util = { * instead of being deleted. * @param {Object} [modifiers] - A set of behavioral modifiers for variable handling. * @param {Boolean} [modifiers.isV1=false] - When set to true, looks for the pathVariableData property as well. - * @return {Array} - The set of sanitized entity level variables. + * @returns {Object[]} - The set of sanitized entity level variables. */ handleVars: function (entity, options, modifiers) { !options && (options = {}); @@ -65,7 +66,7 @@ util = { fallback = options.fallback && options.fallback.values, result = _.map(source || fallback, function (item) { var result = { - id: !(noDefaults || item.id) ? self.uid() : item.id, + id: (noDefaults || item.id) ? item.id : self.uid(), key: item.key || item.id, value: item.value, type: (item.type === 'text' ? 'string' : item.type) || self.typeMap[typeof item.value] || 'any' @@ -88,7 +89,7 @@ util = { * @param {Object} entity - The wrapped auth entity to be cleaned. * @param {?Object} options - The set of options for the current auth cleansing operation. * @param {?Boolean} [options.excludeNoauth=false] - When set to true, noauth is set to null. - * @returns {Object} - The processed auth data. + * @returns {Object|*} - The processed auth data. */ cleanAuth: function (entity, options) { !options && (options = {}); @@ -115,7 +116,7 @@ util = { /** * Transforms an array of auth params to their object equivalent. * - * @param entity {Object} - The wrapper object for the array of auth params. + * @param {Object} entity - The wrapper object for the array of auth params. * @param {?Object} options - The set of options for the current auth cleansing operation. * @param {?Boolean} [options.excludeNoauth=false] - When set to true, noauth is set to null. * @returns {*} @@ -142,7 +143,7 @@ util = { /** * Transforms an object of auth params to their array equivalent. * - * @param entity {Object} - The wrapper object for the array of auth params. + * @param {Object} entity - The wrapper object for the array of auth params. * @param {?Object} options - The set of options for the current auth cleansing operation. * @param {?Boolean} [options.excludeNoauth=false] - When set to true, noauth is set to null. * @returns {*} @@ -177,7 +178,7 @@ util = { /** * Sanitizes a collection SDK compliant auth list. * - * @param entity {Object} - The wrapper entity for the auth manifest. + * @param {Object} entity - The wrapper entity for the auth manifest. * @param {?Object} options - The set of options for the current auth cleansing operation. * @param {?Boolean} [options.excludeNoauth=false] - When set to true, noauth is set to null. * @returns {Object[]} - An array of raw collection SDK compliant auth parameters. @@ -211,7 +212,7 @@ util = { * @private * @param {Object} entityV1 - The v1 entity to be checked for the presence of legacy properties. * @param {String} type - The type of property to be adjudged against. - * @returns {Boolean} - A flag to indicate the legacy property status of the passed v1 entity. + * @returns {Boolean|*} - A flag to indicate the legacy property status of the passed v1 entity. */ notLegacy: function (entityV1, type) { if (!entityV1) { return; } @@ -415,5 +416,3 @@ util = { } } }; - -module.exports = util;