Skip to content

Commit 56534e5

Browse files
committed
FPAD-7660: Add eslint rule to restrict top level arrow functions
1 parent 384b732 commit 56534e5

9 files changed

Lines changed: 28 additions & 19 deletions

eslint.config.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ export default defineConfig(
3232
'@typescript-eslint/switch-exhaustiveness-check': ['error'],
3333
'arrow-body-style': ['error', 'as-needed'],
3434
'keyword-spacing': ['error', { after: true }],
35+
'no-restricted-syntax': [
36+
'error',
37+
{
38+
selector: 'ExportNamedDeclaration > VariableDeclaration > VariableDeclarator > ArrowFunctionExpression',
39+
message:
40+
"Top-level exported functions should use the 'function' keyword for better readability and hoisting.",
41+
},
42+
],
3543
'space-before-blocks': ['error', 'always'],
3644
'space-before-function-paren': ['error', { anonymous: 'always', named: 'never', asyncArrow: 'always' }],
3745
'object-curly-spacing': ['error', 'always'],

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ type DeepRequiredKey<T, K extends keyof T> = Omit<T, K> & {
1818
* @param interventionName - optional intervention name if the event was a fraud intervention
1919
* @param historyList - list of history items
2020
*/
21-
export const buildPartialUpdateAccountStateCommand = (
21+
export function buildPartialUpdateAccountStateCommand(
2222
finalState: StateDetails,
2323
eventName: EventsEnum,
2424
currentTimestamp: number,
2525
interventionEvent: TxMAIngressEvent,
2626
historyList: string[],
2727
interventionName?: AISInterventionTypes,
28-
): Partial<UpdateItemCommandInput> => {
28+
): Partial<UpdateItemCommandInput> {
2929
const eventTimestamp = interventionEvent.event_timestamp_ms ?? interventionEvent.timestamp * 1000;
3030

3131
const baseUpdateItemCommandInput: DeepRequiredKey<
@@ -96,7 +96,7 @@ export const buildPartialUpdateAccountStateCommand = (
9696
baseUpdateItemCommandInput.UpdateExpression += buildRemoveExpression(finalState);
9797

9898
return baseUpdateItemCommandInput;
99-
};
99+
}
100100

101101
/**
102102
* Helper function to build the Remove Expression for DynamoDB update

src/handlers/account-deletion-processor-handler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const ddbService = new DynamoDatabaseService(appConfig.tableName);
1515
* @param context - This object provides methods and properties that provide information about the invocation, function, and execution environment.
1616
* @returns - Void. Sends off response to DynamoDB.
1717
*/
18-
export const handler = async (event: SQSEvent, context: Context): Promise<void> => {
18+
export async function handler(event: SQSEvent, context: Context): Promise<void> {
1919
logger.addContext(context);
2020
if (!event.Records[0]) {
2121
logger.error('The event does not contain any records.');
@@ -28,7 +28,7 @@ export const handler = async (event: SQSEvent, context: Context): Promise<void>
2828
}).filter((prom) => prom !== undefined);
2929
await Promise.all(updateRecordsByIdPromises);
3030
metric.publishStoredMetrics();
31-
};
31+
}
3232

3333
/**
3434
* Function to take the User ID from the SQS Record.

src/handlers/interventions-processor-handler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const accountStateEngine = AccountStateEngine.getInstance();
3838
* @param context - context object
3939
* @returns - Promise of SQS Partial Batch Response
4040
*/
41-
export const handler = async (event: SQSEvent, context: Context): Promise<SQSBatchResponse> => {
41+
export async function handler(event: SQSEvent, context: Context): Promise<SQSBatchResponse> {
4242
logger.addContext(context);
4343

4444
if (event.Records.length === 0) {
@@ -64,7 +64,7 @@ export const handler = async (event: SQSEvent, context: Context): Promise<SQSBat
6464
return {
6565
batchItemFailures: itemFailures,
6666
};
67-
};
67+
}
6868

6969
/**
7070
* Main worker function. It receives an SQS record and processes it according to business logic

src/handlers/invoke-private-api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ interface CustomEvent {
99
headers?: Record<string, string>;
1010
}
1111

12-
export const handle = async (event: CustomEvent) => {
12+
export async function handle(event: CustomEvent) {
1313
const baseUrl = event.baseUrl ?? getBaseUrl();
1414
const endpoint = event.endpoint ?? getEndpoint();
1515
const userId = encodeURI(event.userId ?? getUserId());
@@ -34,7 +34,7 @@ export const handle = async (event: CustomEvent) => {
3434
statusCode: response.status,
3535
body: JSON.stringify(response),
3636
};
37-
};
37+
}
3838

3939
function getUserId() {
4040
return getEnvOrThrow('USER_ID');

src/handlers/status-retriever-handler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const dynamoDatabaseServiceInstance = new DynamoDatabaseService(appConfig.tableN
1717
* @param context - This object provides methods and properties that provide information about the invocation, function, and execution environment.
1818
* @returns - The status of the account when matched with the User ID. Returns a default object if unable to do so. Also returns the relevant status code.
1919
*/
20-
export const handle = async (event: APIGatewayEvent, context: Context): Promise<APIGatewayProxyResult> => {
20+
export async function handle(event: APIGatewayEvent, context: Context): Promise<APIGatewayProxyResult> {
2121
logger.addContext(context);
2222

2323
if (!event.pathParameters?.['userId']) {
@@ -71,7 +71,7 @@ export const handle = async (event: APIGatewayEvent, context: Context): Promise<
7171
statusCode: 500,
7272
body: JSON.stringify({ message: 'Internal Server Error.' }),
7373
};
74-
};
74+
}
7575

7676
/**
7777
* Helper function to remove whitespace from the user id and to validate that the event contains a valid user id

src/handlers/txma-handler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { sendBatchSqsMessage } from '../services/send-sqs-message';
55
import { addMetric, metric } from '../commons/metrics';
66
import { MetricNames } from '../data-types/constants';
77

8-
export const handler = async (event: SQSEvent, context: Context): Promise<void> => {
8+
export async function handler(event: SQSEvent, context: Context): Promise<void> {
99
logger.addContext(context);
1010

1111
if (!process.env['ACCOUNT_DELETION_SQS_QUEUE']) {
@@ -58,4 +58,4 @@ export const handler = async (event: SQSEvent, context: Context): Promise<void>
5858
}
5959

6060
metric.publishStoredMetrics();
61-
};
61+
}

src/services/account-states/account-state-engine.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ export class AccountStateEngine {
158158
}
159159
}
160160

161+
// eslint-disable-next-line no-restricted-syntax
161162
export const isCode = (value: string): value is Codes => Object.values(Codes).includes(value as Codes);
162163

163164
/**

src/services/send-sqs-message.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import {
99
} from '@aws-sdk/client-sqs';
1010
import logger from '../commons/logger';
1111

12-
export const sendSqsMessage = async (
12+
export async function sendSqsMessage(
1313
messageBody: string,
1414
queueUrl: string | undefined,
15-
): Promise<SendMessageCommandOutput> => {
15+
): Promise<SendMessageCommandOutput> {
1616
if (!process.env['AWS_REGION']) {
1717
logger.error('AWS_REGION environment variable is not set');
1818
throw new Error('AWS_REGION environment variable not set');
@@ -24,12 +24,12 @@ export const sendSqsMessage = async (
2424
MessageBody: messageBody,
2525
};
2626
return client.send(new SendMessageCommand(message));
27-
};
27+
}
2828

29-
export const sendBatchSqsMessage = async (
29+
export async function sendBatchSqsMessage(
3030
messages: SendMessageBatchRequestEntry[],
3131
queueUrl: string | undefined,
32-
): Promise<SendMessageBatchCommandOutput> => {
32+
): Promise<SendMessageBatchCommandOutput> {
3333
if (!process.env['AWS_REGION']) {
3434
logger.error('AWS_REGION environment variable is not set');
3535
throw new Error('AWS_REGION environment variable not set');
@@ -42,4 +42,4 @@ export const sendBatchSqsMessage = async (
4242
};
4343
const command = new SendMessageBatchCommand(parameters);
4444
return client.send(command);
45-
};
45+
}

0 commit comments

Comments
 (0)