Skip to content

Commit

Permalink
chore: adopt ESLint v9
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Nov 13, 2024
1 parent d034e2f commit ee84183
Show file tree
Hide file tree
Showing 75 changed files with 1,579 additions and 1,828 deletions.
7 changes: 0 additions & 7 deletions packages/benchmark/.eslintrc

This file was deleted.

26 changes: 0 additions & 26 deletions packages/driver/.eslintrc

This file was deleted.

1 change: 1 addition & 0 deletions packages/driver/eslint.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = [...require('@slonik/eslint-config')];
4 changes: 2 additions & 2 deletions packages/driver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
},
"description": "A Node.js PostgreSQL client with strict types, detailed logging and assertions.",
"devDependencies": {
"@slonik/eslint-config": "workspace:^",
"@types/node": "^18.15.3",
"ava": "^6.1.3",
"cspell": "^8.6.0",
"eslint": "^8.57.0",
"eslint-config-canonical": "^42.8.1",
"eslint": "^9.14.0",
"nyc": "^15.1.0",
"ts-node": "^10.9.1",
"typescript": "^5.4.5"
Expand Down
26 changes: 12 additions & 14 deletions packages/driver/src/factories/createDriverFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ type StreamDataEvent<T> = { data: T; fields: readonly Field[] };

// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export interface DriverStream<T> extends Readable {
[Symbol.asyncIterator]: () => AsyncIterableIterator<StreamDataEvent<T>>;
// eslint-disable-next-line @typescript-eslint/method-signature-style
on(event: 'data', listener: (chunk: StreamDataEvent<T>) => void): this;

// eslint-disable-next-line @typescript-eslint/method-signature-style
on(event: string | symbol, listener: (...args: any[]) => void): this;

[Symbol.asyncIterator]: () => AsyncIterableIterator<StreamDataEvent<T>>;
}

