Skip to content

Commit f5f753c

Browse files
authored
chore: adding and fixing lint in contract test utils (#1191)
<!-- CURSOR_SUMMARY --> > [!NOTE] > **Low Risk** > Low risk: primarily adds ESLint/Prettier tooling and does a mechanical rename of internal/protected `BaseTestHook` members, with minimal behavioral change beyond using the renamed fields/methods. > > **Overview** > Adds a linting setup for `contract-test-utils` (new `.eslintrc.cjs`, `tsconfig.eslint.json`, `lint`/`lint:fix` scripts, and ESLint/Prettier devDependencies). > > Refactors `BaseTestHook` and its client/server `TestHook` implementations to satisfy lint/style rules by renaming underscore-prefixed protected members/methods (e.g., `_safePost` → `safePost`, `_beforeEvaluationImpl` → `beforeEvaluationImpl`, `_errors`/`_data` → `hookErrors`/`hookData`) and updating call sites. > > Adds `tsconfig.ref.json` for `contract-test-utils` and wires it into the root `tsconfig.json` project references. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 455e638. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> <!-- devin-review-badge-begin --> --- <a href="https://app.devin.ai/review/launchdarkly/js-core/pull/1191" target="_blank"> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-open-in-devin-review-dark.svg?v=1"> <img src="https://static.devin.ai/assets/gh-open-in-devin-review-light.svg?v=1" alt="Open with Devin"> </picture> </a> <!-- devin-review-badge-end -->
1 parent f3d48c4 commit f5f753c

8 files changed

Lines changed: 65 additions & 31 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
rules: {
3+
'import/extensions': ['error', 'always', { ts: 'never' }],
4+
},
5+
};

packages/tooling/contract-test-utils/package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
"build": "tsc && tsc -p tsconfig.client.json && tsc -p tsconfig.server.json",
3737
"build:client": "tsc -p tsconfig.client.json",
3838
"build:server": "tsc -p tsconfig.server.json",
39+
"lint": "eslint . --ext .ts",
40+
"lint:fix": "yarn run lint --fix",
3941
"clean": "rimraf dist"
4042
},
4143
"peerDependencies": {
@@ -54,6 +56,16 @@
5456
"@launchdarkly/js-client-sdk-common": "workspace:^",
5557
"@launchdarkly/js-server-sdk-common": "workspace:^",
5658
"@types/node": "^18.11.9",
59+
"@typescript-eslint/eslint-plugin": "^6.20.0",
60+
"@typescript-eslint/parser": "^6.20.0",
61+
"eslint": "^8.45.0",
62+
"eslint-config-airbnb-base": "^15.0.0",
63+
"eslint-config-airbnb-typescript": "^17.1.0",
64+
"eslint-config-prettier": "^8.8.0",
65+
"eslint-plugin-import": "^2.27.5",
66+
"eslint-plugin-jest": "^27.6.3",
67+
"eslint-plugin-prettier": "^5.0.0",
68+
"prettier": "^3.0.0",
5769
"typescript": "^4.9.0"
5870
}
5971
}

packages/tooling/contract-test-utils/src/client-side/TestHook.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import {
66
LDEvaluationDetail,
77
TrackSeriesContext,
88
} from '@launchdarkly/js-client-sdk-common';
9+
910
import { BaseTestHook } from '../shared/BaseTestHook.js';
1011

