Address all eslint warnings

Address all eslint warnings that were still present by:

* Extracting code to a new function in order to reduce complexity
* Renamed error variables and use shorthand notation for objects
* Disabling eslint warnings where addressing the issue would require too much refactoring
This commit is contained in:
Jose Bolos
2022-04-11 16:16:54 +01:00
parent 0e7849dd07
commit b9b049ec2b
7 changed files with 61 additions and 46 deletions

View File

@@ -30,42 +30,21 @@ function route(app) {
return standard;
});
response.render('new', {
standards: standards,
standards,
isNewTaskPage: true
});
});
app.express.post('/new', (request, response) => {
let parsedActions;
if (request.body.actions) {
parsedActions = request.body.actions.split(/[\r\n]+/)
.map(action => {
return action.trim();
})
.filter(action => {
return Boolean(action);
});
}
const parsedActions = parseActions(request.body.actions);
let parsedHeaders;
if (request.body.headers) {
parsedHeaders = httpHeaders(request.body.headers, true);
}
const newTask = {
name: request.body.name,
url: request.body.url,
standard: request.body.standard,
ignore: request.body.ignore || [],
timeout: request.body.timeout || undefined,
wait: request.body.wait || undefined,
actions: parsedActions,
username: request.body.username || undefined,
password: request.body.password || undefined,
headers: parsedHeaders,
hideElements: request.body.hideElements || undefined
};
const newTask = createNewTask(request, parsedActions, parsedHeaders);
app.webservice.tasks.create(newTask, (error, task) => {
if (error) {
@@ -84,8 +63,8 @@ function route(app) {
newTask.actions = request.body.actions;
newTask.headers = request.body.headers;
return response.render('new', {
error: error,
standards: standards,
error,
standards,
task: newTask
});
}
@@ -94,3 +73,32 @@ function route(app) {
});
}
function parseActions(actions) {
if (actions) {
return actions.split(/[\r\n]+/)
.map(action => {
return action.trim();
})
.filter(action => {
return Boolean(action);
});
}
}
/* eslint-disable complexity */
function createNewTask(request, actions, headers) {
return {
name: request.body.name,
url: request.body.url,
standard: request.body.standard,
ignore: request.body.ignore || [],
timeout: request.body.timeout || undefined,
wait: request.body.wait || undefined,
actions,
username: request.body.username || undefined,
password: request.body.password || undefined,
headers,
hideElements: request.body.hideElements || undefined
};
}