Skip to content

Commit aeb2140

Browse files
authored
chore: fixes code smells (#572)
1 parent 678096b commit aeb2140

40 files changed

+475
-549
lines changed

npm-shrinkwrap.json

Lines changed: 328 additions & 379 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@
5252
"jsonwebtoken": "^9.0.2",
5353
"moment": "^2.30.1",
5454
"mongodb": "^6.20.0",
55-
"mongoose": "^8.18.2",
55+
"mongoose": "^8.19.0",
5656
"passport": "^0.7.0",
5757
"@node-saml/passport-saml": "^5.1.0",
58-
"pino": "^9.11.0",
58+
"pino": "^9.13.0",
5959
"pino-pretty": "^13.1.1",
6060
"swagger-ui-express": "^5.0.1",
6161
"switcher-client": "^4.4.1",
@@ -64,7 +64,7 @@
6464
"devDependencies": {
6565
"env-cmd": "^11.0.0",
6666
"eslint": "^9.36.0",
67-
"jest": "^30.1.3",
67+
"jest": "^30.2.0",
6868
"jest-sonar-reporter": "^2.0.0",
6969
"node-notifier": "^10.0.1",
7070
"nodemon": "^3.1.10",

src/aggregator/permission-resolvers.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ export async function resolvePermission(args, admin) {
2626
for (const action_perm of args.actions) {
2727
try {
2828
await verifyOwnership(admin, element, args.domain, action_perm, args.router, false, args.environment);
29-
result[result.length - 1].permissions.push({ action: action_perm.toString(), result: 'ok' });
29+
result.at(-1).permissions.push({ action: action_perm.toString(), result: 'ok' });
3030
} catch (e) {
3131
Logger.debug('resolvePermission', e);
32-
result[result.length - 1].permissions.push({ action: action_perm.toString(), result: 'nok' });
32+
result.at(-1).permissions.push({ action: action_perm.toString(), result: 'nok' });
3333
}
3434
}
3535
}
@@ -50,5 +50,5 @@ const getElements = async (domain, parent, router) => {
5050
return getConfigs({ domain, group: parent }, true);
5151
}
5252

53-
return Promise.resolve([]);
53+
return [];
5454
};

src/aggregator/resolvers.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ export const resolveConfigByKey = async (domain, key) => Config.findOne({ domain
1313
export function resolveEnvValue(source, field, keys) {
1414
const arrValue = [];
1515

16-
keys.forEach(k => {
16+
for (const k of keys) {
1717
arrValue.push({
1818
env: k,
1919
value: source[field][k]
2020
});
21-
});
21+
}
2222

2323
return arrValue;
2424
}

src/app-server.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import https from 'https';
2-
import http from 'http';
3-
import fs from 'fs';
1+
import https from 'node:https';
2+
import http from 'node:http';
3+
import fs from 'node:fs';
44
import Logger from './helpers/logger.js';
55

66
export const createServer = (app) => {

src/external/gitops.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import axios from 'axios';
2-
import https from 'https';
2+
import https from 'node:https';
33
import jwt from 'jsonwebtoken';
44

55
const agent = (url) => {

src/helpers/index.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ const PATTERN_ALPHANUMERIC = /^[a-zA-Z0-9_-]*$/;
1010

1111
export async function checkEnvironmentStatusRemoval(domainId, environmentName, strategy = false) {
1212
const environment = await getEnvironments({ domain: domainId }, ['_id', 'name']);
13-
const isValidOperation = environment.filter((e) =>
13+
const isValidOperation = environment.some((e) =>
1414
e.name === environmentName &&
15-
!strategy ? environmentName !== EnvType.DEFAULT : strategy).length > 0;
15+
!strategy ? environmentName !== EnvType.DEFAULT : strategy);
1616

1717
if (!isValidOperation) {
1818
throw new BadRequestError('Invalid environment');
@@ -32,33 +32,33 @@ export function containsValue(arr, value) {
3232
}
3333

3434
export function formatInput(input,
35-
options = {
36-
toUpper: false,
37-
toLower: false,
38-
autoUnderscore: false,
39-
allowSpace: false
40-
}) {
35+
{
36+
toUpper = false,
37+
toLower = false,
38+
autoUnderscore = false,
39+
allowSpace = false
40+
} = {}) {
4141

4242
let regexStr;
43-
if (options.autoUnderscore) {
43+
if (autoUnderscore) {
4444
regexStr = PATTERN_ALPHANUMERIC_SPACE;
4545
} else {
46-
regexStr = options.allowSpace ? PATTERN_ALPHANUMERIC_SPACE : PATTERN_ALPHANUMERIC;
46+
regexStr = allowSpace ? PATTERN_ALPHANUMERIC_SPACE : PATTERN_ALPHANUMERIC;
4747
}
4848

4949
const regex = new RegExp(regexStr);
5050
if (!regex.test(input)) {
5151
throw new Error('Invalid input format. Use only alphanumeric digits.');
5252
}
5353

54-
if (options.toUpper) {
54+
if (toUpper) {
5555
input = input.toUpperCase();
56-
} else if (options.toLower) {
56+
} else if (toLower) {
5757
input = input.toLowerCase();
5858
}
5959

60-
if (options.autoUnderscore) {
61-
input = input.replace(/\s/g, '_');
60+
if (autoUnderscore) {
61+
input = input.replaceAll(' ', '_');
6262
}
6363

6464
return input.trim();
@@ -76,11 +76,11 @@ export function sortBy(args) {
7676
}
7777

7878
export function validatePagingArgs(args) {
79-
if (args.limit && !Number.isInteger(parseInt(args.limit)) || parseInt(args.limit) < 1) {
79+
if (args.limit && !Number.isInteger(Number.parseInt(args.limit)) || Number.parseInt(args.limit) < 1) {
8080
return false;
8181
}
8282

83-
if (args.skip && !Number.isInteger(parseInt(args.skip)) || parseInt(args.skip) < 0) {
83+
if (args.skip && !Number.isInteger(Number.parseInt(args.skip)) || Number.parseInt(args.skip) < 0) {
8484
return false;
8585
}
8686

src/middleware/gitops.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ function validateChangesContent(changes) {
8383
for (const change of changes) {
8484
if (CONTENT_TYPE_ARRAY.includes(change.diff)) {
8585
if (!Array.isArray(change.content)) {
86-
throw new Error('Request has invalid content type [object]');
86+
throw new TypeError('Request has invalid content type [object]');
8787
}
8888
} else if (Array.isArray(change.content)) {
89-
throw new Error('Request has invalid content type [array]');
89+
throw new TypeError('Request has invalid content type [array]');
9090
}
9191
}
9292
}

src/middleware/limiter.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const ERROR_MESSAGE = {
77

88
const getMaxRate = (rate_limit) => {
99
if (rate_limit === 0) {
10-
return parseInt(DEFAULT_RATE_LIMIT);
10+
return Number.parseInt(DEFAULT_RATE_LIMIT);
1111
}
1212

1313
return rate_limit;
@@ -17,7 +17,7 @@ export const DEFAULT_RATE_LIMIT = 1000;
1717

1818
export const defaultLimiter = rateLimit({
1919
windowMs: DEFAULT_WINDOWMS,
20-
limit: getMaxRate(parseInt(process.env.MAX_REQUEST_PER_MINUTE)),
20+
limit: getMaxRate(Number.parseInt(process.env.MAX_REQUEST_PER_MINUTE)),
2121
skip: (request) => request.rate_limit === 0,
2222
standardHeaders: 'draft-7',
2323
legacyHeaders: false,

src/middleware/validators.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export async function checkEnvironmentStatusChange(args, domain, field) {
66
const environment = await getEnvironments({ domain }, ['_id', 'name']);
77
const updates = Object.keys(field || args);
88
const isValidOperation = updates.every((update) => {
9-
return environment.filter((e) => e.name === update).length > 0;
9+
return environment.some((e) => e.name === update);
1010
});
1111

1212
if (!isValidOperation) {

0 commit comments

Comments
 (0)