Skip to content

Commit

Permalink
update eslint to v9
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig authored and fhanau committed Sep 10, 2024
1 parent 91b7770 commit 57d205c
Show file tree
Hide file tree
Showing 25 changed files with 423 additions and 443 deletions.
8 changes: 8 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@aspect_rules_js//js:defs.bzl", "js_library")
load("@aspect_rules_js//npm:defs.bzl", "npm_link_package")
load("@bazel_skylib//lib:selects.bzl", "selects")
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
Expand Down Expand Up @@ -89,3 +90,10 @@ selects.config_setting_group(
":not_dbg_build",
],
)

# prettier
js_library(
name = "prettierrc",
srcs = [".prettierrc.json"],
visibility = ["//visibility:public"],
)
3 changes: 2 additions & 1 deletion build/wd_ts_bundle.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ def wd_ts_bundle_capnp(
data = srcs + [
eslintrc_json,
tsconfig_json,
"//:node_modules/@typescript-eslint/eslint-plugin",
"//tools:base-eslint",
"//:prettierrc",
],
tags = ["lint"],
target_compatible_with = select({
Expand Down
15 changes: 7 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,23 @@
},
"dependencies": {
"capnp-ts": "^0.7.0",
"prettier": "^3.2.5",
"prettier": "^3.3.3",
"typescript": "5.5.4"
},
"devDependencies": {
"@bazel/bazelisk": "~1.19.0",
"@eslint/js": "^9.9.0",
"@types/debug": "^4.1.10",
"@types/eslint__js": "^8.42.3",
"@types/node": "^20.14.8",
"@types/prettier": "^2.7.1",
"@typescript-eslint/eslint-plugin": "^7.3.1",
"@typescript-eslint/parser": "^7.3.1",
"capnpc-ts": "^0.7.0",
"chrome-remote-interface": "^0.33.2",
"esbuild": "^0.15.18",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint": "^9.9.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-prettier": "^5.1.3",
"expect-type": "^0.18.0"
"eslint-plugin-prettier": "^5.2.1",
"expect-type": "^0.18.0",
"typescript-eslint": "^8.2.0"
},
"pnpm": {
"overrides": {
Expand Down
540 changes: 256 additions & 284 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

41 changes: 0 additions & 41 deletions src/cloudflare/.eslintrc.json

This file was deleted.

2 changes: 1 addition & 1 deletion src/cloudflare/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ load("@workerd//:build/wd_ts_bundle.bzl", "wd_ts_bundle")

wd_ts_bundle(
name = "cloudflare",
eslintrc_json = ".eslintrc.json",
eslintrc_json = "eslint.config.mjs",
import_name = "cloudflare",
internal_modules = glob(
[
Expand Down
4 changes: 4 additions & 0 deletions src/cloudflare/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { baseConfig } from '../../tools/base.eslint.config.mjs';

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
export default [...baseConfig({ tsconfigRootDir: import.meta.dirname })];
6 changes: 3 additions & 3 deletions src/cloudflare/internal/ai-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class Ai {
extraHeaders,
sessionOptions,
...object
}): object => object)(this.options || {});
}): object => object)(this.options);

const body = JSON.stringify({
inputs,
Expand All @@ -90,8 +90,8 @@ export class Ai {
method: 'POST',
body: body,
headers: {
...(this.options?.sessionOptions?.extraHeaders || {}),
...(this.options?.extraHeaders || {}),
...(this.options.sessionOptions?.extraHeaders || {}),
...(this.options.extraHeaders || {}),
'content-type': 'application/json',
'cf-consn-sdk-version': '2.0.0',
'cf-consn-model-id': `${this.options.prefix ? `${this.options.prefix}:` : ''}${model}`,
Expand Down
14 changes: 6 additions & 8 deletions src/cloudflare/internal/d1-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,7 @@ class D1DatabaseWithSessionAPI extends D1Database {
constraintOrToken: D1SessionCommitTokenOrConstraint | null | undefined
): D1DatabaseSession {
constraintOrToken = constraintOrToken?.trim();
if (
constraintOrToken === null ||
constraintOrToken === undefined ||
constraintOrToken === ''
) {
if (constraintOrToken == null || constraintOrToken === '') {
constraintOrToken = D1_SESSION_CONSTRAINT_FIRST_UNCONSTRAINED;
}
return new D1DatabaseSession(this.fetcher, constraintOrToken);
Expand Down Expand Up @@ -181,6 +177,7 @@ class D1DatabaseSession {
switch (this.commitTokenOrConstraint) {
// First to any replica, and then anywhere that satisfies the commit token.
case D1_SESSION_CONSTRAINT_FIRST_UNCONSTRAINED:
return null;
// First to primary, and then anywhere that satisfies the commit token.
case D1_SESSION_CONSTRAINT_FIRST_PRIMARY:
return null;
Expand Down Expand Up @@ -449,7 +446,7 @@ class D1PreparedStatement {

const firstResult = results[0]!;
if (colName !== undefined) {
if (hasResults && firstResult[colName] === undefined) {
if (firstResult[colName] === undefined) {
throw new Error(`D1_COLUMN_NOTFOUND: Column not found (${colName})`, {
cause: new Error('Column not found'),
});
Expand All @@ -460,6 +457,7 @@ class D1PreparedStatement {
}
}

/* eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters */
public async run<T = Record<string, unknown>>(): Promise<D1Response> {
return firstIfArray(
await this.dbSession._sendOrThrow<T>(
Expand Down Expand Up @@ -554,12 +552,12 @@ function mapD1Result<T>(result: D1UpstreamResponse<T>): D1UpstreamResponse<T> {
return result.error
? {
success: false,
meta: result.meta || {},
meta: result.meta,
error: result.error,
}
: {
success: true,
meta: result.meta || {},
meta: result.meta,
...('results' in result ? { results: result.results } : {}),
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/cloudflare/internal/images-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ImageTransformerImpl implements ImageTransformer {
this.consumed = false;
}

public transform(transform: Transform): ImageTransformerImpl {
public transform(transform: Transform): this {
this.transforms.push(transform);
return this;
}
Expand Down
16 changes: 10 additions & 6 deletions src/cloudflare/internal/pipeline-transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async function* readLines(

// @ts-expect-error must have a '[Symbol.asyncIterator]()' method
for await (const chunk of stream) {
const full = partial + chunk;
const full = partial + (chunk as string);
for (const char of full) {
if (char === '\n') {
yield full.substring(start, end);
Expand Down Expand Up @@ -68,13 +68,15 @@ export class PipelineTransformImpl extends entrypoints.WorkerEntrypoint {

// called by the dispatcher which then calls the subclass methods
// @ts-expect-error thinks ping is never used
private async _ping(): Promise<void> {
private _ping(): Promise<void> {
// making sure the function was overriden by an implementing subclass
if (this.transformJson !== PipelineTransformImpl.prototype.transformJson) {
return await Promise.resolve(); // eslint
return Promise.resolve();
} else {
throw new Error(
'the transformJson method must be overridden by the PipelineTransform subclass'
return Promise.reject(
new Error(
'the transformJson method must be overridden by the PipelineTransform subclass'
)
);
}
}
Expand All @@ -92,16 +94,18 @@ export class PipelineTransformImpl extends entrypoints.WorkerEntrypoint {
this.#initalized = true;

switch (this.#batch.format) {
case Format.JSON_STREAM:
case Format.JSON_STREAM: {
const data = await this.#readJsonStream();
const transformed = await this.transformJson(data);
return this.#sendJson(transformed);
}
default:
throw new Error('unsupported batch format');
}
}

async #readJsonStream(): Promise<object[]> {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (this.#batch!.format !== Format.JSON_STREAM) {
throw new Error(`expected JSON_STREAM not ${this.#batch!.format}`);
}
Expand Down
5 changes: 4 additions & 1 deletion src/cloudflare/internal/vectorize-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class VectorizeIndexImpl implements Vectorize {

if (typeof options.returnMetadata === 'boolean') {
// Allow boolean returnMetadata for backward compatibility. true converts to 'all' and false converts to 'none'
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
options.returnMetadata = options.returnMetadata ? 'all' : 'none';
}
}
Expand Down Expand Up @@ -226,7 +227,9 @@ class VectorizeIndexImpl implements Vectorize {
cause: new Error(errResponse.error),
}
);
} catch {}
} catch {
// do nothing
}

if (err) {
throw err;
Expand Down
41 changes: 0 additions & 41 deletions src/node/.eslintrc.json

This file was deleted.

2 changes: 1 addition & 1 deletion src/node/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ load("@workerd//:build/wd_ts_bundle.bzl", "wd_ts_bundle")

wd_ts_bundle(
name = "node",
eslintrc_json = ".eslintrc.json",
eslintrc_json = "eslint.config.mjs",
import_name = "node",
internal_modules = glob([
"internal/*.ts",
Expand Down
3 changes: 3 additions & 0 deletions src/node/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { baseConfig } from '../../tools/base.eslint.config.mjs';

export default [...baseConfig({ tsconfigRootDir: import.meta.dirname })];
9 changes: 6 additions & 3 deletions src/node/internal/internal_zlib_base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ function processCallback(this: ZlibHandleType): void {
assert.strictEqual(have, 0, 'have should not go down');
}

/* eslint-disable-next-line @typescript-eslint/no-unnecessary-condition */
if (self.destroyed) {
this.cb();
return;
Expand Down Expand Up @@ -254,11 +255,12 @@ function processChunkSync(
let offset = self._outOffset;
const chunkSize = self._chunkSize;

let error;
let error: Error | undefined;
self.on('error', function onError(er) {
error = er;
});

/* eslint-disable-next-line @typescript-eslint/no-unnecessary-condition */
while (true) {
ok(handle, 'Handle should have been defined');
handle.writeSync(
Expand Down Expand Up @@ -371,6 +373,7 @@ export class ZlibBase extends Transform {
flushBoundIdx = FLUSH_BOUND_IDX_BROTLI;
}

/* eslint-disable-next-line @typescript-eslint/no-unnecessary-condition */
if (opts) {
if (opts.chunkSize != null) {
chunkSize = opts.chunkSize;
Expand Down Expand Up @@ -430,7 +433,7 @@ export class ZlibBase extends Transform {
this._defaultFlushFlag = flush;
this._finishFlushFlag = finishFlush;
this._defaultFullFlushFlag = fullFlush;
this._info = Boolean(opts?.info);
this._info = Boolean(opts.info);
this._maxOutputLength = maxOutputLength;
}

Expand Down Expand Up @@ -684,7 +687,7 @@ export class Zlib extends ZlibBase {
#paramsAfterFlushCallback(
level: number,
strategy: number,
callback: () => void
callback?: () => void
): void {
ok(this._handle, 'zlib binding closed');
this._handle.params(level, strategy);
Expand Down
3 changes: 3 additions & 0 deletions src/node/internal/streams_transform.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ export class Duplex extends Readable implements Writable {
readonly writableLength: number;
readonly writableObjectMode: boolean;
readonly writableCorked: number;
readonly destroyed: boolean;

allowHalfOpen: boolean;
constructor(opts?: DuplexOptions);
_write(
Expand Down Expand Up @@ -465,6 +467,7 @@ interface TransformOptions extends DuplexOptions {
type TransformCallback = (error?: Error | null, data?: any) => void;

export class Transform extends Duplex {
readonly destroyed: boolean;
constructor(opts?: TransformOptions);
_transform(
chunk: any,
Expand Down
Loading

0 comments on commit 57d205c

Please sign in to comment.