Skip to content

Commit 2723218

Browse files
authored
DEV: Improve code style with turning on few ESlint rules (#5130)
* turn on prettier rules for API * turn on general TS rules
1 parent fb5f024 commit 2723218

File tree

67 files changed

+320
-258
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+320
-258
lines changed

.eslintrc.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,6 @@ module.exports = {
261261
rules: {
262262
semi: 'off',
263263
'@typescript-eslint/semi': 'off',
264-
'@typescript-eslint/no-unused-vars': 'off',
265-
'@typescript-eslint/no-use-before-define': 'off',
266-
'@typescript-eslint/no-unused-expressions': 'off',
267264
'sonarjs/no-identical-functions': 'off',
268265
'sonarjs/prefer-immediate-return': 'off',
269266
'sonarjs/no-duplicate-string': 'off',
@@ -274,14 +271,10 @@ module.exports = {
274271
'no-underscore-dangle': 'off',
275272
'import/no-duplicates': 'off',
276273
'no-console': 'off',
277-
'prettier/prettier': 'off',
278274
'prefer-destructuring': 'off',
279275
'no-unneeded-ternary': 'off',
280276
'prefer-template': 'off',
281277
'prefer-const': 'off',
282-
'@typescript-eslint/naming-convention': 'off',
283-
'@typescript-eslint/lines-between-class-members': 'off',
284-
'@typescript-eslint/no-shadow': 'off',
285278
// REDUNDANT: These are OFF by default in newer Airbnb config
286279
// 'prefer-arrow-callback': 'off',
287280
// 'no-restricted-syntax': 'off',
@@ -427,7 +420,9 @@ module.exports = {
427420
'node_modules',
428421
'release',
429422
'redisinsight/ui/src/packages/**/icons/*.js*',
423+
'redisinsight/ui/src/packages/**',
430424
'redisinsight/api/report/**',
425+
'redisinsight/api/static/**',
431426
'redisinsight/api/migration/**',
432427
// Config files that don't need linting
433428
'.eslintrc.js',

redisinsight/api/config/default.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,8 @@ export default {
114114
databaseManagement: process.env.RI_DATABASE_MANAGEMENT !== 'false',
115115
maxPayloadSize: process.env.RI_MAX_PAYLOAD_SIZE || '512MB',
116116
cors: {
117-
origin: process.env.RI_CORS_ORIGIN
118-
? process.env.RI_CORS_ORIGIN
119-
: '*',
120-
credentials:
121-
process.env.RI_CORS_CREDENTIALS === 'true',
117+
origin: process.env.RI_CORS_ORIGIN ? process.env.RI_CORS_ORIGIN : '*',
118+
credentials: process.env.RI_CORS_CREDENTIALS === 'true',
122119
},
123120
},
124121
statics: {

redisinsight/api/config/logger.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ import {
66
} from 'nest-winston';
77
import { join } from 'path';
88
import config from 'src/utils/config';
9-
import {
10-
prepareLogsData,
11-
prettyFileFormat,
12-
} from 'src/utils/logsFormatter';
9+
import { prepareLogsData, prettyFileFormat } from 'src/utils/logsFormatter';
1310

1411
const PATH_CONFIG = config.get('dir_path');
1512
const LOGGER_CONFIG = config.get('logger');

redisinsight/api/src/common/decorators/client-metadata/client-metadata.decorator.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,24 @@ export const clientMetadataParamFactory = (
3838
uniqueId = req.params?.[options.uniqueIdParam];
3939
}
4040

41-
const clientMetadata = plainToInstance(ClientMetadata, {
42-
sessionMetadata: sessionMetadataFromRequestExecutionContext(undefined, ctx),
43-
databaseId,
44-
uniqueId,
45-
context: options?.context || ClientContext.Common,
46-
db: options?.ignoreDbIndex
47-
? undefined
48-
: req?.headers?.[API_HEADER_DATABASE_INDEX],
49-
}, {
50-
groups: ['security'],
51-
});
41+
const clientMetadata = plainToInstance(
42+
ClientMetadata,
43+
{
44+
sessionMetadata: sessionMetadataFromRequestExecutionContext(
45+
undefined,
46+
ctx,
47+
),
48+
databaseId,
49+
uniqueId,
50+
context: options?.context || ClientContext.Common,
51+
db: options?.ignoreDbIndex
52+
? undefined
53+
: req?.headers?.[API_HEADER_DATABASE_INDEX],
54+
},
55+
{
56+
groups: ['security'],
57+
},
58+
);
5259

5360
const errors = validator.validateSync(clientMetadata, {
5461
whitelist: false, // we need this to allow additional fields if needed for flexibility

redisinsight/api/src/common/decorators/session/session-metadata.decorator.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ export const sessionMetadataFromRequest = (
3434
requestMetadata,
3535
};
3636

37-
const session = plainToInstance(SessionMetadata, requestSession, { groups: ['security'] });
37+
const session = plainToInstance(SessionMetadata, requestSession, {
38+
groups: ['security'],
39+
});
3840

3941
const errors = validator.validateSync(session, {
4042
whitelist: false, // we need this to allow additional fields if needed for flexibility

redisinsight/api/src/common/logger/app-logger.spec.ts

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,30 @@ const logLevels = Object.keys(mockWinstonLogger);
2222
jest.spyOn(WinstonModule, 'createLogger').mockReturnValue(mockWinstonLogger);
2323

2424
const getSessionMetadata = () =>
25-
plainToInstance(SessionMetadata, {
26-
userId: '123',
27-
sessionId: 'test-session-id',
28-
requestMetadata: {
29-
any: 'data',
25+
plainToInstance(
26+
SessionMetadata,
27+
{
28+
userId: '123',
29+
sessionId: 'test-session-id',
30+
requestMetadata: {
31+
any: 'data',
32+
},
3033
},
31-
}, { groups: ['security' ] });
34+
{ groups: ['security'] },
35+
);
3236

3337
const getClientMetadata = () =>
34-
plainToInstance(ClientMetadata, {
35-
sessionMetadata: getSessionMetadata(),
36-
databaseId: 'db-123',
37-
context: ClientContext.Browser,
38-
uniqueId: 'unique-id',
39-
db: 1,
40-
}, { groups: ['security' ] });
38+
plainToInstance(
39+
ClientMetadata,
40+
{
41+
sessionMetadata: getSessionMetadata(),
42+
databaseId: 'db-123',
43+
context: ClientContext.Browser,
44+
uniqueId: 'unique-id',
45+
db: 1,
46+
},
47+
{ groups: ['security'] },
48+
);
4149

4250
describe('AppLogger', () => {
4351
let logger: AppLogger;

redisinsight/api/src/common/logger/app-logger.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ export class AppLogger implements LoggerService {
109109
context,
110110
error,
111111
...instanceToPlain(userMetadata),
112-
data: optionalParamsCopy?.length ? logDataToPlain(optionalParamsCopy) : undefined,
112+
data: optionalParamsCopy?.length
113+
? logDataToPlain(optionalParamsCopy)
114+
: undefined,
113115
};
114116
}
115117

redisinsight/api/src/common/middlewares/body-parser.middleware.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ export default (
2222
return res
2323
.status(HttpStatus.PAYLOAD_TOO_LARGE)
2424
.set('Access-Control-Allow-Origin', serverConfig.cors.origin)
25-
.set('Access-Control-Allow-Credentials', `${serverConfig.cors.credentials}`)
25+
.set(
26+
'Access-Control-Allow-Credentials',
27+
`${serverConfig.cors.credentials}`,
28+
)
2629
.json(exception.getResponse());
2730
}
2831

redisinsight/api/src/constants/error-messages.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ export default {
4444
`Could not connect to ${url}, please check the CA or Client certificate.`,
4545
INCORRECT_CREDENTIALS: (url) =>
4646
`Could not connect to ${url}, please check the Username or Password.`,
47-
DATABASE_DEFAULT_USER_DISABLED: 'Database does not have default user enabled.',
47+
DATABASE_DEFAULT_USER_DISABLED:
48+
'Database does not have default user enabled.',
4849
DATABASE_MANAGEMENT_IS_DISABLED:
4950
'Database connection management is disabled.',
5051
CA_CERT_EXIST: 'This ca certificate name is already in use.',
@@ -159,7 +160,8 @@ export default {
159160
'Encountered a timeout error while attempting to retrieve data',
160161
RDI_VALIDATION_ERROR: 'Validation error',
161162
INVALID_RDI_INSTANCE_ID: 'Invalid rdi instance id.',
162-
UNSAFE_BIG_JSON_LENGTH: 'This JSON is too large. Try opening it with Redis Insight Desktop.',
163+
UNSAFE_BIG_JSON_LENGTH:
164+
'This JSON is too large. Try opening it with Redis Insight Desktop.',
163165

164166
// database settings
165167
DATABASE_SETTINGS_NOT_FOUND: 'Could not find settings for this database',

redisinsight/api/src/init-helper.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,25 @@ export const migrateHomeFolder = async () => {
4646
};
4747

4848
/**
49-
* Remove old folders
49+
* Remove a folder
5050
*/
51-
export const removeOldFolders = async () => {
51+
export const removeFolder = async (path: string) => {
5252
try {
53-
// remove old folders
54-
await PATH_CONFIG.oldFolders?.map(removeFolder);
53+
if (await fs.pathExists(path)) {
54+
await fs.rm(path, { recursive: true, force: true });
55+
}
5556
} catch (e) {
5657
// continue initialization even without removing
5758
}
5859
};
5960

6061
/**
61-
* Remove a folder
62+
* Remove old folders
6263
*/
63-
export const removeFolder = async (path: string) => {
64+
export const removeOldFolders = async () => {
6465
try {
65-
if (await fs.pathExists(path)) {
66-
await fs.rm(path, { recursive: true, force: true });
67-
}
66+
// remove old folders
67+
await PATH_CONFIG.oldFolders?.map(removeFolder);
6868
} catch (e) {
6969
// continue initialization even without removing
7070
}

0 commit comments

Comments
 (0)