Skip to content

Commit 1fd4d04

Browse files
committed
FPAD-7590: Add more eslint rules
1 parent 0c6d008 commit 1fd4d04

14 files changed

Lines changed: 75 additions & 60 deletions

eslint.config.mjs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,42 @@ import eslintPluginTsdoc from 'eslint-plugin-tsdoc';
88
import globals from 'globals';
99

1010
export default defineConfig(
11+
eslintPluginUnicorn.configs.recommended,
1112
{
1213
ignores: ['**/node_modules/**', '**/feature-tests/**', '**/*.test.ts', 'coverage/**', '**/.aws-sam/**'],
1314
},
1415
{
1516
files: ['**/*.ts'],
16-
extends: [eslint.configs.recommended, tseslint.configs.strictTypeChecked],
17+
extends: [eslint.configs.recommended, tseslint.configs.strictTypeChecked, tseslint.configs.stylisticTypeChecked],
1718
languageOptions: {
1819
globals: globals.builtin,
1920
parserOptions: {
2021
projectService: true,
2122
},
2223
},
2324
plugins: {
24-
unicorn: eslintPluginUnicorn,
2525
tsdoc: eslintPluginTsdoc,
2626
},
2727
rules: {
2828
'@typescript-eslint/no-floating-promises': ['error'],
2929
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
3030
'@typescript-eslint/no-explicit-any': ['error'],
31+
'@typescript-eslint/non-nullable-type-assertion-style': ['off'],
32+
'@typescript-eslint/switch-exhaustiveness-check': ['error'],
33+
'arrow-body-style': ['error', 'as-needed'],
3134
'keyword-spacing': ['error', { after: true }],
3235
'space-before-blocks': ['error', 'always'],
3336
'space-before-function-paren': ['error', { anonymous: 'always', named: 'never', asyncArrow: 'always' }],
3437
'object-curly-spacing': ['error', 'always'],
3538
'unicorn/filename-case': ['error', { case: 'kebabCase' }],
36-
'unicorn/prevent-abbreviations': ['error'],
39+
'unicorn/prevent-abbreviations': ['off'],
3740
'unicorn/prefer-string-raw': ['off'],
3841
'unicorn/error-message': ['error'],
3942
'unicorn/no-array-reduce': ['off'],
4043
'unicorn/prefer-logical-operator-over-ternary': ['error'],
4144
'unicorn/prefer-spread': ['error'],
45+
'unicorn/prefer-ternary': ['error'],
46+
'unicorn/no-array-for-each': ['error'],
4247
'tsdoc/syntax': ['error'],
4348
},
4449
},

jest.config.js renamed to jest.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = {
1+
export default {
22
preset: 'ts-jest',
33
testEnvironment: 'node',
44
transform: {

src/commons/build-partial-update-state-command.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,50 +50,50 @@ export const buildPartialUpdateAccountStateCommand = (
5050
};
5151

5252
if (eventName === EventsEnum.IPV_ACCOUNT_INTERVENTION_END) {
53-
baseUpdateItemCommandInput['ExpressionAttributeNames']['#RIdA'] = 'reprovedIdentityAt';
54-
baseUpdateItemCommandInput['ExpressionAttributeValues'][':rida'] = { N: String(eventTimestamp) };
55-
baseUpdateItemCommandInput['ExpressionAttributeNames']['#H'] = 'history';
56-
baseUpdateItemCommandInput['ExpressionAttributeValues'][':h'] = {
53+
baseUpdateItemCommandInput.ExpressionAttributeNames['#RIdA'] = 'reprovedIdentityAt';
54+
baseUpdateItemCommandInput.ExpressionAttributeValues[':rida'] = { N: String(eventTimestamp) };
55+
baseUpdateItemCommandInput.ExpressionAttributeNames['#H'] = 'history';
56+
baseUpdateItemCommandInput.ExpressionAttributeValues[':h'] = {
5757
L: extractValidHistoryItems(historyList, currentTimestamp),
5858
};
59-
baseUpdateItemCommandInput['UpdateExpression'] += ', #RIdA = :rida, #H = :h';
59+
baseUpdateItemCommandInput.UpdateExpression += ', #RIdA = :rida, #H = :h';
6060
return baseUpdateItemCommandInput;
6161
}
6262

6363
if (
6464
eventName === EventsEnum.AUTH_PASSWORD_RESET_SUCCESSFUL ||
6565
eventName === EventsEnum.AUTH_PASSWORD_RESET_SUCCESSFUL_FOR_TEST_CLIENT
6666
) {
67-
baseUpdateItemCommandInput['ExpressionAttributeNames']['#RPswdA'] = 'resetPasswordAt';
68-
baseUpdateItemCommandInput['ExpressionAttributeValues'][':rpswda'] = { N: String(eventTimestamp) };
69-
baseUpdateItemCommandInput['ExpressionAttributeNames']['#H'] = 'history';
70-
baseUpdateItemCommandInput['ExpressionAttributeValues'][':h'] = {
67+
baseUpdateItemCommandInput.ExpressionAttributeNames['#RPswdA'] = 'resetPasswordAt';
68+
baseUpdateItemCommandInput.ExpressionAttributeValues[':rpswda'] = { N: String(eventTimestamp) };
69+
baseUpdateItemCommandInput.ExpressionAttributeNames['#H'] = 'history';
70+
baseUpdateItemCommandInput.ExpressionAttributeValues[':h'] = {
7171
L: extractValidHistoryItems(historyList, currentTimestamp),
7272
};
73-
baseUpdateItemCommandInput['UpdateExpression'] += ', #RPswdA = :rpswda, #H = :h';
73+
baseUpdateItemCommandInput.UpdateExpression += ', #RPswdA = :rpswda, #H = :h';
7474
return baseUpdateItemCommandInput;
7575
}
7676

7777
if (!interventionName) {
7878
addMetric(MetricNames.INTERVENTION_DID_NOT_HAVE_NAME_IN_CURRENT_CONFIG);
7979
throw new Error('The intervention received did not have an interventionName field.');
8080
}
81-
baseUpdateItemCommandInput['ExpressionAttributeNames']['#INT'] = 'intervention';
82-
baseUpdateItemCommandInput['ExpressionAttributeValues'][':int'] = { S: interventionName };
83-
baseUpdateItemCommandInput['ExpressionAttributeNames']['#AA'] = 'appliedAt';
84-
baseUpdateItemCommandInput['ExpressionAttributeValues'][':aa'] = { N: String(currentTimestamp) };
85-
baseUpdateItemCommandInput['ExpressionAttributeNames']['#SA'] = 'sentAt';
86-
baseUpdateItemCommandInput['ExpressionAttributeValues'][':sa'] = { N: String(eventTimestamp) };
81+
baseUpdateItemCommandInput.ExpressionAttributeNames['#INT'] = 'intervention';
82+
baseUpdateItemCommandInput.ExpressionAttributeValues[':int'] = { S: interventionName };
83+
baseUpdateItemCommandInput.ExpressionAttributeNames['#AA'] = 'appliedAt';
84+
baseUpdateItemCommandInput.ExpressionAttributeValues[':aa'] = { N: String(currentTimestamp) };
85+
baseUpdateItemCommandInput.ExpressionAttributeNames['#SA'] = 'sentAt';
86+
baseUpdateItemCommandInput.ExpressionAttributeValues[':sa'] = { N: String(eventTimestamp) };
8787
const stringBuilder = new HistoryStringBuilder();
88-
baseUpdateItemCommandInput['ExpressionAttributeNames']['#H'] = 'history';
89-
baseUpdateItemCommandInput['ExpressionAttributeValues'][':h'] = {
88+
baseUpdateItemCommandInput.ExpressionAttributeNames['#H'] = 'history';
89+
baseUpdateItemCommandInput.ExpressionAttributeValues[':h'] = {
9090
L: [
9191
...extractValidHistoryItems(historyList, currentTimestamp),
9292
{ S: stringBuilder.getHistoryString(interventionEvent, eventTimestamp) },
9393
],
9494
};
95-
baseUpdateItemCommandInput['UpdateExpression'] += ', #INT = :int, #SA = :sa, #AA = :aa, #H = :h';
96-
baseUpdateItemCommandInput['UpdateExpression'] += buildRemoveExpression(finalState);
95+
baseUpdateItemCommandInput.UpdateExpression += ', #INT = :int, #SA = :sa, #AA = :aa, #H = :h';
96+
baseUpdateItemCommandInput.UpdateExpression += buildRemoveExpression(finalState);
9797

9898
return baseUpdateItemCommandInput;
9999
};

src/commons/get-env-or-throw.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const getEnvOrThrow = (name: string) => {
2+
const value = process.env[name];
3+
4+
if (!value) throw new Error(`Environment variable ${name} not found`);
5+
6+
return value;
7+
};
8+
9+
export default getEnvOrThrow;

src/commons/history-string-builder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { AccountStateEngine } from '../services/account-states/account-state-eng
77
* and converts a history string into an object containing the required fields.
88
*/
99
export class HistoryStringBuilder {
10-
separator: string = '|';
10+
separator = '|';
1111
/**
1212
* Method to build the history string from parts
1313
* @param event_timestamp_ms - sentAt part of the history string

src/commons/metrics.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export function addMetric(
1616
metricName: string,
1717
metadata: { key: string; value: string }[] = [],
1818
value = 1,
19-
dimensions?: { [key: string]: string },
19+
dimensions?: Record<string, string>,
2020
) {
2121
for (const data of metadata) {
2222
metric.addMetadata(data.key, data.value);

src/contract-testing/test-helpers/connect-to-pact-broker.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import getEnvOrThrow from '../../commons/get-env-or-throw';
2+
13
//required to connect to PactBroker as Pact libraries don't allow testSource parameter to be passed
24
function connectToPactBroker(pact_url: string, pact_user: string, pact_password: string): string {
35
const auth = btoa(`${pact_user}:${pact_password}`);
@@ -19,7 +21,7 @@ function connectToPactBroker(pact_url: string, pact_user: string, pact_password:
1921
}
2022

2123
connectToPactBroker(
22-
(process.env['PACT_BROKER_URL'] as string) + '?testSource=' + (process.env['PACT_BROKER_SOURCE_SECRET'] as string),
23-
process.env['PACT_BROKER_USER'] as string,
24-
process.env['PACT_BROKER_PASSWORD'] as string,
24+
getEnvOrThrow('PACT_BROKER_URL') + '?testSource=' + getEnvOrThrow('PACT_BROKER_SOURCE_SECRET'),
25+
getEnvOrThrow('PACT_BROKER_USER'),
26+
getEnvOrThrow('PACT_BROKER_PASSWORD'),
2527
);

src/contract-testing/test-helpers/mock-server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export function setupServer(port: number) {
3333
app.disable('x-powered-by');
3434

3535
app.get('/V1/ais/:userId', async (request, response) => {
36-
const apiGatewayEvent = createDefaultApiRequest(request.params['userId']);
36+
const apiGatewayEvent = createDefaultApiRequest(request.params.userId);
3737
try {
3838
result = await handle(apiGatewayEvent, dummyContext);
3939
response.status(result.statusCode).json(JSON.parse(result.body));

src/contract-testing/test-helpers/publish-pacts.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import path from 'node:path';
22
import pact from '@pact-foundation/pact-cli';
3+
import getEnvOrThrow from '../../commons/get-env-or-throw';
34

45
const publishPact = async () => {
56
console.log('STARTING PUBLISH PACT');
67
try {
78
const publishOptions = {
89
pactFilesOrDirs: [path.resolve(process.cwd(), 'pacts')],
9-
pactBroker: process.env['PACT_BROKER_URL'] as string,
10-
pactBrokerUsername: process.env['PACT_BROKER_USER'] as string,
11-
pactBrokerPassword: process.env['PACT_BROKER_PASSWORD'] as string,
10+
pactBroker: getEnvOrThrow('PACT_BROKER_URL'),
11+
pactBrokerUsername: getEnvOrThrow('PACT_BROKER_USER'),
12+
pactBrokerPassword: getEnvOrThrow('PACT_BROKER_PASSWORD'),
1213
logLevel: 'info',
13-
consumerVersion: process.env['CONSUMER_APP_VERSION'] as string,
14-
branch: process.env['GIT_BRANCH'] as string,
14+
consumerVersion: getEnvOrThrow('CONSUMER_APP_VERSION'),
15+
branch: getEnvOrThrow('GIT_BRANCH'),
1516
};
1617

1718
await pact.publishPacts(publishOptions);

src/data-types/interfaces.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,19 +122,16 @@ export interface DeleteStatusUpdateSNSMessage {
122122
}
123123

124124
export interface TransitionConfigurationInterface {
125-
nodes: {
126-
[key: string]: StateDetails;
127-
};
128-
edges: {
129-
[key: string]: {
125+
nodes: Record<string, StateDetails>;
126+
edges: Record<
127+
string,
128+
{
130129
to: string;
131130
name: EventsEnum;
132131
interventionName?: AISInterventionTypes;
133-
};
134-
};
135-
adjacency: {
136-
[key: string]: string[];
137-
};
132+
}
133+
>;
134+
adjacency: Record<string, string[]>;
138135
}
139136

140137
export interface AccountStatus {

0 commit comments

Comments
 (0)