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) => {
exec(`git format-patch ${range} --stdout`, (err, result) => {
if (err) {
reject(err || 'Cannot create patch.');
reject(err);
return;
}

View File

@ -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,

View File

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

View File

@ -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;
}
}

View File

@ -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);

View File

@ -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);
}