Skip to content

Commit

Permalink
update eslint to v9
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Aug 22, 2024
1 parent 3114d6d commit f398f25
Show file tree
Hide file tree
Showing 24 changed files with 411 additions and 432 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 @@ -90,7 +90,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
7 changes: 4 additions & 3 deletions src/cloudflare/internal/d1-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,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 @@ -286,6 +286,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.database._sendOrThrow<T>(
Expand Down Expand Up @@ -380,12 +381,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
4 changes: 3 additions & 1 deletion src/cloudflare/internal/vectorize-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,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 })];
10 changes: 7 additions & 3 deletions src/node/internal/internal_zlib_base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ function processCallback(this: zlibUtil.ZlibStream): 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 @@ -231,11 +232,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) {
// TODO(soon): This was `writeSync` before, but it's not anymore.
handle?.write(
Expand Down Expand Up @@ -348,6 +350,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 @@ -407,7 +410,8 @@ export class ZlibBase extends Transform {
this._defaultFlushFlag = flush;
this._finishFlushFlag = finishFlush;
this._defaultFullFlushFlag = fullFlush;
this._info = opts && opts.info;
/* eslint-disable-next-line @typescript-eslint/no-unnecessary-condition */
this._info = opts?.info;
this._maxOutputLength = maxOutputLength;
}

Expand Down Expand Up @@ -668,7 +672,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
14 changes: 7 additions & 7 deletions src/node/internal/util.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// https://opensource.org/licenses/Apache-2.0

/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/ban-types */

export abstract class MIMEType {
public constructor(input: string);
Expand Down Expand Up @@ -74,11 +73,12 @@ export type TypedArray =
export function isArrayBufferView(value: unknown): value is ArrayBufferView;
export function isArgumentsObject(value: unknown): value is IArguments;
export function isArrayBuffer(value: unknown): value is ArrayBuffer;
/* eslint-disable-next-line @typescript-eslint/no-unsafe-function-type */
export function isAsyncFunction(value: unknown): value is Function;
export function isBigInt64Array(value: unknown): value is BigInt64Array;
export function isBigIntObject(value: unknown): value is BigInt;
export function isBigIntObject(value: unknown): value is bigint;
export function isBigUint64Array(value: unknown): value is BigUint64Array;
export function isBooleanObject(value: unknown): value is Boolean;
export function isBooleanObject(value: unknown): value is boolean;
export function isDataView(value: unknown): value is DataView;
export function isDate(value: unknown): value is Date;
export function isExternal(value: unknown): boolean;
Expand All @@ -95,7 +95,7 @@ export function isMapIterator(
): value is IterableIterator<unknown>;
export function isModuleNamespaceObject(value: unknown): boolean;
export function isNativeError(value: unknown): value is Error;
export function isNumberObject(value: unknown): value is Number;
export function isNumberObject(value: unknown): value is number;
export function isPromise(value: unknown): value is Promise<unknown>;
export function isProxy(value: unknown): boolean;
export function isRegExp(value: unknown): value is RegExp;
Expand All @@ -104,8 +104,8 @@ export function isSetIterator(
value: unknown
): value is IterableIterator<unknown>;
export function isSharedArrayBuffer(value: unknown): value is SharedArrayBuffer;
export function isStringObject(value: unknown): value is String;
export function isSymbolObject(value: unknown): value is Symbol;
export function isStringObject(value: unknown): value is string;
export function isSymbolObject(value: unknown): value is symbol;
export function isTypedArray(value: unknown): value is TypedArray;
export function isUint8Array(value: unknown): value is Uint8Array;
export function isUint8ClampedArray(value: unknown): value is Uint8ClampedArray;
Expand All @@ -118,6 +118,6 @@ export function isAnyArrayBuffer(
): value is ArrayBuffer | SharedArrayBuffer;
export function isBoxedPrimitive(
value: unknown
): value is Number | String | Boolean | BigInt | Symbol;
): value is number | string | boolean | bigint | symbol;

export function getBuiltinModule(id: string): any;
6 changes: 0 additions & 6 deletions src/pyodide/.eslintrc.json

This file was deleted.

2 changes: 1 addition & 1 deletion src/pyodide/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ expand_template(

data = wd_ts_bundle_capnp(
name = "pyodide.capnp",
eslintrc_json = ".eslintrc.json",
eslintrc_json = "eslint.config.mjs",
import_name = "pyodide",
internal_data_modules = ["generated/python_stdlib.zip"] + glob([
"internal/*.py",
Expand Down
12 changes: 12 additions & 0 deletions tools/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
load("@aspect_rules_js//js:defs.bzl", "js_library")

js_library(
name = "base-eslint",
srcs = ["base.eslint.config.mjs"],
visibility = ["//visibility:public"],
deps = [
"//:node_modules/@eslint/js",
"//:node_modules/eslint-plugin-prettier",
"//:node_modules/typescript-eslint",
],
)
Loading

0 comments on commit f398f25

Please sign in to comment.