From cec8aba1b7dd80b7ccc094a153dc5bc7bb8dedf5 Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Wed, 24 Sep 2025 12:04:46 +0200 Subject: [PATCH] style(commons): apply stricter linting --- packages/commons/src/Utility.ts | 6 +++--- packages/commons/src/envUtils.ts | 2 +- packages/commons/src/index.ts | 6 +++--- packages/commons/tests/types/LambdaInterface.test.ts | 3 ++- packages/commons/tests/unit/awsSdkUtils.test.ts | 4 ++-- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/packages/commons/src/Utility.ts b/packages/commons/src/Utility.ts index 89f1dbd03d..4f21aab7ae 100644 --- a/packages/commons/src/Utility.ts +++ b/packages/commons/src/Utility.ts @@ -10,9 +10,9 @@ * To learn more about the Lambda execution environment lifecycle, see the [Execution environment section](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-context.html) of the AWS Lambda documentation. * * As a Powertools for AWS Lambda (TypeScript) user you probably won't be using this class directly, in fact if you use other Powertools for AWS utilities the cold start heuristic found here is already used to: - * * Add a `coldStart` key to the structured logs when injecting context information in `Logger` - * * Emit a metric during a cold start function invocation in `Metrics` - * * Annotate the invocation segment with a `coldStart` key in `Tracer` + * - Add a `coldStart` key to the structured logs when injecting context information in `Logger` + * - Emit a metric during a cold start function invocation in `Metrics` + * - Annotate the invocation segment with a `coldStart` key in `Tracer` * * If you want to use this logic in your own utilities, `Utility` provides two methods: * diff --git a/packages/commons/src/envUtils.ts b/packages/commons/src/envUtils.ts index b9848dc993..cfc4b2adfa 100644 --- a/packages/commons/src/envUtils.ts +++ b/packages/commons/src/envUtils.ts @@ -107,7 +107,7 @@ const getNumberFromEnv = ({ const parsedValue = Number(value); if (Number.isNaN(parsedValue)) { - throw new Error(`Environment variable ${key} must be a number`); + throw new TypeError(`Environment variable ${key} must be a number`); } return parsedValue; diff --git a/packages/commons/src/index.ts b/packages/commons/src/index.ts index f4eb6ce10b..aed1788618 100644 --- a/packages/commons/src/index.ts +++ b/packages/commons/src/index.ts @@ -1,10 +1,10 @@ import { PT_VERSION } from './version.js'; const env = process.env.AWS_EXECUTION_ENV || 'NA'; -if (!process.env.AWS_SDK_UA_APP_ID) { - process.env.AWS_SDK_UA_APP_ID = `PT/NO-OP/${PT_VERSION}/PTEnv/${env}`; -} else { +if (process.env.AWS_SDK_UA_APP_ID) { process.env.AWS_SDK_UA_APP_ID = `${process.env.AWS_SDK_UA_APP_ID}/PT/NO-OP/${PT_VERSION}/PTEnv/${env}`; +} else { + process.env.AWS_SDK_UA_APP_ID = `PT/NO-OP/${PT_VERSION}/PTEnv/${env}`; } export { addUserAgentMiddleware, isSdkClient } from './awsSdkUtils.js'; diff --git a/packages/commons/tests/types/LambdaInterface.test.ts b/packages/commons/tests/types/LambdaInterface.test.ts index 5b50d083fe..75be898c11 100644 --- a/packages/commons/tests/types/LambdaInterface.test.ts +++ b/packages/commons/tests/types/LambdaInterface.test.ts @@ -21,11 +21,12 @@ describe('Type: LambdaInterface', () => { expectTypeOf(lambda.handler).toBeFunction(); }); - it('works with an async handler', async () => { + it('works with an async handler', () => { // Prepare class Lambda implements LambdaInterface { public async handler(_event: unknown, context: Context) { context.getRemainingTimeInMillis(); + await new Promise((r) => setTimeout(r, 1)); return 'Hello World'; } } diff --git a/packages/commons/tests/unit/awsSdkUtils.test.ts b/packages/commons/tests/unit/awsSdkUtils.test.ts index 2029c2ecc7..5223605292 100644 --- a/packages/commons/tests/unit/awsSdkUtils.test.ts +++ b/packages/commons/tests/unit/awsSdkUtils.test.ts @@ -28,7 +28,7 @@ describe('Helpers: awsSdk', () => { expect(console.warn).toHaveBeenCalledTimes(1); }); - it('should return and do nothing if the client already has a Powertools UA middleware', async () => { + it('should return and do nothing if the client already has a Powertools UA middleware', () => { // Prepare const client = { middlewareStack: { @@ -51,7 +51,7 @@ describe('Helpers: awsSdk', () => { expect(client.middlewareStack.addRelativeTo).toHaveBeenCalledTimes(0); }); - it('should call the function to add the middleware with the correct arguments', async () => { + it('should call the function to add the middleware with the correct arguments', () => { // Prepare const client = { middlewareStack: {