type BasicConnection = {
Expand All @@ -33,16 +33,16 @@ export type DriverTypeParser<T = unknown> = {
};

export type DriverConfiguration = {
readonly connectionTimeout: number | 'DISABLE_TIMEOUT';
readonly connectionTimeout: 'DISABLE_TIMEOUT' | number;
readonly connectionUri: string;
readonly gracefulTerminationTimeout?: number;
readonly idleInTransactionSessionTimeout: number | 'DISABLE_TIMEOUT';
readonly idleTimeout?: number | 'DISABLE_TIMEOUT';
readonly idleInTransactionSessionTimeout: 'DISABLE_TIMEOUT' | number;
readonly idleTimeout?: 'DISABLE_TIMEOUT' | number;
readonly maximumPoolSize?: number;
readonly minimumPoolSize?: number;
readonly resetConnection?: (connection: BasicConnection) => Promise<void>;
readonly ssl?: TlsConnectionOptions;
readonly statementTimeout: number | 'DISABLE_TIMEOUT';
readonly statementTimeout: 'DISABLE_TIMEOUT' | number;
readonly typeParsers: readonly DriverTypeParser[];
};

Expand Down Expand Up @@ -111,7 +111,7 @@ export type DriverCommand = 'COPY' | 'DELETE' | 'INSERT' | 'SELECT' | 'UPDATE';
export type DriverQueryResult = {
readonly command: DriverCommand;
readonly fields: DriverField[];
readonly rowCount: number | null;
readonly rowCount: null | number;
readonly rows: Array<Record<string, unknown>>;
};

Expand All @@ -121,8 +121,8 @@ export type DriverStreamResult = {
};

type DriverSetup = ({
driverEventEmitter,
driverConfiguration,
driverEventEmitter,
}: {
driverConfiguration: DriverConfiguration;
driverEventEmitter: DriverEventEmitter;
Expand Down Expand Up @@ -189,17 +189,17 @@ export const createDriverFactory = (setup: DriverSetup): DriverFactory => {

clientEventEmitter.on('error', onError);

const { query, stream, connect, end } = await createPoolClient({
const { connect, end, query, stream } = await createPoolClient({
clientEventEmitter,
});

let isAcquired = false;
let isDestroyed = false;
let idleTimeout: NodeJS.Timeout | null = null;

let activeQueryPromise: Promise<DriverQueryResult> | null = null;
let destroyPromise: Promise<void> | null = null;
let releasePromise: Promise<void> | null = null;
let activeQueryPromise: null | Promise<DriverQueryResult> = null;
let destroyPromise: null | Promise<void> = null;
let releasePromise: null | Promise<void> = null;

const id = generateUid();

Expand Down Expand Up @@ -311,7 +311,6 @@ export const createDriverFactory = (setup: DriverSetup): DriverFactory => {
}, driverConfiguration.idleTimeout).unref();
}

// eslint-disable-next-line require-atomic-updates
isAcquired = false;

releasePromise = null;
Expand Down Expand Up @@ -397,7 +396,6 @@ export const createDriverFactory = (setup: DriverSetup): DriverFactory => {

return result;
} finally {
// eslint-disable-next-line require-atomic-updates
activeQueryPromise = null;
}
},
Expand Down
26 changes: 0 additions & 26 deletions packages/errors/.eslintrc

This file was deleted.

1 change: 1 addition & 0 deletions packages/errors/eslint.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = [...require('@slonik/eslint-config')];
4 changes: 2 additions & 2 deletions packages/errors/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
},
"description": "A Node.js PostgreSQL client with strict types, detailed logging and assertions.",
"devDependencies": {
"@slonik/eslint-config": "workspace:^",
"@types/node": "^18.15.3",
"ava": "^6.1.3",
"cspell": "^8.6.0",
"eslint": "^8.57.0",
"eslint-config-canonical": "^42.8.1",
"eslint": "^9.14.0",
"nyc": "^15.1.0",
"ts-node": "^10.9.1",
"typescript": "^5.4.5",
Expand Down
24 changes: 12 additions & 12 deletions packages/errors/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import {
import { type ZodIssue } from 'zod';

export class SlonikError extends Error {
public readonly message: string;

public override readonly cause?: Error;

public readonly message: string;

public constructor(message: string, options?: { cause?: Error }) {
super(message);

Expand Down Expand Up @@ -115,13 +115,13 @@ export class DataIntegrityError extends SlonikError {
}

export class SchemaValidationError extends SlonikError {
public sql: string;

public values: readonly PrimitiveValueExpression[];
public issues: ZodIssue[];

public row: QueryResultRow;

public issues: ZodIssue[];
public sql: string;

public values: readonly PrimitiveValueExpression[];

public constructor(query: Query, row: QueryResultRow, issues: ZodIssue[]) {
super('Query returned rows that do not conform with the schema.');
Expand All @@ -133,20 +133,20 @@ export class SchemaValidationError extends SlonikError {
}
}

type IntegrityConstraintViolationErrorCause = Error & {
type IntegrityConstraintViolationErrorCause = {
column?: string;
constraint?: string;
table?: string;
};
} & Error;

export class IntegrityConstraintViolationError extends SlonikError {
public constraint: string | null;
public cause?: Error;

public column: string | null;
public column: null | string;

public table: string | null;
public constraint: null | string;

public cause?: Error;
public table: null | string;

public constructor(
message: string,
Expand Down
24 changes: 24 additions & 0 deletions packages/eslint-config/index.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = [
...require('eslint-config-canonical/configurations/auto'),
{
files: ['**/*.cjs', '**/*.js', '**/*.ts'],
...require('eslint-config-canonical/configurations/node').recommended
},
{
files: ['**/eslint.config.cjs'],
rules: {
'n/global-require': 0,
}
},
{
files: ['**/*.test.ts'],
rules: {
'id-length': 0,
'@typescript-eslint/no-unused-expressions': 0,
'@typescript-eslint/no-explicit-any': 0,
},
},
{
ignores: ['**/dist/', '**/.*/'],
},
];
9 changes: 9 additions & 0 deletions packages/eslint-config/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"dependencies": {
"eslint-config-canonical": "^44.3.28"
},
"main": "./index.cjs",
"name": "@slonik/eslint-config",
"private": true,
"version": "0.0.0"
}
26 changes: 0 additions & 26 deletions packages/pg-driver/.eslintrc

This file was deleted.

1 change: 1 addition & 0 deletions packages/pg-driver/eslint.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = [...require('@slonik/eslint-config')];
4 changes: 2 additions & 2 deletions packages/pg-driver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
},
"description": "A Node.js PostgreSQL client with strict types, detailed logging and assertions.",
"devDependencies": {
"@slonik/eslint-config": "workspace:^",
"@types/node": "^18.15.3",
"@types/pg": "^8.11.6",
"ava": "^6.1.3",
"cspell": "^8.6.0",
"eslint": "^8.57.0",
"eslint-config-canonical": "^42.8.1",
"eslint": "^9.14.0",
"nyc": "^15.1.0",
"ts-node": "^10.9.1",
"typescript": "^5.4.5"
Expand Down
6 changes: 2 additions & 4 deletions packages/pg-driver/src/factories/createPgDriverFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ import { type PrimitiveValueExpression } from '@slonik/sql-tag';
import { type Field, type Query } from '@slonik/types';
import { parseDsn } from '@slonik/utilities';
import { Transform } from 'node:stream';
// eslint-disable-next-line no-restricted-imports
import {
Client,
type ClientConfig as NativePostgresClientConfiguration,
type DatabaseError,
type ClientConfig as NativePostgresClientConfiguration,
} from 'pg';
import QueryStream from 'pg-query-stream';
import { getTypeParser as getNativeTypeParser } from 'pg-types';
Expand Down Expand Up @@ -187,7 +186,7 @@ const isErrorWithCode = (error: Error): error is DatabaseError => {
// TODO evaluate if we can remove query from the error object.
// I suspect we should not be even using InputSyntaxError as one of the error types.
// @see https://github.com/gajus/slonik/issues/557
const wrapError = (error: Error, query: Query | null) => {
const wrapError = (error: Error, query: null | Query) => {
if (
error.message.toLowerCase().includes('connection terminated unexpectedly')
) {
Expand Down Expand Up @@ -355,7 +354,6 @@ export const createPgDriverFactory = (): DriverFactory => {
return;
}

// eslint-disable-next-line @babel/no-invalid-this
this.push({
fields,
row: datum,
Expand Down
1 change: 1 addition & 0 deletions packages/slonik-dataloaders/eslint.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = [...require('@slonik/eslint-config')];
4 changes: 2 additions & 2 deletions packages/slonik-dataloaders/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
},
"description": "Utilities for creating DataLoaders using Slonik.",
"devDependencies": {
"@slonik/eslint-config": "workspace:^",
"@slonik/types": "^46.1.0",
"eslint": "^8.57.0",
"eslint-config-canonical": "^42.8.1",
"eslint": "^9.14.0",
"slonik": "^46.1.0",
"typescript": "^5.4.5",
"vitest": "^1.6.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ export const createConnectionLoader = <T extends ZodTypeAny>(

return {
load: async (args: {
after?: string | null;
before?: string | null;
first?: number | null;
after?: null | string;
before?: null | string;
first?: null | number;
info?: LoadParameters['info'];
last?: number | null;
last?: null | number;
orderBy?: LoadParameters['orderBy'];
where?: LoadParameters['where'];
}) => {
Expand Down
Loading

0 comments on commit ee84183

Please sign in to comment.