From 266301e36b3349d1e5dc9bd3f95cd45ea27b264c Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Mon, 22 Jul 2024 13:12:42 +0200 Subject: [PATCH 1/3] chore(maintenance): add biome.js --- biome.json | 26 ++++++++ package-lock.json | 156 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + 3 files changed, 183 insertions(+) create mode 100644 biome.json diff --git a/biome.json b/biome.json new file mode 100644 index 0000000000..19d23a030d --- /dev/null +++ b/biome.json @@ -0,0 +1,26 @@ +{ + "$schema": "https://biomejs.dev/schemas/1.8.3/schema.json", + "organizeImports": { + "enabled": true + }, + "linter": { + "enabled": true, + "rules": { + "recommended": true + } + }, + "formatter": { + "enabled": true, + "indentStyle": "space", + "indentWidth": 2, + "lineEnding": "lf" + }, + "javascript": { + "formatter": { + "semicolons": "always", + "bracketSpacing": true, + "quoteStyle": "single", + "trailingComma": "es5" + } + } +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index ea890dc6e3..80d5733127 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,6 +24,7 @@ "examples/app" ], "devDependencies": { + "@biomejs/biome": "^1.8.3", "@types/aws-lambda": "^8.10.141", "@types/jest": "^29.5.12", "@types/node": "^20.14.10", @@ -1848,6 +1849,161 @@ "integrity": "sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==", "dev": true }, + "node_modules/@biomejs/biome": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/@biomejs/biome/-/biome-1.8.3.tgz", + "integrity": "sha512-/uUV3MV+vyAczO+vKrPdOW0Iaet7UnJMU4bNMinggGJTAnBPjCoLEYcyYtYHNnUNYlv4xZMH6hVIQCAozq8d5w==", + "dev": true, + "hasInstallScript": true, + "bin": { + "biome": "bin/biome" + }, + "engines": { + "node": ">=14.21.3" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/biome" + }, + "optionalDependencies": { + "@biomejs/cli-darwin-arm64": "1.8.3", + "@biomejs/cli-darwin-x64": "1.8.3", + "@biomejs/cli-linux-arm64": "1.8.3", + "@biomejs/cli-linux-arm64-musl": "1.8.3", + "@biomejs/cli-linux-x64": "1.8.3", + "@biomejs/cli-linux-x64-musl": "1.8.3", + "@biomejs/cli-win32-arm64": "1.8.3", + "@biomejs/cli-win32-x64": "1.8.3" + } + }, + "node_modules/@biomejs/cli-darwin-arm64": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/@biomejs/cli-darwin-arm64/-/cli-darwin-arm64-1.8.3.tgz", + "integrity": "sha512-9DYOjclFpKrH/m1Oz75SSExR8VKvNSSsLnVIqdnKexj6NwmiMlKk94Wa1kZEdv6MCOHGHgyyoV57Cw8WzL5n3A==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-darwin-x64": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/@biomejs/cli-darwin-x64/-/cli-darwin-x64-1.8.3.tgz", + "integrity": "sha512-UeW44L/AtbmOF7KXLCoM+9PSgPo0IDcyEUfIoOXYeANaNXXf9mLUwV1GeF2OWjyic5zj6CnAJ9uzk2LT3v/wAw==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-linux-arm64": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-arm64/-/cli-linux-arm64-1.8.3.tgz", + "integrity": "sha512-fed2ji8s+I/m8upWpTJGanqiJ0rnlHOK3DdxsyVLZQ8ClY6qLuPc9uehCREBifRJLl/iJyQpHIRufLDeotsPtw==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-linux-arm64-musl": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-arm64-musl/-/cli-linux-arm64-musl-1.8.3.tgz", + "integrity": "sha512-9yjUfOFN7wrYsXt/T/gEWfvVxKlnh3yBpnScw98IF+oOeCYb5/b/+K7YNqKROV2i1DlMjg9g/EcN9wvj+NkMuQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-linux-x64": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-x64/-/cli-linux-x64-1.8.3.tgz", + "integrity": "sha512-I8G2QmuE1teISyT8ie1HXsjFRz9L1m5n83U1O6m30Kw+kPMPSKjag6QGUn+sXT8V+XWIZxFFBoTDEDZW2KPDDw==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-linux-x64-musl": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-x64-musl/-/cli-linux-x64-musl-1.8.3.tgz", + "integrity": "sha512-UHrGJX7PrKMKzPGoEsooKC9jXJMa28TUSMjcIlbDnIO4EAavCoVmNQaIuUSH0Ls2mpGMwUIf+aZJv657zfWWjA==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-win32-arm64": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/@biomejs/cli-win32-arm64/-/cli-win32-arm64-1.8.3.tgz", + "integrity": "sha512-J+Hu9WvrBevfy06eU1Na0lpc7uR9tibm9maHynLIoAjLZpQU3IW+OKHUtyL8p6/3pT2Ju5t5emReeIS2SAxhkQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-win32-x64": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/@biomejs/cli-win32-x64/-/cli-win32-x64-1.8.3.tgz", + "integrity": "sha512-/PJ59vA1pnQeKahemaQf4Nyj7IKUvGQSc3Ze1uIGi+Wvr1xF7rGobSrAAG01T/gUDG21vkDsZYM03NAmPiVkqg==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=14.21.3" + } + }, "node_modules/@cspotcode/source-map-support": { "version": "0.8.1", "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", diff --git a/package.json b/package.json index 66fcd8ef7d..4efd18859e 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ }, "homepage": "https://github.com/aws-powertools/powertools-lambda-typescript#readme", "devDependencies": { + "@biomejs/biome": "^1.8.3", "@types/aws-lambda": "^8.10.141", "@types/jest": "^29.5.12", "@types/node": "^20.14.10", From 0ed3e1c55fb81bf175a5129cfab99c4109861dfb Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Mon, 22 Jul 2024 15:52:41 +0200 Subject: [PATCH 2/3] chore(maintenance): add biome to project --- biome.json | 15 +++++++++++++-- examples/app/cdk/example-stack.ts | 4 ++-- .../app/functions/commons/helpers/get-item.ts | 4 ++-- .../app/functions/commons/helpers/put-item.ts | 6 +++--- .../app/functions/commons/helpers/scan-items.ts | 4 ++-- examples/app/package.json | 10 +++------- package.json | 4 ++-- 7 files changed, 27 insertions(+), 20 deletions(-) diff --git a/biome.json b/biome.json index 19d23a030d..46c5a0c5d5 100644 --- a/biome.json +++ b/biome.json @@ -13,14 +13,25 @@ "enabled": true, "indentStyle": "space", "indentWidth": 2, - "lineEnding": "lf" + "lineEnding": "lf", + "lineWidth": 80 }, "javascript": { "formatter": { "semicolons": "always", "bracketSpacing": true, "quoteStyle": "single", - "trailingComma": "es5" + "trailingCommas": "es5" } + }, + "files": { + "ignore": [ + "node_modules", + "coverage", + "lib", + "cdk.out", + "site", + ".aws-sam" + ] } } \ No newline at end of file diff --git a/examples/app/cdk/example-stack.ts b/examples/app/cdk/example-stack.ts index b5e7f66284..067ef6752f 100644 --- a/examples/app/cdk/example-stack.ts +++ b/examples/app/cdk/example-stack.ts @@ -1,4 +1,4 @@ -import { RemovalPolicy, Stack, StackProps } from 'aws-cdk-lib'; +import { RemovalPolicy, Stack, type StackProps } from 'aws-cdk-lib'; import { LambdaIntegration, RestApi } from 'aws-cdk-lib/aws-apigateway'; import { AttributeType, @@ -18,7 +18,7 @@ import { DynamoEventSource } from 'aws-cdk-lib/aws-lambda-event-sources'; import { OutputFormat } from 'aws-cdk-lib/aws-lambda-nodejs'; import { Queue } from 'aws-cdk-lib/aws-sqs'; import { StringParameter } from 'aws-cdk-lib/aws-ssm'; -import { Construct } from 'constructs'; +import type { Construct } from 'constructs'; import { FunctionWithLogGroup } from './function-with-logstream-construct.js'; export class PowertoolsExampleStack extends Stack { diff --git a/examples/app/functions/commons/helpers/get-item.ts b/examples/app/functions/commons/helpers/get-item.ts index 3ce1030ea7..165b01f0d0 100644 --- a/examples/app/functions/commons/helpers/get-item.ts +++ b/examples/app/functions/commons/helpers/get-item.ts @@ -1,7 +1,7 @@ +import { GetCommand, type GetCommandOutput } from '@aws-sdk/lib-dynamodb'; import { docClient } from '#clients/dynamodb'; import { itemsTableName } from '#constants'; import type { DebugLogger } from '#types'; -import { GetCommand, type GetCommandOutput } from '@aws-sdk/lib-dynamodb'; /** * Fetch an item from the DynamoDB table. @@ -22,7 +22,7 @@ const getItemDynamoDB = async ( }) ); - logger.debug(`ddb response`, { + logger.debug('ddb response', { response, }); diff --git a/examples/app/functions/commons/helpers/put-item.ts b/examples/app/functions/commons/helpers/put-item.ts index a978e0382c..853756899d 100644 --- a/examples/app/functions/commons/helpers/put-item.ts +++ b/examples/app/functions/commons/helpers/put-item.ts @@ -1,8 +1,8 @@ +import { randomUUID } from 'node:crypto'; +import { PutCommand } from '@aws-sdk/lib-dynamodb'; import { docClient } from '#clients/dynamodb'; import { itemsTableName } from '#constants'; import type { DebugLogger } from '#types'; -import { PutCommand } from '@aws-sdk/lib-dynamodb'; -import { randomUUID } from 'node:crypto'; /** * Put an item in the DynamoDB table. @@ -28,7 +28,7 @@ const putItemInDynamoDB = async ( }) ); - logger.debug(`ddb response`, { + logger.debug('ddb response', { response, }); diff --git a/examples/app/functions/commons/helpers/scan-items.ts b/examples/app/functions/commons/helpers/scan-items.ts index 858b752c1d..d528085f28 100644 --- a/examples/app/functions/commons/helpers/scan-items.ts +++ b/examples/app/functions/commons/helpers/scan-items.ts @@ -1,7 +1,7 @@ +import { ScanCommand, type ScanCommandOutput } from '@aws-sdk/lib-dynamodb'; import { docClient } from '#clients/dynamodb'; import { itemsTableName } from '#constants'; import type { DebugLogger } from '#types'; -import { ScanCommand, type ScanCommandOutput } from '@aws-sdk/lib-dynamodb'; /** * Scan the DynamoDB table and return all items. @@ -19,7 +19,7 @@ const scanItemsDynamoDB = async ( }) ); - logger.debug(`ddb response`, { + logger.debug('ddb response', { response, }); diff --git a/examples/app/package.json b/examples/app/package.json index 30b84d438e..8f6c790d63 100644 --- a/examples/app/package.json +++ b/examples/app/package.json @@ -11,16 +11,12 @@ "scripts": { "build": "echo 'Not applicable, run `npx cdk synth` instead to build the stack'", "test": "npm run test:unit", - "lint": "eslint --ext .ts,.js --no-error-on-unmatched-pattern .", - "lint-fix": "eslint --fix --ext .ts,.js --fix --no-error-on-unmatched-pattern .", + "lint": "biome lint .", + "lint:fix": "biome check --write .", "test:unit": "export POWERTOOLS_DEV=true && jest --silent", "test:e2e": "echo 'To be implemented ...'", "cdk": "cdk" }, - "lint-staged": { - "*.ts": "npm run lint-fix", - "*.js": "npm run lint-fix" - }, "type": "module", "imports": { "#types": "./functions/commons/types.js", @@ -64,4 +60,4 @@ "ts-node": "^10.9.2", "typescript": "^5.4.5" } -} +} \ No newline at end of file diff --git a/package.json b/package.json index 4efd18859e..c1f422af13 100644 --- a/package.json +++ b/package.json @@ -78,7 +78,7 @@ "typescript": "^5.4.5" }, "lint-staged": { - "*.{js,ts}": "eslint --fix", + "*.{js,ts}": "biome check --write", "*.md": "markdownlint-cli2 --fix" }, "engines": { @@ -89,4 +89,4 @@ "tar": "6.2.1" } } -} +} \ No newline at end of file From 6ad808ae3d4f7c1a81860a93fe65dced929111bc Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Mon, 22 Jul 2024 16:25:34 +0200 Subject: [PATCH 3/3] chore(maintenance): migrate commons utility to biome --- packages/commons/package.json | 31 ++++------------ packages/commons/src/awsSdkUtils.ts | 4 +-- .../src/config/EnvironmentVariablesService.ts | 4 +-- packages/commons/src/fromBase64.ts | 4 +-- .../src/middleware/cleanupMiddlewares.ts | 8 ++--- packages/commons/src/typeUtils.ts | 35 ++++++++++++------- packages/commons/tests/tsconfig.json | 17 ++++----- .../unit/EnvironmentVariablesService.test.ts | 6 ++-- .../tests/unit/LambdaInterface.test.ts | 9 ++--- packages/commons/tests/unit/Utility.test.ts | 16 --------- .../commons/tests/unit/awsSdkUtils.test.ts | 7 +++- .../tests/unit/cleanupMiddlewares.test.ts | 10 +++--- .../commons/tests/unit/fromBase64.test.ts | 4 +-- packages/commons/tests/unit/typeUtils.test.ts | 12 +++---- packages/commons/tsconfig.esm.json | 6 ++-- packages/commons/tsconfig.json | 18 +++++----- packages/commons/typedoc.json | 11 ++---- 17 files changed, 84 insertions(+), 118 deletions(-) diff --git a/packages/commons/package.json b/packages/commons/package.json index e94dc64d63..4d5ae71edc 100644 --- a/packages/commons/package.json +++ b/packages/commons/package.json @@ -19,8 +19,8 @@ "build:cjs": "tsc --build tsconfig.json && echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json", "build:esm": "tsc --build tsconfig.esm.json && echo '{ \"type\": \"module\" }' > lib/esm/package.json", "build": "npm run build:esm & npm run build:cjs", - "lint": "eslint --ext .ts,.js --no-error-on-unmatched-pattern .", - "lint-fix": "eslint --fix --ext .ts,.js --no-error-on-unmatched-pattern .", + "lint": "biome lint .", + "lint:fix": "biome check --write .", "prepack": "node ../../.github/scripts/release_patch_package_json.js ." }, "homepage": "https://github.com/aws-powertools/powertools-lambda-typescript/tree/main/packages/commons#readme", @@ -52,25 +52,14 @@ }, "typesVersions": { "*": { - "typeutils": [ - "lib/cjs/typeUtils.d.ts", - "lib/esm/typeUtils.d.ts" - ], - "utils/base64": [ - "lib/cjs/fromBase64.d.ts", - "lib/esm/fromBase64.d.ts" - ], - "types": [ - "lib/cjs/types/index.d.ts", - "lib/esm/types/index.d.ts" - ] + "typeutils": ["lib/cjs/typeUtils.d.ts", "lib/esm/typeUtils.d.ts"], + "utils/base64": ["lib/cjs/fromBase64.d.ts", "lib/esm/fromBase64.d.ts"], + "types": ["lib/cjs/types/index.d.ts", "lib/esm/types/index.d.ts"] } }, "types": "./lib/cjs/index.d.ts", "main": "./lib/cjs/index.js", - "files": [ - "lib" - ], + "files": ["lib"], "repository": { "type": "git", "url": "git+https://github.com/aws-powertools/powertools-lambda-typescript.git" @@ -78,13 +67,7 @@ "bugs": { "url": "https://github.com/aws-powertools/powertools-lambda-typescript/issues" }, - "keywords": [ - "aws", - "lambda", - "powertools", - "serverless", - "nodejs" - ], + "keywords": ["aws", "lambda", "powertools", "serverless", "nodejs"], "devDependencies": { "@aws-lambda-powertools/testing-utils": "file:../testing" } diff --git a/packages/commons/src/awsSdkUtils.ts b/packages/commons/src/awsSdkUtils.ts index 451661b007..df922f9e27 100644 --- a/packages/commons/src/awsSdkUtils.ts +++ b/packages/commons/src/awsSdkUtils.ts @@ -1,5 +1,5 @@ -import { PT_VERSION } from './version.js'; import type { MiddlewareArgsLike, SdkClient } from './types/awsSdk.js'; +import { PT_VERSION } from './version.js'; const EXEC_ENV = process.env.AWS_EXECUTION_ENV || 'NA'; const middlewareOptions = { @@ -96,7 +96,7 @@ const addUserAgentMiddleware = (client: unknown, feature: string): void => { ); } else { throw new Error( - `The client provided does not match the expected interface` + 'The client provided does not match the expected interface' ); } } catch (error) { diff --git a/packages/commons/src/config/EnvironmentVariablesService.ts b/packages/commons/src/config/EnvironmentVariablesService.ts index f9b2003a44..726c05b683 100644 --- a/packages/commons/src/config/EnvironmentVariablesService.ts +++ b/packages/commons/src/config/EnvironmentVariablesService.ts @@ -108,11 +108,11 @@ class EnvironmentVariablesService implements ConfigServiceInterface { const xRayTraceData: Record = {}; - xRayTraceEnv.split(';').forEach((field) => { + for (const field of xRayTraceEnv.split(';')) { const [key, value] = field.split('='); xRayTraceData[key] = value; - }); + } return xRayTraceData; } diff --git a/packages/commons/src/fromBase64.ts b/packages/commons/src/fromBase64.ts index 5fd0236c64..44179987fe 100644 --- a/packages/commons/src/fromBase64.ts +++ b/packages/commons/src/fromBase64.ts @@ -22,10 +22,10 @@ const BASE64_REGEX = /^[A-Za-z0-9+/]*={0,2}$/; */ const fromBase64 = (input: string, encoding?: BufferEncoding): Uint8Array => { if ((input.length * 3) % 4 !== 0) { - throw new TypeError(`Incorrect padding on base64 string.`); + throw new TypeError('Incorrect padding on base64 string.'); } if (!BASE64_REGEX.exec(input)) { - throw new TypeError(`Invalid base64 string.`); + throw new TypeError('Invalid base64 string.'); } const buffer = encoding ? Buffer.from(input, encoding) : Buffer.from(input); diff --git a/packages/commons/src/middleware/cleanupMiddlewares.ts b/packages/commons/src/middleware/cleanupMiddlewares.ts index 7c393077e1..577b793904 100644 --- a/packages/commons/src/middleware/cleanupMiddlewares.ts +++ b/packages/commons/src/middleware/cleanupMiddlewares.ts @@ -1,10 +1,10 @@ +import type { CleanupFunction, MiddyLikeRequest } from '../types/middy.js'; import { - TRACER_KEY, - METRICS_KEY, - LOGGER_KEY, IDEMPOTENCY_KEY, + LOGGER_KEY, + METRICS_KEY, + TRACER_KEY, } from './constants.js'; -import type { MiddyLikeRequest, CleanupFunction } from '../types/middy.js'; /** * Typeguard to assert that an object is of Function type. diff --git a/packages/commons/src/typeUtils.ts b/packages/commons/src/typeUtils.ts index 3cd53b81fc..9a4dbd1b34 100644 --- a/packages/commons/src/typeUtils.ts +++ b/packages/commons/src/typeUtils.ts @@ -99,17 +99,21 @@ const isIntegerNumber = (value: unknown): value is number => { const isTruthy = (value: unknown): boolean => { if (isString(value)) { return value !== ''; - } else if (isNumber(value)) { + } + if (isNumber(value)) { return value !== 0; - } else if (typeof value === 'boolean') { + } + if (typeof value === 'boolean') { return value; - } else if (Array.isArray(value)) { + } + if (Array.isArray(value)) { return value.length > 0; - } else if (isRecord(value)) { + } + if (isRecord(value)) { return Object.keys(value).length > 0; - } else { - return false; } + + return false; }; /** @@ -168,19 +172,24 @@ const isNullOrUndefined = (value: unknown): value is null | undefined => { const getType = (value: unknown): string => { if (Array.isArray(value)) { return 'array'; - } else if (isRecord(value)) { + } + if (isRecord(value)) { return 'object'; - } else if (isString(value)) { + } + if (isString(value)) { return 'string'; - } else if (isNumber(value)) { + } + if (isNumber(value)) { return 'number'; - } else if (typeof value === 'boolean') { + } + if (typeof value === 'boolean') { return 'boolean'; - } else if (isNull(value)) { + } + if (isNull(value)) { return 'null'; - } else { - return 'unknown'; } + + return 'unknown'; }; /** diff --git a/packages/commons/tests/tsconfig.json b/packages/commons/tests/tsconfig.json index 5654b3e15f..45ba862a85 100644 --- a/packages/commons/tests/tsconfig.json +++ b/packages/commons/tests/tsconfig.json @@ -1,11 +1,8 @@ { - "extends": "../tsconfig.json", - "compilerOptions": { - "rootDir": "../", - "noEmit": true - }, - "include": [ - "../src/**/*", - "./**/*", - ] -} \ No newline at end of file + "extends": "../tsconfig.json", + "compilerOptions": { + "rootDir": "../", + "noEmit": true + }, + "include": ["../src/**/*", "./**/*"] +} diff --git a/packages/commons/tests/unit/EnvironmentVariablesService.test.ts b/packages/commons/tests/unit/EnvironmentVariablesService.test.ts index 230e04afb0..2c7b7266f3 100644 --- a/packages/commons/tests/unit/EnvironmentVariablesService.test.ts +++ b/packages/commons/tests/unit/EnvironmentVariablesService.test.ts @@ -32,7 +32,7 @@ describe('Class: EnvironmentVariablesService', () => { test('When the variable IS NOT present, it returns an empty string', () => { // Prepare - delete process.env.CUSTOM_VARIABLE; + process.env.CUSTOM_VARIABLE = undefined; const service = new EnvironmentVariablesService(); // Act @@ -84,7 +84,7 @@ describe('Class: EnvironmentVariablesService', () => { test('It returns the value of the Root X-Ray segment ID properly formatted', () => { // Prepare - delete process.env._X_AMZN_TRACE_ID; + process.env._X_AMZN_TRACE_ID = undefined; const service = new EnvironmentVariablesService(); // Act @@ -124,7 +124,7 @@ describe('Class: EnvironmentVariablesService', () => { it('It returns false when no _X_AMZN_TRACE_ID environment variable is present', () => { // Prepare - delete process.env._X_AMZN_TRACE_ID; + process.env._X_AMZN_TRACE_ID = undefined; const service = new EnvironmentVariablesService(); // Act diff --git a/packages/commons/tests/unit/LambdaInterface.test.ts b/packages/commons/tests/unit/LambdaInterface.test.ts index 7d7decc5a0..4afc6e40f9 100644 --- a/packages/commons/tests/unit/LambdaInterface.test.ts +++ b/packages/commons/tests/unit/LambdaInterface.test.ts @@ -3,13 +3,12 @@ * * @group unit/commons/lambdaInterface */ -import { Handler } from 'aws-lambda'; -import { Callback, Context } from 'aws-lambda'; import context from '@aws-lambda-powertools/testing-utils/context'; +import type { Callback, Context, Handler } from 'aws-lambda'; import type { - SyncHandler, AsyncHandler, LambdaInterface, + SyncHandler, } from '../../src/types/index.js'; describe('LambdaInterface with arrow function', () => { @@ -105,10 +104,8 @@ describe('LambdaInterface with decorator', () => { callback, ]); console.log(`Invoked ${String(_propertyKey)}`); - } catch (error) { - throw error; } finally { - console.log(`Finally from decorator`); + console.log('Finally from decorator'); } return result; diff --git a/packages/commons/tests/unit/Utility.test.ts b/packages/commons/tests/unit/Utility.test.ts index 9e9d18194e..f60e7edeea 100644 --- a/packages/commons/tests/unit/Utility.test.ts +++ b/packages/commons/tests/unit/Utility.test.ts @@ -14,10 +14,6 @@ describe('Class: Utility', () => { describe('Method: getDefaultServiceName', () => { test('it should return the default service name', () => { class PowerTool extends Utility { - public constructor() { - super(); - } - public dummyMethod(): string { return this.getDefaultServiceName(); } @@ -56,10 +52,6 @@ describe('Class: Utility', () => { test('when called multiple times on a child class, it returns true the first time, then false afterwards', () => { // Prepare class PowerTool extends Utility { - public constructor() { - super(); - } - public dummyMethod(): boolean { return this.getColdStart(); } @@ -115,10 +107,6 @@ describe('Class: Utility', () => { test('when called multiple times on a child class, it returns true the first time, then false afterwards', () => { // Prepare class PowerTool extends Utility { - public constructor() { - super(); - } - public dummyMethod(): boolean { return this.isColdStart(); } @@ -149,10 +137,6 @@ describe('Class: Utility', () => { describe('Method: isValidServiceName', () => { class PowerTool extends Utility { - public constructor() { - super(); - } - public dummyMethod(name: string): boolean { return this.isValidServiceName(name); } diff --git a/packages/commons/tests/unit/awsSdkUtils.test.ts b/packages/commons/tests/unit/awsSdkUtils.test.ts index 0a2e4c6cd7..da06ea7729 100644 --- a/packages/commons/tests/unit/awsSdkUtils.test.ts +++ b/packages/commons/tests/unit/awsSdkUtils.test.ts @@ -1,9 +1,14 @@ +/** + * Test AWS SDK utilities + * + * @group unit/commons/awsSdkUtils + */ +import { customUserAgentMiddleware } from '../../src/awsSdkUtils.js'; import { addUserAgentMiddleware, isSdkClient, PT_VERSION as version, } from '../../src/index.js'; -import { customUserAgentMiddleware } from '../../src/awsSdkUtils.js'; describe('Helpers: awsSdk', () => { describe('Function: userAgentMiddleware', () => { diff --git a/packages/commons/tests/unit/cleanupMiddlewares.test.ts b/packages/commons/tests/unit/cleanupMiddlewares.test.ts index 15295a0396..8b178f2e9f 100644 --- a/packages/commons/tests/unit/cleanupMiddlewares.test.ts +++ b/packages/commons/tests/unit/cleanupMiddlewares.test.ts @@ -3,14 +3,14 @@ * * @group unit/commons/cleanupMiddlewares */ +import context from '@aws-lambda-powertools/testing-utils/context'; import { - cleanupMiddlewares, - TRACER_KEY, - METRICS_KEY, - LOGGER_KEY, IDEMPOTENCY_KEY, + LOGGER_KEY, + METRICS_KEY, + TRACER_KEY, + cleanupMiddlewares, } from '../../src/index.js'; -import context from '@aws-lambda-powertools/testing-utils/context'; describe('Function: cleanupMiddlewares', () => { it('calls the cleanup function that are present', async () => { diff --git a/packages/commons/tests/unit/fromBase64.test.ts b/packages/commons/tests/unit/fromBase64.test.ts index 23ee84ecd3..6d2a2a965b 100644 --- a/packages/commons/tests/unit/fromBase64.test.ts +++ b/packages/commons/tests/unit/fromBase64.test.ts @@ -34,7 +34,7 @@ describe('Function: fromBase64', () => { // Assess expect(result).toThrow(TypeError); - expect(result).toThrow(`Incorrect padding on base64 string.`); + expect(result).toThrow('Incorrect padding on base64 string.'); }); it('throws a TypeError when the base64 string is invalid', () => { @@ -46,7 +46,7 @@ describe('Function: fromBase64', () => { // Assess expect(result).toThrow(TypeError); - expect(result).toThrow(`Invalid base64 string.`); + expect(result).toThrow('Invalid base64 string.'); }); it('uses the provided encoding to create the Uint8Array', () => { diff --git a/packages/commons/tests/unit/typeUtils.test.ts b/packages/commons/tests/unit/typeUtils.test.ts index 7bb940f343..6b96d61882 100644 --- a/packages/commons/tests/unit/typeUtils.test.ts +++ b/packages/commons/tests/unit/typeUtils.test.ts @@ -4,15 +4,15 @@ * @group unit/commons/typeUtils */ import { - isRecord, - isTruthy, - isNullOrUndefined, - isString, - isNumber, + getType, isIntegerNumber, isNull, - getType, + isNullOrUndefined, + isNumber, + isRecord, isStrictEqual, + isString, + isTruthy, } from '../../src/index.js'; describe('Functions: typeUtils', () => { diff --git a/packages/commons/tsconfig.esm.json b/packages/commons/tsconfig.esm.json index 123291b0cf..82486b64fa 100644 --- a/packages/commons/tsconfig.esm.json +++ b/packages/commons/tsconfig.esm.json @@ -6,7 +6,5 @@ "rootDir": "./src", "tsBuildInfoFile": ".tsbuildinfo/esm.json" }, - "include": [ - "./src/**/*" - ] -} \ No newline at end of file + "include": ["./src/**/*"] +} diff --git a/packages/commons/tsconfig.json b/packages/commons/tsconfig.json index 4836a14962..4923c4f6f4 100644 --- a/packages/commons/tsconfig.json +++ b/packages/commons/tsconfig.json @@ -1,11 +1,9 @@ { - "extends": "../../tsconfig.json", - "compilerOptions": { - "outDir": "./lib/cjs/", - "rootDir": "./src", - "tsBuildInfoFile": ".tsbuildinfo/cjs.json" - }, - "include": [ - "./src/**/*" - ], -} \ No newline at end of file + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "./lib/cjs/", + "rootDir": "./src", + "tsBuildInfoFile": ".tsbuildinfo/cjs.json" + }, + "include": ["./src/**/*"] +} diff --git a/packages/commons/typedoc.json b/packages/commons/typedoc.json index d3799003ef..60dfaa41cd 100644 --- a/packages/commons/typedoc.json +++ b/packages/commons/typedoc.json @@ -1,10 +1,5 @@ { - "extends": [ - "../../typedoc.base.json" - ], - "entryPoints": [ - "./src/index.ts", - "./src/types/index.ts" - ], + "extends": ["../../typedoc.base.json"], + "entryPoints": ["./src/index.ts", "./src/types/index.ts"], "readme": "./README.md" -} \ No newline at end of file +}