Skip to content

Commit b1d6ce9

Browse files
committed
build: upgrade eslint
1 parent 22a7bd7 commit b1d6ce9

18 files changed

+1493
-957
lines changed

.eslintrc.js

Lines changed: 0 additions & 32 deletions
This file was deleted.

eslint.config.mjs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// @ts-check
2+
import { FlatCompat } from '@eslint/eslintrc';
3+
import path from 'node:path';
4+
import { fileURLToPath } from 'node:url';
5+
6+
// mimic CommonJS variables -- not needed if using CommonJS
7+
const __filename = fileURLToPath(import.meta.url);
8+
const __dirname = path.dirname(__filename);
9+
10+
const compat = new FlatCompat({
11+
baseDirectory: __dirname, // optional; default: process.cwd()
12+
resolvePluginsRelativeTo: __dirname, // optional
13+
});
14+
15+
export default [
16+
17+
// mimic ESLintRC-style extends
18+
// ...compat.extends(''),
19+
20+
// mimic environments
21+
...compat.env({
22+
es2020: true,
23+
node: true,
24+
}),
25+
26+
// mimic plugins
27+
...compat.plugins('mocha', 'jest'),
28+
29+
// translate an entire config
30+
...compat.config({
31+
plugins: ['mocha', 'jest'],
32+
extends: 'airbnb-base',
33+
env: {
34+
es2020: true,
35+
node: true,
36+
jest: true,
37+
mocha: true,
38+
},
39+
rules: {
40+
indent: ['error', 4, { SwitchCase: 1 }],
41+
'no-underscore-dangle': [0],
42+
'max-len': ['error', {
43+
code: 140,
44+
ignoreComments: true,
45+
}],
46+
'no-console': 0,
47+
'object-curly-newline': ['error', {
48+
ObjectPattern: { multiline: true },
49+
}],
50+
'newline-per-chained-call': ['error', {
51+
ignoreChainWithDepth: 10,
52+
}],
53+
'object-property-newline': ['error', {
54+
allowAllPropertiesOnSameLine: true,
55+
}],
56+
'import/no-extraneous-dependencies': ['error', { devDependencies: true }],
57+
},
58+
}),
59+
];

infra/__tests__/smoke_test.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const { splitUriBySlash, getDbNameFromUri } = require('../helper');
21
const { MongoMemoryServer } = require('mongodb-memory-server');
2+
const { splitUriBySlash, getDbNameFromUri } = require('../helper');
33
const mongoClient = require('../mongo');
44

