MOBILE-4081 chore: JS Code smell fixes

main
Pau Ferrer Ocaña 2022-09-01 11:10:28 +02:00
parent 4d6962043c
commit 16a4e62f3b
6 changed files with 48 additions and 47 deletions

View File

@ -33,7 +33,7 @@ class Git {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
exec(`git format-patch ${range} --stdout`, (err, result) => { exec(`git format-patch ${range} --stdout`, (err, result) => {
if (err) { if (err) {
reject(err || 'Cannot create patch.'); reject(err);
return; return;
} }

View File

@ -170,11 +170,11 @@ class Jira {
return data; return data;
} catch (error) { } catch (error) {
// MDK not available or not configured. Ask for the data. // 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; return;
} }
exec('mdk config show tracker.username', (err, username) => { exec('mdk config show tracker.username', (error, username) => {
if (username) { if (username) {
resolve({ resolve({
url: url.replace('\n', ''), url: url.replace('\n', ''),
username: username.replace('\n', ''), username: username.replace('\n', ''),
}); });
} else { } else {
reject(err | 'Username not found.'); reject(error || 'Username not found.');
} }
}); });
}); });
@ -234,7 +234,7 @@ class Jira {
} }
// Get tracker URL and username. // Get tracker URL and username.
const trackerData = await this.getTrackerData(); let trackerData = await this.getTrackerData();
this.url = trackerData.url; this.url = trackerData.url;
this.username = trackerData.username; this.username = trackerData.username;
@ -316,15 +316,15 @@ class Jira {
auth: `${this.username}:${this.password}`, auth: `${this.username}:${this.password}`,
headers: headers, headers: headers,
}; };
const request = https.request(url, options); const buildRequest = https.request(url, options);
// Add data. // Add data.
if (data) { if (data) {
request.write(data); buildRequest.write(data);
} }
// Treat response. // Treat response.
request.on('response', (response) => { buildRequest.on('response', (response) => {
// Read the result. // Read the result.
let result = ''; let result = '';
response.on('data', (chunk) => { response.on('data', (chunk) => {
@ -344,24 +344,24 @@ class Jira {
}); });
}); });
request.on('error', (e) => { buildRequest.on('error', (e) => {
reject(e); reject(e);
}); });
// Send the request. // Send the request.
request.end(); buildRequest.end();
}); });
} }
/** /**
* Sets a set of fields for a certain issue in Jira. * 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. * @param updates Object with the fields to update.
* @return Promise resolved when done. * @return Promise resolved when done.
*/ */
async setCustomFields(key, updates) { async setCustomFields(issueId, updates) {
const issue = await this.getIssue(key); const issue = await this.getIssue(issueId);
const update = {'fields': {}}; const update = {'fields': {}};
// Detect which fields have changed. // Detect which fields have changed.
@ -372,9 +372,10 @@ class Jira {
if (!remoteValue || remoteValue != updateValue) { if (!remoteValue || remoteValue != updateValue) {
// Map the label of the field with the field code. // Map the label of the field with the field code.
let fieldKey; let fieldKey;
for (const key in issue.names) {
if (issue.names[key] == updateName) { for (const id in issue.names) {
fieldKey = key; if (issue.names[id] == updateName) {
fieldKey = id;
break; break;
} }
} }
@ -439,7 +440,7 @@ class Jira {
headers = headers || {}; headers = headers || {};
headers['Content-Type'] = 'multipart/form-data'; headers['Content-Type'] = 'multipart/form-data';
return new Promise((resolve, reject) => { return new Promise((resolve) => {
// Add the file to the form data. // Add the file to the form data.
const formData = {}; const formData = {};
formData[fieldName] = { formData[fieldName] = {
@ -462,7 +463,7 @@ class Jira {
formData: formData, formData: formData,
}; };
request(options, (err, httpResponse, body) => { request(options, (_err, httpResponse, body) => {
resolve({ resolve({
status: httpResponse.statusCode, status: httpResponse.statusCode,
data: body, data: body,

View File

@ -144,10 +144,9 @@ class BuildLangTask {
switch (folders[0]) { switch (folders[0]) {
case 'core': case 'core':
switch (folders[1]) { if (folders[1] == 'features') {
case 'features':
return `core.${folders[2]}.`; return `core.${folders[2]}.`;
default: } else {
return 'core.'; return 'core.';
} }
case 'addons': case 'addons':

View File

@ -58,22 +58,23 @@ class Utils {
*/ */
static getCommandLineArguments() { static getCommandLineArguments() {
let args = {}, opt, thisOpt, curOpt; let args = {};
for (let a = 0; a < process.argv.length; a++) { let curOpt;
thisOpt = process.argv[a].trim(); for (const argument of process.argv) {
opt = thisOpt.replace(/^\-+/, ''); const thisOpt = argument.trim();
const option = thisOpt.replace(/^\-+/, '');
if (opt === thisOpt) { if (option === thisOpt) {
// argument value // argument value
if (curOpt) { if (curOpt) {
args[curOpt] = opt; args[curOpt] = option;
} }
curOpt = null; curOpt = null;
} }
else { else {
// Argument name. // Argument name.
curOpt = opt; curOpt = option;
args[curOpt] = true; args[curOpt] = true;
} }
} }

View File

@ -93,7 +93,7 @@ async function main() {
} }
const newPath = featurePath.substring(0, featurePath.length - ('/tests/behat'.length)); 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 prefix = relative(behatTempFeaturesPath, newPath).replace(searchRegExp,'-') || 'core';
const featureFilename = prefix + '-' + basename(featureFile); const featureFilename = prefix + '-' + basename(featureFile);
renameSync(featureFile, behatFeaturesPath + '/' + featureFilename); renameSync(featureFile, behatFeaturesPath + '/' + featureFilename);

View File

@ -13,9 +13,9 @@
// limitations under the License. // limitations under the License.
(function () { (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. // Same domain as the app, stop.
return; return;
} }
@ -41,14 +41,14 @@
}; };
// Handle link clicks. // Handle link clicks.
document.addEventListener('click', (event) => { document.addEventListener('click', (documentClickEvent) => {
if (event.defaultPrevented) { if (documentClickEvent.defaultPrevented) {
// Event already prevented by some other code. // Event already prevented by some other code.
return; return;
} }
// Find the link being clicked. // Find the link being clicked.
var el = event.target; let el = documentClickEvent.target;
while (el && (el.tagName !== 'A' && el.tagName !== 'a')) { while (el && (el.tagName !== 'A' && el.tagName !== 'a')) {
el = el.parentElement; 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. // 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.treated = true;
el.addEventListener('click', function(event) { el.addEventListener('click', function(elementClickEvent) {
linkClicked(el, event); linkClicked(el, elementClickEvent);
}); });
}, { }, {
capture: true // Use capture to fix this listener not called if the element clicked is too deep in the DOM. 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; return leftPath;
} }
var lastCharLeft = leftPath.slice(-1); const lastCharLeft = leftPath.slice(-1);
var firstCharRight = rightPath.charAt(0); const firstCharRight = rightPath.charAt(0);
if (lastCharLeft === '/' && firstCharRight === '/') { if (lastCharLeft === '/' && firstCharRight === '/') {
return leftPath + rightPath.substr(1); return leftPath + rightPath.substr(1);
@ -119,7 +119,7 @@
return; return;
} }
var matches = url.match(/^([a-z][a-z0-9+\-.]*):/); const matches = url.match(/^([a-z][a-z0-9+\-.]*):/);
if (matches && matches[1]) { if (matches && matches[1]) {
return matches[1]; return matches[1];
} }
@ -164,9 +164,9 @@
return; return;
} }
var linkScheme = getUrlScheme(link.href); const linkScheme = getUrlScheme(link.href);
var pageScheme = getUrlScheme(location.href); const pageScheme = getUrlScheme(location.href);
var isTargetSelf = !link.target || link.target == '_self'; const isTargetSelf = !link.target || link.target == '_self';
if (!link.href || linkScheme == 'javascript') { if (!link.href || linkScheme == 'javascript') {
// Links with no URL and Javascript links are ignored. // 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. // 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); return concatenatePaths(pathToDir, url);
} }