forked from external-repos/pa11y-dashboard
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:
10
index.js
10
index.js
@@ -33,8 +33,8 @@ require('./app')(config, (error, app) => {
|
|||||||
console.log(kleur.grey('mode: %s'), process.env.NODE_ENV);
|
console.log(kleur.grey('mode: %s'), process.env.NODE_ENV);
|
||||||
console.log(kleur.grey('uri: %s'), app.address);
|
console.log(kleur.grey('uri: %s'), app.address);
|
||||||
|
|
||||||
app.on('route-error', error => {
|
app.on('route-error', routeError => {
|
||||||
const stack = (error.stack ? error.stack.split('\n') : [error.message]);
|
const stack = (routeError.stack ? routeError.stack.split('\n') : [routeError.message]);
|
||||||
const msg = kleur.red(stack.shift());
|
const msg = kleur.red(stack.shift());
|
||||||
console.error('');
|
console.error('');
|
||||||
console.error(msg);
|
console.error(msg);
|
||||||
@@ -43,9 +43,9 @@ require('./app')(config, (error, app) => {
|
|||||||
|
|
||||||
// Start the webservice if required
|
// Start the webservice if required
|
||||||
if (typeof config.webservice === 'object') {
|
if (typeof config.webservice === 'object') {
|
||||||
require('pa11y-webservice')(config.webservice, (error, webservice) => {
|
require('pa11y-webservice')(config.webservice, (webserviceError, webservice) => {
|
||||||
if (error) {
|
if (webserviceError) {
|
||||||
console.error(error.stack);
|
console.error(webserviceError.stack);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
62
route/new.js
62
route/new.js
@@ -30,42 +30,21 @@ function route(app) {
|
|||||||
return standard;
|
return standard;
|
||||||
});
|
});
|
||||||
response.render('new', {
|
response.render('new', {
|
||||||
standards: standards,
|
standards,
|
||||||
isNewTaskPage: true
|
isNewTaskPage: true
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
app.express.post('/new', (request, response) => {
|
app.express.post('/new', (request, response) => {
|
||||||
|
|
||||||
let parsedActions;
|
const parsedActions = parseActions(request.body.actions);
|
||||||
if (request.body.actions) {
|
|
||||||
parsedActions = request.body.actions.split(/[\r\n]+/)
|
|
||||||
.map(action => {
|
|
||||||
return action.trim();
|
|
||||||
})
|
|
||||||
.filter(action => {
|
|
||||||
return Boolean(action);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
let parsedHeaders;
|
let parsedHeaders;
|
||||||
|
|
||||||
if (request.body.headers) {
|
if (request.body.headers) {
|
||||||
parsedHeaders = httpHeaders(request.body.headers, true);
|
parsedHeaders = httpHeaders(request.body.headers, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
const newTask = {
|
const newTask = createNewTask(request, parsedActions, parsedHeaders);
|
||||||
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
|
|
||||||
};
|
|
||||||
|
|
||||||
app.webservice.tasks.create(newTask, (error, task) => {
|
app.webservice.tasks.create(newTask, (error, task) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
@@ -84,8 +63,8 @@ function route(app) {
|
|||||||
newTask.actions = request.body.actions;
|
newTask.actions = request.body.actions;
|
||||||
newTask.headers = request.body.headers;
|
newTask.headers = request.body.headers;
|
||||||
return response.render('new', {
|
return response.render('new', {
|
||||||
error: error,
|
error,
|
||||||
standards: standards,
|
standards,
|
||||||
task: newTask
|
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
|
||||||
|
};
|
||||||
|
}
|
||||||
|
@@ -29,8 +29,8 @@ function route(app) {
|
|||||||
app.webservice
|
app.webservice
|
||||||
.task(request.params.id)
|
.task(request.params.id)
|
||||||
.result(request.params.rid)
|
.result(request.params.rid)
|
||||||
.get({full: true}, (error, result) => {
|
.get({full: true}, (webserviceError, result) => {
|
||||||
if (error) {
|
if (webserviceError) {
|
||||||
return next('route');
|
return next('route');
|
||||||
}
|
}
|
||||||
response.locals.task = task;
|
response.locals.task = task;
|
||||||
|
@@ -30,8 +30,8 @@ function route(app) {
|
|||||||
app.webservice
|
app.webservice
|
||||||
.task(request.params.id)
|
.task(request.params.id)
|
||||||
.result(request.params.rid)
|
.result(request.params.rid)
|
||||||
.get({full: true}, (error, result) => {
|
.get({full: true}, (webserviceError, result) => {
|
||||||
if (error) {
|
if (webserviceError) {
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
response.render('result', {
|
response.render('result', {
|
||||||
|
@@ -43,13 +43,15 @@ function route(app) {
|
|||||||
task.actions = (task.actions ? task.actions.join('\n') : '');
|
task.actions = (task.actions ? task.actions.join('\n') : '');
|
||||||
response.render('task/edit', {
|
response.render('task/edit', {
|
||||||
edited: (typeof request.query.edited !== 'undefined'),
|
edited: (typeof request.query.edited !== 'undefined'),
|
||||||
standards: standards,
|
standards,
|
||||||
task: presentTask(task),
|
task: presentTask(task),
|
||||||
isTaskSubPage: true
|
isTaskSubPage: true
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/* eslint-disable complexity */
|
||||||
|
/* eslint-disable max-statements */
|
||||||
app.express.post('/:id/edit', (request, response, next) => {
|
app.express.post('/:id/edit', (request, response, next) => {
|
||||||
app.webservice.task(request.params.id).get({}, (error, task) => {
|
app.webservice.task(request.params.id).get({}, (error, task) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
@@ -57,9 +59,11 @@ function route(app) {
|
|||||||
}
|
}
|
||||||
const originalActions = request.body.actions;
|
const originalActions = request.body.actions;
|
||||||
const originalHeaders = request.body.headers;
|
const originalHeaders = request.body.headers;
|
||||||
|
|
||||||
request.body.ignore = request.body.ignore || [];
|
request.body.ignore = request.body.ignore || [];
|
||||||
request.body.timeout = request.body.timeout || undefined;
|
request.body.timeout = request.body.timeout || undefined;
|
||||||
request.body.wait = request.body.wait || undefined;
|
request.body.wait = request.body.wait || undefined;
|
||||||
|
|
||||||
if (request.body.actions) {
|
if (request.body.actions) {
|
||||||
request.body.actions = request.body.actions.split(/[\r\n]+/)
|
request.body.actions = request.body.actions.split(/[\r\n]+/)
|
||||||
.map(action => {
|
.map(action => {
|
||||||
@@ -69,15 +73,18 @@ function route(app) {
|
|||||||
return Boolean(action);
|
return Boolean(action);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!request.body.actions) {
|
if (!request.body.actions) {
|
||||||
request.body.actions = [];
|
request.body.actions = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
request.body.username = request.body.username || undefined;
|
request.body.username = request.body.username || undefined;
|
||||||
request.body.password = request.body.password || undefined;
|
request.body.password = request.body.password || undefined;
|
||||||
request.body.hideElements = request.body.hideElements || undefined;
|
request.body.hideElements = request.body.hideElements || undefined;
|
||||||
request.body.headers = httpHeaders(request.body.headers || '', true);
|
request.body.headers = httpHeaders(request.body.headers || '', true);
|
||||||
app.webservice.task(request.params.id).edit(request.body, error => {
|
|
||||||
if (error) {
|
app.webservice.task(request.params.id).edit(request.body, webserviceError => {
|
||||||
|
if (webserviceError) {
|
||||||
task.name = request.body.name;
|
task.name = request.body.name;
|
||||||
task.ignore = request.body.ignore;
|
task.ignore = request.body.ignore;
|
||||||
task.timeout = request.body.timeout;
|
task.timeout = request.body.timeout;
|
||||||
@@ -100,9 +107,9 @@ function route(app) {
|
|||||||
return standard;
|
return standard;
|
||||||
});
|
});
|
||||||
return response.render('task/edit', {
|
return response.render('task/edit', {
|
||||||
error: error,
|
webserviceError,
|
||||||
standards: standards,
|
standards,
|
||||||
task: task,
|
task,
|
||||||
isTaskSubPage: true
|
isTaskSubPage: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -28,9 +28,9 @@ function route(app) {
|
|||||||
if (error) {
|
if (error) {
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
app.webservice.task(request.params.id).results({}, (error, results) => {
|
app.webservice.task(request.params.id).results({}, (webserviceError, results) => {
|
||||||
if (error) {
|
if (webserviceError) {
|
||||||
return next(error);
|
return next(webserviceError);
|
||||||
}
|
}
|
||||||
const presentedResults = presentResultList(results.map(presentResult));
|
const presentedResults = presentResultList(results.map(presentResult));
|
||||||
response.render('task', {
|
response.render('task', {
|
||||||
|
@@ -22,7 +22,7 @@ module.exports = presentIgnoreRules;
|
|||||||
function presentIgnoreRules(ignore) {
|
function presentIgnoreRules(ignore) {
|
||||||
return ignore.map(name => {
|
return ignore.map(name => {
|
||||||
return {
|
return {
|
||||||
name: name,
|
name,
|
||||||
description: rules[name]
|
description: rules[name]
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user