55
/**

infra/config.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
const _ = require('lodash');
42
const path = require('path');
53
const fs = require('fs');
@@ -15,8 +13,8 @@ function findAppRoot(dir = path.dirname(require.main.filename)) {
1513
}
1614

1715
function getApproot() {
18-
if ((process.env.NODE_ENV === 'test') &&
19-
(_.includes(__dirname, 'node_modules'))) {
16+
if ((process.env.NODE_ENV === 'test')
17+
&& (_.includes(__dirname, 'node_modules'))) {
2018
return path.resolve(__dirname).split('/node_modules')[0];
2119
}
2220
return findAppRoot();
@@ -93,9 +91,9 @@ base.logger = {
9391
});
9492
}
9593
// human readable format
96-
return `${options.timestamp()} ${options.level.toUpperCase()} >> ` +
97-
`${options.message || ''}` +
98-
`${options.meta && Object.keys(options.meta).length ? ` << ${JSON.stringify(options.meta)}` : ''}`;
94+
return `${options.timestamp()} ${options.level.toUpperCase()} >> `
95+
+ `${options.message || ''}`
96+
+ `${options.meta && Object.keys(options.meta).length ? ` << ${JSON.stringify(options.meta)}` : ''}`;
9997
},
10098
},
10199
basePath: null,
@@ -106,7 +104,7 @@ base.logger = {
106104
correlationId: () => {
107105
try {
108106
return getRequestId();
109-
} catch (err) {
107+
} catch {
110108
return {};
111109
}
112110
},
@@ -117,7 +115,7 @@ base.logger = {
117115
authEntity.activeAccount = _.omit(authEntity.activeAccount, 'features');
118116
}
119117
return authEntity;
120-
} catch (err) {
118+
} catch {
121119
return {};
122120
}
123121
},

infra/encryption/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ function _encryptDecryptObjectValues(safeId, obj, keysToEncrypt = [], encrypt =
1111
return Promise.resolve(obj);
1212
}
1313
const pairs = _.chain(keysToEncrypt)
14-
.map(k => _.has(obj, k) && _.assign({ key: k, value: _.get(obj, k) }))
14+
.map((k) => _.has(obj, k) && _.assign({ key: k, value: _.get(obj, k) }))
1515
.compact()
1616
.value();
1717

1818
const resObj = _.clone(obj);
1919

2020
return safe.getOrCreateSafe(safeId)
2121
.then((safeObj) => {
22-
const Promises = pairs.map(kv => _encryptDecryptValue(safeObj, kv.value, encrypt)
23-
.then(res => _.set(resObj, kv.key, res)));
22+
const Promises = pairs.map((kv) => _encryptDecryptValue(safeObj, kv.value, encrypt)
23+
.then((res) => _.set(resObj, kv.key, res)));
2424
return Promise.all(Promises);
2525
})
2626
.then(() => resObj);
@@ -35,13 +35,13 @@ function decryptObjectValues(safeId, obj, keysToEncrypt) {
3535
}
3636

3737
function replaceEncryptedValues(encryptedObject = {}, keys = [], replaceWith = '*****') {
38-
return Promise.map(keys, k => _.has(encryptedObject, k) && _.set(encryptedObject, k, replaceWith))
38+
return Promise.map(keys, (k) => _.has(encryptedObject, k) && _.set(encryptedObject, k, replaceWith))
3939
.then(() => encryptedObject);
4040
}
4141

4242
module.exports = {
4343
encryptObjectValues,
4444
decryptObjectValues,
45-
getSafe: safeId => safe.getOrCreateSafe(safeId),
45+
getSafe: (safeId) => safe.getOrCreateSafe(safeId),
4646
replaceEncryptedValues,
4747
};

infra/encryption/safe.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
const _ = require('lodash');
42
const Promise = require('bluebird');
53
const uuid = require('node-uuid');
@@ -113,7 +111,6 @@ Safe.prototype.write_crypto = function (plaintext) { // eslint-disable-line
113111
return deferred.promise;
114112
};
115113

116-
117114
Safe.prototype.read = Safe.prototype.read_crypto;
118115
Safe.prototype.write = Safe.prototype.write_crypto;
119116

infra/eventbus.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
const Promise = require('bluebird');
42
const eventBus = require('@codefresh-io/eventbus');
53
const monitor = require('@codefresh-io/cf-monitor');
@@ -59,7 +57,6 @@ class Eventbus {
5957
});
6058
}
6159

62-
6360
/**
6461
* stops the connection to eventbus
6562
* @returns {*}
@@ -119,5 +116,4 @@ class Eventbus {
119116
}
120117
}
121118

122-
123119
module.exports = new Eventbus();

infra/express.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
const Promise = require('bluebird');
32
const express = require('express');
43
const compression = require('compression');
@@ -122,9 +121,9 @@ class Express {
122121
const statusCode = err.statusCode || 500;
123122
// check if err object has overridden toString method
124123
// before sending toString() response to prevent [object Object] responses
125-
const message = err.toString === Object.prototype.toString ?
126-
(err.message || 'Internal server error') :
127-
err.toString();
124+
const message = err.toString === Object.prototype.toString
125+
? (err.message || 'Internal server error')
126+
: err.toString();
128127
res.status(statusCode).send({ message });
129128
});
130129
});
@@ -154,10 +153,9 @@ class Express {
154153
.then((ret) => {
155154
res.send(ret);
156155
})
157-
.catch(err => next(err));
156+
.catch((err) => next(err));
158157
};
159158
}
160159
}
161160

162-
163161
module.exports = new Express();

infra/helper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ const splitUriBySlash = (uri) => {
88
};
99
};
1010

11-
const getDbNameFromUri = uri => splitUriBySlash(uri).dbName;
11+
const getDbNameFromUri = (uri) => splitUriBySlash(uri).dbName;
1212
module.exports = { splitUriBySlash, getDbNameFromUri };

infra/index.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
2-
31
const monitor = require('@codefresh-io/cf-monitor');
42

53
monitor.init();
64
const Promise = require('bluebird'); // jshint ignore:line
5+
const cflogs = require('cf-logs');
6+
const { openapi } = require('@codefresh-io/cf-openapi');
77
const config = require('./config');
88
const eventbus = require('./eventbus');
99
const mongo = require('./mongo');
1010
const processEvents = require('./process-events');
1111
const express = require('./express');
1212
const logging = require('./logging');
1313
const redis = require('./redis');
14-
const cflogs = require('cf-logs');
15-
const { openapi } = require('@codefresh-io/cf-openapi');
1614
const { publishInterface, subscribeInterface } = require('./openapi-events');
1715

1816
let logger;
@@ -87,7 +85,7 @@ class Microservice {
8785
openapi.events().setSubscribeInterface(subscribeInterface);
8886
}
8987
})
90-
.then(() => express.init(config, app => initFn(app, eventbus), opt))
88+
.then(() => express.init(config, (app) => initFn(app, eventbus), opt))
9189
.then(() => {
9290
logger.info('Initialization completed');
9391
this.markAsReady();
@@ -103,7 +101,7 @@ class Microservice {
103101
// - first phase need to make sure to not accept any new requests/events
104102
// - then a decent amount of time will be given to clear all on-going contexts
105103
// - second phase will close all dependencies connections like mongo, postgres etc
106-
stop() { // eslint-disable-line
104+
stop() {
107105
const enabledComponents = config.getConfigArray('enabledComponents');
108106
const gracePeriod = config.gracePeriodTimers.totalPeriod;
109107

infra/logging.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
const Promise = require('bluebird');
42
const cflogs = require('cf-logs');
53
const { name: serviceName } = require('./config');
@@ -31,5 +29,4 @@ class Logging {
3129
}
3230
}
3331

34-
3532
module.exports = new Logging();

infra/mongo.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,12 @@ class Mongo {
3333
}
3434
}
3535

36-
3736
/**
3837
* stops the connection to mongo
3938
* @returns {Promise<void>}
4039
*/
4140
async stop() {
42-
if (!this.client) return;
43-
await this.client.close();
41+
await this.client?.close();
4442
}
4543

