Skip to content

Commit 428842e

Browse files
authored
Add more JS linting (#215)
* Enable and fix eslint/await-thenable lint * Enable and fix eslint/no-deprecated lint * Enable and fix no-console lint
1 parent fb4200e commit 428842e

File tree

12 files changed

+64
-41
lines changed

12 files changed

+64
-41
lines changed

modal-js/eslint.config.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,22 @@ export default defineConfig([
4040
// We added this lint because `tsx` gets confused when you export types
4141
// without using the `type` keyword.
4242
"@typescript-eslint/consistent-type-exports": "error",
43-
"object-shorthand": "warn",
43+
"object-shorthand": "error",
44+
"@typescript-eslint/await-thenable": "error",
45+
"@typescript-eslint/no-deprecated": "error",
46+
"no-console": "error",
47+
},
48+
},
49+
{
50+
files: ["test/legacy/**/*.{ts,mts,cts}"],
51+
rules: {
52+
"@typescript-eslint/no-deprecated": "off",
53+
},
54+
},
55+
{
56+
files: ["examples/**/*.{ts,mts,cts}"],
57+
rules: {
58+
"no-console": "off",
4459
},
4560
},
4661
]);

modal-js/src/app.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ export class App {
117117
/**
118118
* @deprecated Use {@link AppService#fromName client.apps.fromName()} instead.
119119
*/
120+
// eslint-disable-next-line @typescript-eslint/no-deprecated
120121
static async lookup(name: string, options: LookupOptions = {}): Promise<App> {
121122
return getDefaultClient().apps.fromName(name, options);
122123
}

modal-js/src/client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ export type ClientOptions = {
469469
/**
470470
* @deprecated Use {@link ModalClient `new ModalClient()`} instead.
471471
*/
472+
// eslint-disable-next-line @typescript-eslint/no-deprecated
472473
export function initializeClient(options: ClientOptions) {
473474
defaultClientOptions = {
474475
tokenId: options.tokenId,

modal-js/src/cloud_bucket_mount.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export class CloudBucketMount {
3939
!url.hostname.endsWith("r2.cloudflarestorage.com") &&
4040
!url.hostname.endsWith("storage.googleapis.com")
4141
) {
42+
// eslint-disable-next-line no-console
4243
console.warn(
4344
"CloudBucketMount received unrecognized bucket endpoint URL. " +
4445
"Assuming AWS S3 configuration as fallback.",

modal-js/src/logger.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-console */
12
export type LogLevel = "debug" | "info" | "warn" | "error";
23

34
const LOG_LEVELS: Record<LogLevel, number> = {

modal-js/test/function.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ test("FunctionCall", async () => {
1818
});
1919

2020
test("FunctionCallJsMap", async () => {
21-
const function_ = await Function_.lookup(
21+
const function_ = await tc.functions.fromName(
2222
"libmodal-test-support",
2323
"identity_with_repr",
2424
);
@@ -28,7 +28,7 @@ test("FunctionCallJsMap", async () => {
2828
});
2929

3030
test("FunctionCallDateTimeRoundtrip", async () => {
31-
const function_ = await Function_.lookup(
31+
const function_ = await tc.functions.fromName(
3232
"libmodal-test-support",
3333
"identity_with_repr",
3434
);

modal-js/test/image.test.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,14 @@ test("ImageFromAwsEcr", async () => {
5959
});
6060
expect(app.appId).toBeTruthy();
6161

62-
const image = await app.imageFromAwsEcr(
63-
"459781239556.dkr.ecr.us-east-1.amazonaws.com/ecr-private-registry-test-7522615:python",
64-
await tc.secrets.fromName("libmodal-aws-ecr-test", {
65-
requiredKeys: ["AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY"],
66-
}),
67-
);
62+
const image = await tc.images
63+
.fromAwsEcr(
64+
"459781239556.dkr.ecr.us-east-1.amazonaws.com/ecr-private-registry-test-7522615:python",
65+
await tc.secrets.fromName("libmodal-aws-ecr-test", {
66+
requiredKeys: ["AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY"],
67+
}),
68+
)
69+
.build(app);
6870
expect(image.imageId).toBeTruthy();
6971
expect(image.imageId).toMatch(/^im-/);
7072
});
@@ -75,12 +77,14 @@ test("ImageFromGcpArtifactRegistry", { timeout: 30_000 }, async () => {
7577
});
7678
expect(app.appId).toBeTruthy();
7779

78-
const image = await app.imageFromGcpArtifactRegistry(
79-
"us-east1-docker.pkg.dev/modal-prod-367916/private-repo-test/my-image",
80-
await tc.secrets.fromName("libmodal-gcp-artifact-registry-test", {
81-
requiredKeys: ["SERVICE_ACCOUNT_JSON"],
82-
}),
83-
);
80+
const image = await tc.images
81+
.fromGcpArtifactRegistry(
82+
"us-east1-docker.pkg.dev/modal-prod-367916/private-repo-test/my-image",
83+
await tc.secrets.fromName("libmodal-gcp-artifact-registry-test", {
84+
requiredKeys: ["SERVICE_ACCOUNT_JSON"],
85+
}),
86+
)
87+
.build(app);
8488
expect(image.imageId).toBeTruthy();
8589
expect(image.imageId).toMatch(/^im-/);
8690
});
@@ -107,7 +111,7 @@ test("CreateOneSandboxTopLevelImageAPISecret", async () => {
107111
});
108112
expect(app.appId).toBeTruthy();
109113

110-
const image = await tc.images.fromRegistry(
114+
const image = tc.images.fromRegistry(
111115
"us-east1-docker.pkg.dev/modal-prod-367916/private-repo-test/my-image",
112116
await tc.secrets.fromName("libmodal-gcp-artifact-registry-test", {
113117
requiredKeys: ["REGISTRY_USERNAME", "REGISTRY_PASSWORD"],
@@ -128,7 +132,7 @@ test("ImageFromAwsEcrTopLevel", async () => {
128132
});
129133
expect(app.appId).toBeTruthy();
130134

131-
const image = await tc.images.fromAwsEcr(
135+
const image = tc.images.fromAwsEcr(
132136
"459781239556.dkr.ecr.us-east-1.amazonaws.com/ecr-private-registry-test-7522615:python",
133137
await tc.secrets.fromName("libmodal-aws-ecr-test", {
134138
requiredKeys: ["AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY"],
@@ -149,7 +153,7 @@ test("ImageFromGcpEcrTopLevel", async () => {
149153
});
150154
expect(app.appId).toBeTruthy();
151155

152-
const image = await tc.images.fromGcpArtifactRegistry(
156+
const image = tc.images.fromGcpArtifactRegistry(
153157
"us-east1-docker.pkg.dev/modal-prod-367916/private-repo-test/my-image",
154158
await tc.secrets.fromName("libmodal-gcp-artifact-registry-test", {
155159
requiredKeys: ["SERVICE_ACCOUNT_JSON"],

modal-js/test/legacy/image.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ test("CreateOneSandboxTopLevelImageAPISecret", async () => {
8989
const app = await App.lookup("libmodal-test", { createIfMissing: true });
9090
expect(app.appId).toBeTruthy();
9191

92-
const image = await Image.fromRegistry(
92+
const image = Image.fromRegistry(
9393
"us-east1-docker.pkg.dev/modal-prod-367916/private-repo-test/my-image",
9494
await Secret.fromName("libmodal-gcp-artifact-registry-test", {
9595
requiredKeys: ["REGISTRY_USERNAME", "REGISTRY_PASSWORD"],
@@ -108,7 +108,7 @@ test("ImageFromAwsEcrTopLevel", async () => {
108108
const app = await App.lookup("libmodal-test", { createIfMissing: true });
109109
expect(app.appId).toBeTruthy();
110110

111-
const image = await Image.fromAwsEcr(
111+
const image = Image.fromAwsEcr(
112112
"459781239556.dkr.ecr.us-east-1.amazonaws.com/ecr-private-registry-test-7522615:python",
113113
await Secret.fromName("libmodal-aws-ecr-test", {
114114
requiredKeys: ["AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY"],
@@ -127,7 +127,7 @@ test("ImageFromGcpEcrTopLevel", async () => {
127127
const app = await App.lookup("libmodal-test", { createIfMissing: true });
128128
expect(app.appId).toBeTruthy();
129129

130-
const image = await Image.fromGcpArtifactRegistry(
130+
const image = Image.fromGcpArtifactRegistry(
131131
"us-east1-docker.pkg.dev/modal-prod-367916/private-repo-test/my-image",
132132
await Secret.fromName("libmodal-gcp-artifact-registry-test", {
133133
requiredKeys: ["SERVICE_ACCOUNT_JSON"],

modal-js/test/legacy/sandbox.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ test("SandboxWithVolume", async () => {
176176

177177
test("SandboxWithReadOnlyVolume", async () => {
178178
const app = await App.lookup("libmodal-test", { createIfMissing: true });
179-
const image = await Image.fromRegistry("alpine:3.21");
179+
const image = Image.fromRegistry("alpine:3.21");
180180

181181
const volume = await Volume.fromName("libmodal-test-sandbox-volume", {
182182
createIfMissing: true,

modal-js/test/legacy/secret.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ test("SecretFromObject", async () => {
3333
expect(secret).toBeDefined();
3434

3535
const app = await App.lookup("libmodal-test", { createIfMissing: true });
36-
const image = await Image.fromRegistry("alpine:3.21");
36+
const image = Image.fromRegistry("alpine:3.21");
3737

3838
const sandbox = await app.createSandbox(image, {
3939
command: ["printenv", "key"],

0 commit comments

Comments
 (0)