Skip to content

Commit

Permalink
Replace tslint with typescript-eslint (#1030)
Browse files Browse the repository at this point in the history
* Add basic eslint 9 flat config

* Add @eslint/js and typescript-eslint

* Fix some errors, mostly type imports and git add .

* Fix some lint errors

* Fix lint issues

* This works

* Run prettier

* Remove unused @ts-expect-error

* Add comment to eslint.config.mjs

* Add stylistic rules and turn off majority

* Enable no-inferrable-types & prefer-for-of rules

* Format code

* Enable consistent-type-assertions rule

* Enable no-confusing-non-null-assertion rule

* Fix few lint issues & turn off erroring rules
  • Loading branch information
diksipav authored May 29, 2024
1 parent 5030017 commit 6db71ef
Show file tree
Hide file tree
Showing 87 changed files with 571 additions and 714 deletions.
19 changes: 0 additions & 19 deletions .eslintrc.cjs

This file was deleted.

38 changes: 38 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import eslint from "@eslint/js";
import tseslint from "typescript-eslint";

export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
...tseslint.configs.stylistic,
{
files: ["packages/*/src/**/*.ts"],
languageOptions: {
parser: tseslint.parser,
// parserOptions: {
// project: true,
// },
},
rules: {
"@typescript-eslint/no-unnecessary-type-constraint": "warn",
// Svelte doesn't correctly compile if imports of the generated /modules
// aren't imported as 'import type' in other parts of the generated
// querybuilder, so set this option to ensure we always do that
"@typescript-eslint/consistent-type-imports": "error",
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-empty-function": "warn",
"@typescript-eslint/ban-ts-comment": "warn",
"no-empty-function": "off",
"@typescript-eslint/class-literal-property-style": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{ argsIgnorePattern: "^_", varsIgnorePattern: "^_" },
],
// some stylistic rules results with errors, turn them off for now
"@typescript-eslint/consistent-indexed-object-style": "off",
"@typescript-eslint/consistent-type-definitions": "off",
"@typescript-eslint/no-empty-interface": "off",
},
}
);
6 changes: 6 additions & 0 deletions integration-tests/lts/deno/deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 6 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,15 @@
],
"packageManager": "[email protected]",
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.60.1",
"@typescript-eslint/parser": "^5.60.1",
"eslint": "^8.43.0",
"eslint-config-prettier": "^8.8.0",
"@eslint/js": "^9.2.0",
"eslint": "^9.2.0",
"prettier": "^2.8.8",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0",
"tslint-plugin-prettier": "^2.3.0",
"typescript": "^5.4.5"
"typescript": "^5.4.5",
"typescript-eslint": "^7.8.0"
},
"scripts": {
"lint": "tslint 'packages/*/src/**/*.ts'",
"eslint": "eslint 'packages/*/src/**/*.ts'",
"lint": "eslint --quiet 'packages/*/src/**/*.ts'",
"lint:fix": "eslint 'packages/*/src/**/*.ts' --fix",
"format:check": "prettier --check 'packages/*/src/**/*.(mts|ts)' 'packages/*/test/**/*.ts'",
"format": "prettier --write 'packages/*/src/**/*.(mts|ts)' 'packages/*/test/**/*.ts'",
"generate": "yarn workspace @edgedb/generate generate"
Expand Down
2 changes: 1 addition & 1 deletion packages/auth-nextjs/src/pages/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class NextPagesClientAuth extends NextAuthHelpers {
}

async function apiRequest(url: string, _data: any) {
let data: { [key: string]: any };
let data: Record<string, any>;
if (_data instanceof FormData) {
data = {};
for (const [key, val] of _data.entries()) {
Expand Down
6 changes: 1 addition & 5 deletions packages/auth-nextjs/src/pages/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ export default function createNextPagesServerAuth(
const sessionCache = new WeakMap<any, NextAuthSession>();

export class NextPagesAuth extends NextAuth {
getSession(req: {
cookies: Partial<{
[key: string]: string;
}>;
}) {
getSession(req: { cookies: Partial<Record<string, string>> }) {
const session =
sessionCache.get(req) ??
new NextAuthSession(
Expand Down
2 changes: 1 addition & 1 deletion packages/auth-remix/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export class RemixServerAuth extends RemixClientAuth {
params,
}: {
request: Request;
params: { [key: string]: string | undefined };
params: Record<string, string | undefined>;
}) => {
const path = params["*"];
if (!path) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import { redirect } from "next/navigation";
import { auth } from "@/edgedb";
import type { TokenData } from "@edgedb/auth-core";

export const { GET, POST } = auth.createAuthRouteHandlers({
async onBuiltinUICallback({ error, tokenData, provider, isSignUp }) {
async onBuiltinUICallback({
error,
tokenData,
isSignUp,
}: {
error?: Error;
tokenData?: TokenData;
isSignUp?: boolean;
}) {
if (error) {
console.error("sign in failed", error);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import type { NextApiRequest, NextApiResponse } from "next";

import { auth } from "@/edgedb";

type Data = {
interface Data {
name: string;
identity: any;
};
}

export default async function handler(
req: NextApiRequest,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import type { NextApiRequest, NextApiResponse } from "next";

type Data = {
interface Data {
name: string;
};
}

export default function handler(
req: NextApiRequest,
Expand Down
9 changes: 4 additions & 5 deletions packages/create/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ export async function copyTemplateFiles(
vars[filepath].push({ varname, value });
}
return vars;
}, {} as { [filepath: string]: { varname: string; value: string }[] }) ??
{},
}, {} as Record<string, { varname: string; value: string }[]>) ?? {},
});
}

Expand All @@ -53,11 +52,11 @@ async function _walkDir(
_dest: string,
untaggedSource: string,
opts: Omit<CopyTemplateFilesOpts, "injectVars"> & {
injectVars: { [filepath: string]: { varname: string; value: string }[] };
injectVars: Record<string, { varname: string; value: string }[]>;
}
) {
const files: { [filename: string]: { entry: Dirent; tags: string[] }[] } = {};
const dirs: { [dirname: string]: { entry: Dirent; tags: string[] }[] } = {};
const files: Record<string, { entry: Dirent; tags: string[] }[]> = {};
const dirs: Record<string, { entry: Dirent; tags: string[] }[]> = {};
for (const entry of await fs.readdir(source, { withFileTypes: true })) {
const parts = entry.name.split(".");
const name = [
Expand Down
4 changes: 2 additions & 2 deletions packages/driver/src/adapter.crypto.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { CryptoUtils } from "./utils";
let cryptoUtils: CryptoUtils;

if (typeof crypto === "undefined") {
// tslint:disable-next-line:no-var-requires
// eslint-disable-next-line @typescript-eslint/no-var-requires
const nodeCrypto = require("crypto");

cryptoUtils = {
Expand Down Expand Up @@ -32,7 +32,7 @@ if (typeof crypto === "undefined") {
},
};
} else {
// tslint:disable-next-line:no-var-requires
// eslint-disable-next-line @typescript-eslint/no-var-requires
cryptoUtils = require("./browserCrypto").default;
}

Expand Down
8 changes: 5 additions & 3 deletions packages/driver/src/adapter.deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export function homeDir(): string {
export async function input(message = "", _params?: { silent?: boolean }) {
const buf = new Uint8Array(1024);
await Deno.stdout.write(new TextEncoder().encode(message));
const n = <number>await Deno.stdin.read(buf);
const n = (await Deno.stdin.read(buf)) as number;
return new TextDecoder().decode(buf.subarray(0, n)).trim();
}

Expand All @@ -162,6 +162,7 @@ export namespace net {

export const isIP = _isIP;

// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
export declare interface Socket {
on(eventName: "error", listener: (e: any) => void): this;
on(eventName: "connect", listener: () => void): this;
Expand Down Expand Up @@ -234,6 +235,7 @@ export namespace net {
}
}

// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
export class Socket extends BaseSocket<Deno.Conn> {
constructor(pconn: Promise<Deno.Conn>) {
super();
Expand Down Expand Up @@ -272,8 +274,8 @@ export namespace tls {
}

export function checkServerIdentity(
hostname: string,
cert: Object
_hostname: string,
_cert: object
): Error | undefined {
return undefined;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/driver/src/adapter.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export function input(
): Promise<string> {
let silent = false;

const output = !!params?.silent
const output = params?.silent
? new Writable({
write(
chunk: any,
Expand All @@ -102,7 +102,7 @@ export function input(
output,
});

return new Promise((resolve, rej) => {
return new Promise((resolve) => {
rl.question(message, (val) => {
rl.close();
resolve(val);
Expand Down
5 changes: 1 addition & 4 deletions packages/driver/src/adapter.shared.node.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
export function getEnv(
envName: string,
required: boolean = false
): string | undefined {
export function getEnv(envName: string, _required = false): string | undefined {
return process.env[envName];
}
25 changes: 15 additions & 10 deletions packages/driver/src/baseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,32 @@

import type { Duration } from "./datatypes/datetime";
import { CodecsRegistry } from "./codecs/registry";
import {
import type {
ConnectArgumentsParser,
ConnectConfig,
NormalizedConnectConfig,
ResolvedConnectConfigReadonly,
} from "./conUtils";
import * as errors from "./errors";
import { Cardinality, Executor, OutputFormat, QueryArgs } from "./ifaces";
import {
Options,
type Executor,
type QueryArgs,
Cardinality,
OutputFormat,
} from "./ifaces";
import type {
RetryOptions,
Session,
SimpleRetryOptions,
SimpleTransactionOptions,
TransactionOptions,
} from "./options";
import { Options } from "./options";
import Event from "./primitives/event";
import { LifoQueue } from "./primitives/queues";
import { BaseRawConnection } from "./baseConn";
import { ConnectWithTimeout, retryingConnect } from "./retry";
import type { BaseRawConnection } from "./baseConn";
import type { ConnectWithTimeout } from "./retry";
import { retryingConnect } from "./retry";
import { util } from "./reflection/util";
import { Transaction } from "./transaction";
import { sleep } from "./utils";
Expand Down Expand Up @@ -121,7 +127,7 @@ export class ClientConnectionHolder {
action: (transaction: Transaction) => Promise<T>
): Promise<T> {
let result: T | void;
for (let iteration = 0; true; ++iteration) {
for (let iteration = 0; ; ++iteration) {
const transaction = await Transaction._startTransaction(this);

let commitFailed = false;
Expand Down Expand Up @@ -173,7 +179,7 @@ export class ClientConnectionHolder {
expectedCardinality: Cardinality
): Promise<any> {
let result: any;
for (let iteration = 0; true; ++iteration) {
for (let iteration = 0; ; ++iteration) {
const conn = await this._getConnection();
try {
result = await conn.fetch(
Expand Down Expand Up @@ -438,7 +444,6 @@ export abstract class BaseClientPool {
);

const warningTimeoutId = setTimeout(() => {
// tslint:disable-next-line: no-console
console.warn(
"Client.close() is taking over 60 seconds to complete. " +
"Check if you have any unreleased connections left."
Expand Down Expand Up @@ -534,7 +539,7 @@ export class Client implements Executor {
return new Client(this.pool, this.options.withSession(session));
}

withModuleAliases(aliases: { [name: string]: string }) {
withModuleAliases(aliases: Record<string, string>) {
return new Client(
this.pool,
this.options.withSession(this.options.session.withModuleAliases(aliases))
Expand All @@ -546,7 +551,7 @@ export class Client implements Executor {
return new Client(this.pool, this.options.withSession(newConfig));
}

withGlobals(globals: { [name: string]: any }): Client {
withGlobals(globals: Record<string, any>): Client {
return new Client(
this.pool,
this.options.withSession(this.options.session.withGlobals(globals))
Expand Down
Loading

0 comments on commit 6db71ef

Please sign in to comment.