Skip to content

Commit

Permalink
eslint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Idrinth committed May 18, 2024
1 parent 55d4cf3 commit 23ac585
Show file tree
Hide file tree
Showing 24 changed files with 69 additions and 37 deletions.
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 2
1 change: 1 addition & 0 deletions src/cli/check-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default async(args: string[], cwd: string,): Promise<void> => {
error('validation_warnings', `${ warnings }`,);
}
if (warnings === EMPTY && errors === EMPTY) {
// eslint-disable-next-line no-console
console.log(logSymbols.success + ' ' + language('no_errors_warnings',),);
}
};
3 changes: 2 additions & 1 deletion src/helper/user-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ const getVersion = (name: string, lock: Lock,): string => {
const lock: Lock = reqlib.require('/package-lock.json',) as Lock;
const main = `${ lock.name }/${ formatVersion(lock,) }`;
const needle = `needle/${ getVersion('needle', lock,) }`;
const self = `@idrinth-api-bench/framework/${ getVersion('@idrinth-api-bench/framework', lock,) }`;
const name = '@idrinth-api-bench/framework';
const self = `${ name }/${ getVersion(name, lock,) }`;
export default `${ main } ${ self } ${ needle }`.replace(/ {2,}/ug, ' ',);
4 changes: 2 additions & 2 deletions src/middlewares/access-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const prepare: prepareType = (request: Request,): Request => {
request.headers.authorization = `Bearer ${ access }`;
}
return request;
}
};

export const process: processType = (response: Result,): void => {
if (typeof response.response.headers === 'undefined') {
Expand All @@ -59,4 +59,4 @@ export const process: processType = (response: Result,): void => {
refresh = get(refresh, body, 'refresh', 'refresh_token', 'refresh-token',);
store.set('access', access,);
store.set('refresh', refresh,);
}
};
4 changes: 2 additions & 2 deletions src/middlewares/cookie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const prepare: prepareType = (request: Request,): Request => {
}
}
return request;
}
};

export const process: processType = (response: Result,): void => {
if (typeof response.response.cookies === 'undefined') {
Expand All @@ -30,4 +30,4 @@ export const process: processType = (response: Result,): void => {
}
}
store.set('cookie', JSON.stringify(jar,),);
}
};
4 changes: 2 additions & 2 deletions src/middlewares/csrf-header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const prepare: prepareType = (request: Request,): Request => {
}
}
return request;
}
};

