Skip to content

Commit c2d0dd1

Browse files
committed
enable eslint on wd-test files
1 parent fd0665d commit c2d0dd1

80 files changed

Lines changed: 368 additions & 249 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

build/lint_test.bzl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ def lint_test(
55
eslintrc_json,
66
tsconfig_json,
77
srcs,
8-
data = []):
8+
data = [],
9+
no_copy_to_bin = []):
910
js_srcs = [src for src in srcs if src.endswith(".ts") or src.endswith(".mts") or src.endswith(".js") or src.endswith(".mjs")]
1011

1112
eslint_bin.eslint_test(
@@ -21,6 +22,7 @@ def lint_test(
2122
"@workerd//tools:base-tsconfig",
2223
"@workerd//tools:base-eslint",
2324
],
25+
no_copy_to_bin = no_copy_to_bin,
2426
tags = ["lint"],
2527
target_compatible_with = select({
2628
"@platforms//os:windows": ["@platforms//:incompatible"],

build/wd_test.bzl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
load("@aspect_rules_ts//ts:defs.bzl", "ts_config", "ts_project")
2+
load("@workerd//:build/lint_test.bzl", "lint_test")
23

34
def wd_test(
45
src,
56
data = [],
67
name = None,
78
args = [],
89
ts_deps = [],
10+
lint = True,
911
python_snapshot_test = False,
1012
generate_default_variant = True,
1113
generate_all_autogates_variant = True,
@@ -63,6 +65,20 @@ def wd_test(
6365
)
6466
data += [js_src.removesuffix(".ts") + ".js" for js_src in ts_srcs]
6567

68+
if lint:
69+
lint_srcs = [s for s in data if (s.endswith(".ts") or s.endswith(".mts") or s.endswith(".js") or s.endswith(".mjs")) and not s.startswith("../") and not s.startswith("//")]
70+
if lint_srcs:
71+
lint_test(
72+
name = name,
73+
eslintrc_json = "@workerd//tools:base.eslint.config.mjs",
74+
tsconfig_json = "@workerd//tools:base.tsconfig.json",
75+
srcs = lint_srcs,
76+
no_copy_to_bin = [
77+
"@workerd//tools:base.eslint.config.mjs",
78+
"@workerd//tools:base.tsconfig.json",
79+
],
80+
)
81+
6682
# Add initial arguments for `workerd test` command.
6783
base_args = [
6884
"$(location //src/workerd/server:workerd_cross)",

src/cloudflare/internal/test/ai/ai-api-test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export const tests = {
5858
}
5959
);
6060
// Test request internal status code is present
61+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
6162
assert.deepEqual;
6263
assert.deepStrictEqual(env.ai.lastRequestInternalStatusCode, 1001);
6364
}
@@ -161,7 +162,7 @@ export const tests = {
161162
async () => {
162163
const arr = [1, 2, 3];
163164
const encoder = new TextEncoder();
164-
const resp = await env.ai.run('readableStreamIputs', {
165+
const _resp = await env.ai.run('readableStreamIputs', {
165166
audio: {
166167
body: new ReadableStream({
167168
start(controller) {
@@ -195,7 +196,7 @@ export const tests = {
195196
controller.close();
196197
},
197198
});
198-
const resp = await env.ai.run('readableStreamIputs', {
199+
const _resp = await env.ai.run('readableStreamIputs', {
199200
audio: {
200201
body: stream,
201202
contentType: 'audio/wav',

src/cloudflare/internal/test/ai/ai-mock.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,6 @@
22
// Licensed under the Apache 2.0 license found in the LICENSE file or at:
33
// https://opensource.org/licenses/Apache-2.0
44

5-
function base64ToBlob(base64, mimeType) {
6-
const binaryString = atob(base64); // Decode Base64
7-
const len = binaryString.length;
8-
const bytes = new Uint8Array(len);
9-
for (let i = 0; i < len; i++) {
10-
bytes[i] = binaryString.charCodeAt(i);
11-
}
12-
return new Blob([bytes], { type: mimeType });
13-
}
14-
155
export default {
166
async fetch(request, env, ctx) {
177
const url = new URL(request.url);
@@ -137,7 +127,7 @@ export default {
137127
try {
138128
// The AI API doesn't URL-encode the body parameter, so parse directly
139129
websocketData = JSON.parse(bodyParam);
140-
} catch (e) {
130+
} catch (_e) {
141131
websocketData = { inputs: {}, options: {} };
142132
}
143133
}

src/cloudflare/internal/test/d1/d1-api-test-common.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ const anything = Symbol('anything');
1111
const deleteAnything = (expected, actual) => {
1212
Object.entries(expected).forEach(([k, v]) => {
1313
if (v === anything) {
14+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
1415
delete actual[k];
16+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
1517
delete expected[k];
1618
} else if (typeof v === 'object' && typeof actual[k] === 'object') {
1719
deleteAnything(expected[k], actual[k]);

src/cloudflare/internal/test/images/images-api-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2024 Cloudflare, Inc.
22
// Licensed under the Apache 2.0 license found in the LICENSE file or at:
33
// https://opensource.org/licenses/Apache-2.0
4-
// @ts-ignore
4+
// @ts-expect-error - no type declarations for node:assert in this context
55
import * as assert from 'node:assert';
66

77
const encoder = new TextEncoder();

src/cloudflare/internal/test/images/images-upstream-mock.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export class ServiceEntrypoint extends WorkerEntrypoint {
180180
/** @type {any} */
181181
const obj = {
182182
image: await imageAsString(form.get('image')),
183-
// @ts-ignore
183+
// @ts-expect-error - form.get() returns FormDataEntryValue which is not assignable to string
184184
transforms: JSON.parse(form.get('transforms') || '{}'),
185185
};
186186
for (const x of [

src/cloudflare/internal/test/pipeline-transform/transform-test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
12
// @ts-nocheck
23
// Copyright (c) 2024 Cloudflare, Inc.
34
// Licensed under the Apache 2.0 license found in the LICENSE file or at:

src/cloudflare/internal/test/vectorize/vectorize-api-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Licensed under the Apache 2.0 license found in the LICENSE file or at:
33
// https://opensource.org/licenses/Apache-2.0
44

5-
// @ts-ignore
5+
// @ts-expect-error - no type declarations for node:assert in this context
66
import * as assert from 'node:assert';
77
import { KnownModel, DistanceMetric } from 'cloudflare:vectorize';
88

src/cloudflare/internal/test/vectorize/vectorize-mock.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ export default {
196196
}
197197
} catch (err) {
198198
return Response.json(
199-
// @ts-ignore
199+
// @ts-expect-error - err is typed as unknown but has message and stack
200200
{ error: err.message, stack: err.stack },
201201
{ status: 500 }
202202
);

0 commit comments

Comments
 (0)