4644
/**

infra/openapi-events.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const eventbus = require('./eventbus');
22

3-
const publishInterface = (serviceName) => eventbus.publish('openapi.push', { // eslint-disable-line
3+
const publishInterface = (serviceName) => eventbus.publish('openapi.push', {
44
aggregateId: serviceName,
55
}, true, true);
66

infra/process-events.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
const EventEmitter = require('events');
42
const Promise = require('bluebird');
53

@@ -36,5 +34,4 @@ class ProcessEvents extends EventEmitter {
3634
}
3735
}
3836

39-
4037
module.exports = new ProcessEvents();

infra/redis.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
const Promise = require('bluebird');
42
const monitor = require('@codefresh-io/cf-monitor');
53
const redis = require('redis');
@@ -24,14 +22,13 @@ class Redis {
2422
deferred.resolve();
2523
}, 30000);
2624

27-
this.client =
28-
redis.createClient({
29-
host: config.redis.url,
30-
port: config.redis.port,
31-
password: config.redis.password,
32-
db: config.redis.db,
33-
tls: config.redis.tls,
34-
});
25+
this.client = redis.createClient({
26+
host: config.redis.url,
27+
port: config.redis.port,
28+
password: config.redis.password,
29+
db: config.redis.db,
30+
tls: config.redis.tls,
31+
});
3532

3633
this.client.on('ready', () => {
3734
logger.info('Redis client ready');
@@ -55,7 +52,6 @@ class Redis {
5552
return deferred.promise;
5653
}
5754

58-
5955
/**
6056
* stops the connection to redis
6157
* @returns {*}

0 commit comments

Comments
 (0)