export const process: processType = (response: Result,): void => {
if (typeof response.response.headers === 'undefined') {
Expand All @@ -26,4 +26,4 @@ export const process: processType = (response: Result,): void => {
if (response.response.headers['x-csrf-token']) {
store.set('csrf', response.response.headers['x-csrf-token'],);
}
}
};
4 changes: 2 additions & 2 deletions src/middlewares/encoding.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
prepare as prepareType
prepare as prepareType,
} from './middleware.js';
import Request from '../routes/request.js';
import formUrlEncoded from 'form-urlencoded';
Expand Down Expand Up @@ -30,4 +30,4 @@ export const prepare: prepareType = (request: Request,): Request => {
return handleForm(request,);
}
return request;
}
};
4 changes: 2 additions & 2 deletions src/middlewares/failure-check.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
process as processType
process as processType,
} from './middleware.js';
import Result from '../messaging/result.js';
import language from '../helper/language.js';
Expand All @@ -23,4 +23,4 @@ export const process: processType = (result: Result,): void => {
language('response_not_failure', 'success', `${ response.success }`,),
);
}
}
};
2 changes: 1 addition & 1 deletion src/middlewares/json-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ export const process: processType = (result: Result,): void => {
} catch (e) {
throw Error(language('invalid_json_body', `${ e }`,),);
}
}
};
2 changes: 1 addition & 1 deletion src/middlewares/max-time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ export const process: processType = (result: Result,): void => {
if (result.duration > result.maxDuration) {
throw new Error(language('too_slow', `${ result.maxDuration }`,),);
}
}
};
4 changes: 2 additions & 2 deletions src/middlewares/silent-server-validator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
process as processType
process as processType,
} from './middleware.js';
import Result from '../messaging/result.js';
import language from '../helper/language.js';
Expand All @@ -11,4 +11,4 @@ export const process: processType = (result: Result,): void => {
if (typeof result.response.headers['X-Powered-By'] !== 'undefined') {
throw Error(language('powered_by_is_set',),);
}
}
};
2 changes: 1 addition & 1 deletion src/middlewares/status-2xx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ export const process: processType = (response: Result,): void => {
if (response.response.status < MINIMUM) {
throw new Error(language('response_status_below_2xx',),);
}
}
};
4 changes: 2 additions & 2 deletions src/middlewares/status-403.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
process as processType
process as processType,
} from './middleware.js';
import Result from '../messaging/result.js';
import language from '../helper/language.js';
Expand All @@ -16,4 +16,4 @@ export const process: processType = (response: Result,): void => {
`${ response.response.status }`,
),);
}
}
};
4 changes: 2 additions & 2 deletions src/middlewares/status-404.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
process as processType
process as processType,
} from './middleware.js';
import Result from '../messaging/result.js';
import language from '../helper/language.js';
Expand All @@ -15,4 +15,4 @@ export const process: processType = (response: Result,): void => {
language('response_status_not_404', `${ response.response.status }`,),
);
}
}
};
4 changes: 2 additions & 2 deletions src/middlewares/success-check.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
process as processType
process as processType,
} from './middleware.js';
import Result from '../messaging/result.js';
import language from '../helper/language.js';
Expand All @@ -24,4 +24,4 @@ export const process: processType = (result: Result,): void => {
language('response_not_success', 'success', `${ response.success }`,),
);
}
}
};
2 changes: 1 addition & 1 deletion src/middlewares/user-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ export const prepare: prepareType = (request: Request,): Request => {
request.headers['user-agent'] = agent;
}
return request;
}
};
2 changes: 1 addition & 1 deletion src/middlewares/xml-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ export const process: processType = (result: Result,): void => {
if (FastXMLValidator.validate(result.response.body,) !== true) {
throw Error(language('invalid_xml_body',),);
}
}
};
9 changes: 6 additions & 3 deletions src/routes/include-default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ import isCallable from 'is-callable';
import {
INCLUDE_EXTENSION,
} from '../constants.js';
import language from "../helper/language.js";
import language from '../helper/language.js';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const include = async(path: string, part: string = 'default'): Promise<any> => {
const include = async(
path: string,
part: string = 'default',
): Promise<unknown> => {
path = path
.replace(/\/\//ug, '/',)
.replace(/\.ts$/u, INCLUDE_EXTENSION,);
let val = await import('file://' + path,)[part];
const val = await import('file://' + path,)[part];
if (typeof val !== 'function') {
throw new Error(language('impossible_include', path, part,),);
}
Expand Down
7 changes: 5 additions & 2 deletions src/routes/middleware-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ const resolve = (path: string,): string => {
}
return path.endsWith(INCLUDE_EXTENSION,) ? path : path + INCLUDE_EXTENSION;
};
const load = async(path: string, part: 'pre'|'post',): Promise<prepare|process> => {
const load = async(
path: string,
part: 'pre'|'post',
): Promise<prepare|process> => {
const req = cache[path] || (cache[path] = resolve(path,));
if (part === 'pre') {
return await include(req, 'prepare',) as prepare;
}
return await include(req, 'process') as process;
return await include(req, 'process',) as process;
};
export default load;
7 changes: 5 additions & 2 deletions src/validation/check-middleware.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import Task from '../task.js';
import Task from '../routes/task.js';
import error from './error.js';

const checkMiddleware = (type: 'pre' | 'post', route: Task,) => {
const checkMiddleware = (

Check failure on line 4 in src/validation/check-middleware.ts

View workflow job for this annotation

GitHub Actions / lint

Arrow function has a complexity of 6. Maximum allowed is 5
type: 'pre' | 'post',
route: Task,
) => {
if (typeof route[type] === 'undefined') {
return true;
}
Expand Down
6 changes: 4 additions & 2 deletions src/validation/check-request.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Request from '../request.js';
import Request from '../routes/request.js';
import error from './error.js';
import {
EMPTY,
Expand Down Expand Up @@ -57,7 +57,9 @@ const validateProperty = (property: Property, id: string, main: Request,) => {
error('invalid_request_property', id, property.name,);
return false;
}
const allowedTypes: string[] = Array.isArray(property.type,) ? property.type : [ property.type, ];
const allowedTypes: string[] = Array.isArray(property.type,)
? property.type
: [ property.type, ];
if (! allowedTypes.includes(typeof main[property.name],)) {
error('invalid_request_property', id, property.name,);
delete main[property.name];
Expand Down
5 changes: 3 additions & 2 deletions src/validation/check-type.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import Job from '../job.js';
import taskType from '../task-type.js';
import Job from '../routes/job.js';
import taskType from '../routes/task-type.js';
import {
EMPTY,
} from '../constants.js';
import checkRequest from './check-request.js';
import warn from './warn.js';
import checkMiddleware from './check-middleware.js';

// eslint-disable-next-line complexity
const checkType = (job: Job, type: taskType,) => {
if (typeof job[type] === 'undefined') {
return {
Expand Down
10 changes: 8 additions & 2 deletions src/worker/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ const handlePre = async(task: Task,) => {
if (task.pre) {
for (const middleware of task.pre) {
// eslint-disable-next-line no-await-in-loop
const requestMiddleware: prepare = await load(middleware, 'pre',) as prepare;
const requestMiddleware: prepare = await load(
middleware,
'pre',
) as prepare;
task.main = requestMiddleware(task.main,);
}
}
Expand All @@ -42,7 +45,10 @@ const handlePost = async(task: Task, res:Result, callable: Callback,) => {
for (const validator of task.post) {
try {
// eslint-disable-next-line no-await-in-loop
const validatorMiddleware: process = await load(validator, 'post',) as process;
const validatorMiddleware: process = await load(
validator,
'post',
) as process;
validatorMiddleware(res,);
} catch (er) {
callable(buildAnswer(res, er+'', false,),);
Expand Down
4 changes: 4 additions & 0 deletions tools/fta.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const setUnixPerms = (binaryPath,) => {
try {
fs.chmodSync(binaryPath, '755',);
} catch (e) {
// eslint-disable-next-line no-console
console.warn('Could not chmod fta binary: ', e,);
}
}
Expand Down Expand Up @@ -120,10 +121,13 @@ for (const file of output) {
].join('|',);
if (file.fta_score > ERROR_FTA_SCORE) {
hardToMaintain = true;
// eslint-disable-next-line no-console
console.error(message,);
} else if (file.fta_score > WARNING_FTA_SCORE) {
// eslint-disable-next-line no-console
console.warn(message,);
} else {
// eslint-disable-next-line no-console
console.log(message,);
}
}
Expand Down

0 comments on commit 23ac585

Please sign in to comment.