mirror of
https://github.com/pa11y/pa11y-dashboard.git
synced 2025-09-24 22:31:15 +00:00
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:
62
route/new.js
62
route/new.js
@@ -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
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user