diff --git a/gulp/git.js b/gulp/git.js index f3f66298a..e7eacb000 100644 --- a/gulp/git.js +++ b/gulp/git.js @@ -33,7 +33,7 @@ class Git { return new Promise((resolve, reject) => { exec(`git format-patch ${range} --stdout`, (err, result) => { if (err) { - reject(err || 'Cannot create patch.'); + reject(err); return; } diff --git a/gulp/jira.js b/gulp/jira.js index 90aeaa1c7..5e3474973 100644 --- a/gulp/jira.js +++ b/gulp/jira.js @@ -170,11 +170,11 @@ class Jira { return data; } catch (error) { // MDK not available or not configured. Ask for the data. - const data = await this.askTrackerData(); + const trackerData = await this.askTrackerData(); - data.fromInput = true; + trackerData.fromInput = true; - return data; + return trackerData; } } @@ -208,14 +208,14 @@ class Jira { return; } - exec('mdk config show tracker.username', (err, username) => { + exec('mdk config show tracker.username', (error, username) => { if (username) { resolve({ url: url.replace('\n', ''), username: username.replace('\n', ''), }); } else { - reject(err | 'Username not found.'); + reject(error || 'Username not found.'); } }); }); @@ -234,7 +234,7 @@ class Jira { } // Get tracker URL and username. - const trackerData = await this.getTrackerData(); + let trackerData = await this.getTrackerData(); this.url = trackerData.url; this.username = trackerData.username; @@ -316,15 +316,15 @@ class Jira { auth: `${this.username}:${this.password}`, headers: headers, }; - const request = https.request(url, options); + const buildRequest = https.request(url, options); // Add data. if (data) { - request.write(data); + buildRequest.write(data); } // Treat response. - request.on('response', (response) => { + buildRequest.on('response', (response) => { // Read the result. let result = ''; response.on('data', (chunk) => { @@ -344,24 +344,24 @@ class Jira { }); }); - request.on('error', (e) => { + buildRequest.on('error', (e) => { reject(e); }); // Send the request. - request.end(); + buildRequest.end(); }); } /** * Sets a set of fields for a certain issue in Jira. * - * @param key Key to identify the issue. E.g. MOBILE-1234. + * @param issueId Key to identify the issue. E.g. MOBILE-1234. * @param updates Object with the fields to update. * @return Promise resolved when done. */ - async setCustomFields(key, updates) { - const issue = await this.getIssue(key); + async setCustomFields(issueId, updates) { + const issue = await this.getIssue(issueId); const update = {'fields': {}}; // Detect which fields have changed. @@ -372,9 +372,10 @@ class Jira { if (!remoteValue || remoteValue != updateValue) { // Map the label of the field with the field code. let fieldKey; - for (const key in issue.names) { - if (issue.names[key] == updateName) { - fieldKey = key; + + for (const id in issue.names) { + if (issue.names[id] == updateName) { + fieldKey = id; break; } } @@ -439,7 +440,7 @@ class Jira { headers = headers || {}; headers['Content-Type'] = 'multipart/form-data'; - return new Promise((resolve, reject) => { + return new Promise((resolve) => { // Add the file to the form data. const formData = {}; formData[fieldName] = { @@ -462,7 +463,7 @@ class Jira { formData: formData, }; - request(options, (err, httpResponse, body) => { + request(options, (_err, httpResponse, body) => { resolve({ status: httpResponse.statusCode, data: body, diff --git a/gulp/task-build-lang.js b/gulp/task-build-lang.js index 7fe60ad7c..a8d6348cf 100644 --- a/gulp/task-build-lang.js +++ b/gulp/task-build-lang.js @@ -144,11 +144,10 @@ class BuildLangTask { switch (folders[0]) { case 'core': - switch (folders[1]) { - case 'features': - return `core.${folders[2]}.`; - default: - return 'core.'; + if (folders[1] == 'features') { + return `core.${folders[2]}.`; + } else { + return 'core.'; } case 'addons': return `addon.${folders.slice(1).join('_')}.`; diff --git a/gulp/utils.js b/gulp/utils.js index 0ca11fa74..1e8783337 100644 --- a/gulp/utils.js +++ b/gulp/utils.js @@ -58,22 +58,23 @@ class Utils { */ static getCommandLineArguments() { - let args = {}, opt, thisOpt, curOpt; - for (let a = 0; a < process.argv.length; a++) { + let args = {}; + let curOpt; - thisOpt = process.argv[a].trim(); - opt = thisOpt.replace(/^\-+/, ''); + for (const argument of process.argv) { + const thisOpt = argument.trim(); + const option = thisOpt.replace(/^\-+/, ''); - if (opt === thisOpt) { + if (option === thisOpt) { // argument value if (curOpt) { - args[curOpt] = opt; + args[curOpt] = option; } curOpt = null; } else { // Argument name. - curOpt = opt; + curOpt = option; args[curOpt] = true; } } diff --git a/scripts/build-behat-plugin.js b/scripts/build-behat-plugin.js index e5a7aebfb..9dc94bcc8 100755 --- a/scripts/build-behat-plugin.js +++ b/scripts/build-behat-plugin.js @@ -93,7 +93,7 @@ async function main() { } const newPath = featurePath.substring(0, featurePath.length - ('/tests/behat'.length)); - const searchRegExp = new RegExp('/', 'g'); + const searchRegExp = /\//g; const prefix = relative(behatTempFeaturesPath, newPath).replace(searchRegExp,'-') || 'core'; const featureFilename = prefix + '-' + basename(featureFile); renameSync(featureFile, behatFeaturesPath + '/' + featureFilename); diff --git a/src/assets/js/iframe-treat-links.js b/src/assets/js/iframe-treat-links.js index abded2658..e1a507545 100644 --- a/src/assets/js/iframe-treat-links.js +++ b/src/assets/js/iframe-treat-links.js @@ -13,9 +13,9 @@ // limitations under the License. (function () { - var url = location.href; + const locationHref = location.href; - if (url.match(/^moodleappfs:\/\/localhost/i) || !url.match(/^[a-z0-9]+:\/\//i)) { + if (locationHref.match(/^moodleappfs:\/\/localhost/i) || !locationHref.match(/^[a-z0-9]+:\/\//i)) { // Same domain as the app, stop. return; } @@ -41,14 +41,14 @@ }; // Handle link clicks. - document.addEventListener('click', (event) => { - if (event.defaultPrevented) { + document.addEventListener('click', (documentClickEvent) => { + if (documentClickEvent.defaultPrevented) { // Event already prevented by some other code. return; } // Find the link being clicked. - var el = event.target; + let el = documentClickEvent.target; while (el && (el.tagName !== 'A' && el.tagName !== 'a')) { el = el.parentElement; } @@ -59,8 +59,8 @@ // Add click listener to the link, this way if the iframe has added a listener to the link it will be executed first. el.treated = true; - el.addEventListener('click', function(event) { - linkClicked(el, event); + el.addEventListener('click', function(elementClickEvent) { + linkClicked(el, elementClickEvent); }); }, { capture: true // Use capture to fix this listener not called if the element clicked is too deep in the DOM. @@ -82,8 +82,8 @@ return leftPath; } - var lastCharLeft = leftPath.slice(-1); - var firstCharRight = rightPath.charAt(0); + const lastCharLeft = leftPath.slice(-1); + const firstCharRight = rightPath.charAt(0); if (lastCharLeft === '/' && firstCharRight === '/') { return leftPath + rightPath.substr(1); @@ -119,7 +119,7 @@ return; } - var matches = url.match(/^([a-z][a-z0-9+\-.]*):/); + const matches = url.match(/^([a-z][a-z0-9+\-.]*):/); if (matches && matches[1]) { return matches[1]; } @@ -164,9 +164,9 @@ return; } - var linkScheme = getUrlScheme(link.href); - var pageScheme = getUrlScheme(location.href); - var isTargetSelf = !link.target || link.target == '_self'; + const linkScheme = getUrlScheme(link.href); + const pageScheme = getUrlScheme(location.href); + const isTargetSelf = !link.target || link.target == '_self'; if (!link.href || linkScheme == 'javascript') { // Links with no URL and Javascript links are ignored. @@ -207,7 +207,7 @@ } // It's a relative URL, use the frame src to create the full URL. - var pathToDir = location.href.substring(0, location.href.lastIndexOf('/')); + const pathToDir = location.href.substring(0, location.href.lastIndexOf('/')); return concatenatePaths(pathToDir, url); }