1112
export default class TestHook extends BaseTestHook implements Hook {
12-
protected async _safePost(body: unknown): Promise<void> {
13+
protected async safePost(body: unknown): Promise<void> {
1314
try {
14-
await fetch(this._endpoint, {
15+
await fetch(this.endpoint, {
1516
method: 'POST',
1617
body: JSON.stringify(body),
1718
});
@@ -29,7 +30,7 @@ export default class TestHook extends BaseTestHook implements Hook {
2930
hookContext: EvaluationSeriesContext,
3031
data: EvaluationSeriesData,
3132
): EvaluationSeriesData {
32-
return this._beforeEvaluationImpl(
33+
return this.beforeEvaluationImpl(
3334
hookContext as unknown as Record<string, unknown>,
3435
data,
3536
) as EvaluationSeriesData;
@@ -40,18 +41,18 @@ export default class TestHook extends BaseTestHook implements Hook {
4041
data: EvaluationSeriesData,
4142
detail: LDEvaluationDetail,
4243
): EvaluationSeriesData {
43-
return this._afterEvaluationImpl(
44+
return this.afterEvaluationImpl(
4445
hookContext as unknown as Record<string, unknown>,
4546
data,
4647
detail,
4748
) as EvaluationSeriesData;
4849
}
4950

5051
afterTrack(hookContext: TrackSeriesContext): void {
51-
if (this._errors?.afterTrack) {
52-
throw new Error(this._errors.afterTrack);
52+
if (this.hookErrors?.afterTrack) {
53+
throw new Error(this.hookErrors.afterTrack);
5354
}
54-
this._safePost({
55+
this.safePost({
5556
trackSeriesContext: hookContext,
5657
stage: 'afterTrack',
5758
});

packages/tooling/contract-test-utils/src/server-side/TestHook.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { integrations, LDEvaluationDetail } from '@launchdarkly/js-server-sdk-common';
2+
23
import { BaseTestHook } from '../shared/BaseTestHook.js';
34

45
export default class TestHook extends BaseTestHook implements integrations.Hook {
5-
protected async _safePost(body: unknown): Promise<void> {
6+
protected async safePost(body: unknown): Promise<void> {
67
try {
7-
await fetch(this._endpoint, {
8+
await fetch(this.endpoint, {
89
method: 'POST',
910
headers: { 'Content-Type': 'application/json' },
1011
body: JSON.stringify(body),
@@ -23,7 +24,7 @@ export default class TestHook extends BaseTestHook implements integrations.Hook
2324
hookContext: integrations.EvaluationSeriesContext,
2425
data: integrations.EvaluationSeriesData,
2526
): integrations.EvaluationSeriesData {
26-
return this._beforeEvaluationImpl(
27+
return this.beforeEvaluationImpl(
2728
hookContext as unknown as Record<string, unknown>,
2829
data,
2930
) as integrations.EvaluationSeriesData;
@@ -34,7 +35,7 @@ export default class TestHook extends BaseTestHook implements integrations.Hook
3435
data: integrations.EvaluationSeriesData,
3536
detail: LDEvaluationDetail,
3637
): integrations.EvaluationSeriesData {
37-
return this._afterEvaluationImpl(
38+
return this.afterEvaluationImpl(
3839
hookContext as unknown as Record<string, unknown>,
3940
data,
4041
detail,
Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,53 @@
11
import { HookData, HookErrors } from '../types/CommandParams.js';
22

33
export abstract class BaseTestHook {
4-
protected readonly _name: string;
5-
protected readonly _endpoint: string;
6-
protected readonly _data?: HookData;
7-
protected readonly _errors?: HookErrors;
4+
protected readonly hookName: string;
5+
protected readonly endpoint: string;
6+
protected readonly hookData?: HookData;
7+
protected readonly hookErrors?: HookErrors;
88

99
constructor(name: string, endpoint: string, data?: HookData, errors?: HookErrors) {
10-
this._name = name;
11-
this._endpoint = endpoint;
12-
this._data = data;
13-
this._errors = errors;
10+
this.hookName = name;
11+
this.endpoint = endpoint;
12+
this.hookData = data;
13+
this.hookErrors = errors;
1414
}
1515

16-
protected abstract _safePost(body: unknown): Promise<void>;
16+
protected abstract safePost(body: unknown): Promise<void>;
1717

1818
getMetadata() {
19-
return { name: this._name };
19+
return { name: this.hookName };
2020
}
2121

22-
protected _beforeEvaluationImpl(
22+
protected beforeEvaluationImpl(
2323
hookContext: Record<string, unknown>,
2424
data: Record<string, unknown>,
2525
): Record<string, unknown> {
26-
if (this._errors?.beforeEvaluation) {
27-
throw new Error(this._errors.beforeEvaluation);
26+
if (this.hookErrors?.beforeEvaluation) {
27+
throw new Error(this.hookErrors.beforeEvaluation);
2828
}
29-
this._safePost({
29+
this.safePost({
3030
evaluationSeriesContext: hookContext,
3131
evaluationSeriesData: data,
3232
stage: 'beforeEvaluation',
3333
});
34-
return { ...data, ...(this._data?.beforeEvaluation ?? {}) };
34+
return { ...data, ...(this.hookData?.beforeEvaluation ?? {}) };
3535
}
3636

37-
protected _afterEvaluationImpl(
37+
protected afterEvaluationImpl(
3838
hookContext: Record<string, unknown>,
3939
data: Record<string, unknown>,
4040
detail: unknown,
4141
): Record<string, unknown> {
42-
if (this._errors?.afterEvaluation) {
43-
throw new Error(this._errors.afterEvaluation);
42+
if (this.hookErrors?.afterEvaluation) {
43+
throw new Error(this.hookErrors.afterEvaluation);
4444
}
45-
this._safePost({
45+
this.safePost({
4646
evaluationSeriesContext: hookContext,
4747
evaluationSeriesData: data,
4848
stage: 'afterEvaluation',
4949
evaluationDetail: detail,
5050
});
51-
return { ...data, ...(this._data?.afterEvaluation ?? {}) };
51+
return { ...data, ...(this.hookData?.afterEvaluation ?? {}) };
5252
}
5353
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"include": ["src/**/*.ts"],
4+
"exclude": ["node_modules"]
5+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"include": ["src/**/*", "package.json"],
4+
"compilerOptions": {
5+
"composite": true
6+
}
7+
}

tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252
{
5353
"path": "./packages/tooling/jest/tsconfig.ref.json"
5454
},
55+
{
56+
"path": "./packages/tooling/contract-test-utils/tsconfig.ref.json"
57+
},
5558
{
5659
"path": "./packages/sdk/browser/tsconfig.ref.json"
5760
},

0 commit comments

Comments
 (0)