Skip to content

Commit

Permalink
ci: add lint rules for Tests and Typings
Browse files Browse the repository at this point in the history
  • Loading branch information
wellwelwel committed Mar 6, 2024
1 parent a402a61 commit 5d21d68
Show file tree
Hide file tree
Showing 21 changed files with 108 additions and 70 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,9 @@ jobs:

- name: Lint JS snippets in docs
run: npm run lint:docs

- name: Lint Tests
run: npm run lint:tests

- name: Lint Typings
run: npm run lint:typings
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"lint": "npm run lint:docs && npm run lint:code",
"lint:code": "eslint index.js promise.js index.d.ts promise.d.ts \"typings/**/*.ts\" \"lib/**/*.js\" \"test/**/*.{js,ts}\" \"benchmarks/**/*.js\"",
"lint:docs": "eslint Contributing.md README.md",
"lint:typings": "npx prettier --check ./typings",
"lint:tests": "npx prettier --check ./test",
"test": "poku --debug --include=\"test/esm,test/unit,test/integration\"",
"test:bun": "poku --debug --platform=\"bun\" --include=\"test/esm,test/unit,test/integration\"",
"test:tsc-build": "cd \"test/tsc-build\" && npx tsc -p \"tsconfig.json\"",
Expand Down
2 changes: 1 addition & 1 deletion test/esm/integration/test-pool.test.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { assert, test, describe } from 'poku';
import mysql from '../../../index.js';
import {describeOptions} from '../../common.test.cjs';
import { describeOptions } from '../../common.test.cjs';

const poolConfig = {}; // config: { connectionConfig: {} };

Expand Down
8 changes: 7 additions & 1 deletion test/tsc-build/mysql/createPoolCluster/getConnection.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { mysql } from '../../index.test.js';
import { access, uriAccess, sql, sqlPS, values } from '../baseConnection.test.js';
import {
access,
uriAccess,
sql,
sqlPS,
values,
} from '../baseConnection.test.js';

const poolCluster = mysql.createPoolCluster();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { mysql } from '../../../index.test.js';
import { access, uriAccess, sql, sqlPS, values } from '../../baseConnection.test.js';
import {
access,
uriAccess,
sql,
sqlPS,
values,
} from '../../baseConnection.test.js';

const poolCluster = mysql.createPoolCluster();

Expand Down
8 changes: 7 additions & 1 deletion test/tsc-build/mysql/createPoolCluster/of/of.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { mysql } from '../../../index.test.js';
import { access, uriAccess, sql, sqlPS, values } from '../../baseConnection.test.js';
import {
access,
uriAccess,
sql,
sqlPS,
values,
} from '../../baseConnection.test.js';

const poolCluster = mysql.createPoolCluster();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { mysqlp as mysql } from '../../index.test.js';
import { access, uriAccess, sql, sqlPS, values } from '../baseConnection.test.js';
import {
access,
uriAccess,
sql,
sqlPS,
values,
} from '../baseConnection.test.js';

const poolCluster = mysql.createPoolCluster();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { mysqlp as mysql } from '../../../index.test.js';
import { access, uriAccess, sql, sqlPS, values } from '../../baseConnection.test.js';
import {
access,
uriAccess,
sql,
sqlPS,
values,
} from '../../baseConnection.test.js';

const poolCluster = mysql.createPoolCluster();

Expand Down
8 changes: 7 additions & 1 deletion test/tsc-build/promise/createPoolCluster/of/of.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { mysqlp as mysql } from '../../../index.test.js';
import { access, uriAccess, sql, sqlPS, values } from '../../baseConnection.test.js';
import {
access,
uriAccess,
sql,
sqlPS,
values,
} from '../../baseConnection.test.js';

const poolCluster = mysql.createPoolCluster();

Expand Down
8 changes: 7 additions & 1 deletion test/tsc-build/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
{
"include": ["index.test.ts", "helpers.test.ts", "mysql", "promise", "strict-checks"],
"include": [
"index.test.ts",
"helpers.test.ts",
"mysql",
"promise",
"strict-checks"
],
"compilerOptions": {
"target": "ES2016",
"module": "CommonJS",
Expand Down
4 changes: 2 additions & 2 deletions typings/mysql/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ export function format(
sql: string,
values: any[],
stringifyObjects?: boolean,
timeZone?: string
timeZone?: string,
): string;

export function format(
sql: string,
values: any,
stringifyObjects?: boolean,
timeZone?: string
timeZone?: string,
): string;

export function raw(sql: string): {
Expand Down
2 changes: 1 addition & 1 deletion typings/mysql/lib/Auth.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export type AuthPlugin = (pluginMetadata: {
connection: Connection;
command: string;
}) => (
pluginData: Buffer
pluginData: Buffer,
) => Promise<string> | string | Buffer | Promise<Buffer> | null;

type AuthPluginDefinition<T> = (pluginOptions?: T) => AuthPlugin;
Expand Down
6 changes: 3 additions & 3 deletions typings/mysql/lib/Pool.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ declare class Pool extends QueryableBase(ExecutableBase(EventEmitter)) {
getConnection(
callback: (
err: NodeJS.ErrnoException | null,
connection: PoolConnection
) => any
connection: PoolConnection,
) => any,
): void;

releaseConnection(connection: PoolConnection | PromisePoolConnection): void;

end(
callback?: (err: NodeJS.ErrnoException | null, ...args: any[]) => any
callback?: (err: NodeJS.ErrnoException | null, ...args: any[]) => any,
): void;

on(event: string, listener: (...args: any[]) => void): this;
Expand Down
18 changes: 9 additions & 9 deletions typings/mysql/lib/PoolCluster.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { QueryableBase as QueryableBaseClass } from './protocol/sequences/Querya

// Expose class interfaces
declare class QueryableAndExecutableBase extends QueryableBaseClass(
ExecutableBaseClass(EventEmitter)
ExecutableBaseClass(EventEmitter),
) {}

export interface PoolClusterOptions {
Expand Down Expand Up @@ -40,8 +40,8 @@ export interface PoolNamespace extends QueryableAndExecutableBase {
getConnection(
callback: (
err: NodeJS.ErrnoException | null,
connection: PoolConnection
) => any
connection: PoolConnection,
) => any,
): void;
}

Expand All @@ -57,23 +57,23 @@ declare class PoolCluster extends EventEmitter {
getConnection(
callback: (
err: NodeJS.ErrnoException | null,
connection: PoolConnection
) => void
connection: PoolConnection,
) => void,
): void;
getConnection(
group: string,
callback: (
err: NodeJS.ErrnoException | null,
connection: PoolConnection
) => void
connection: PoolConnection,
) => void,
): void;
getConnection(
group: string,
selector: string,
callback: (
err: NodeJS.ErrnoException | null,
connection: PoolConnection
) => void
connection: PoolConnection,
) => void,
): void;

of(pattern: string, selector?: string): PoolNamespace;
Expand Down
2 changes: 1 addition & 1 deletion typings/mysql/lib/protocol/packets/FieldPacket.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ declare interface FieldPacket {
protocol41?: boolean;
table: string;
type?: number;
columnType?: number
columnType?: number;
zerofill?: boolean;
typeName?: string;
encoding?: string;
Expand Down
4 changes: 2 additions & 2 deletions typings/mysql/lib/protocol/packets/ProcedurePacket.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ declare type ProcedureCallPacket<
> = T extends RowDataPacket[]
? [T, ResultSetHeader]
: T extends ResultSetHeader | OkPacket
? ResultSetHeader
: [RowDataPacket[], ResultSetHeader] | ResultSetHeader;
? ResultSetHeader
: [RowDataPacket[], ResultSetHeader] | ResultSetHeader;

export { ProcedureCallPacket };
15 changes: 6 additions & 9 deletions typings/mysql/lib/protocol/sequences/ExecutableBase.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
FieldPacket,
QueryResult,
} from '../packets/index.js';
import { FieldPacket, QueryResult } from '../packets/index.js';
import {
Query,
QueryError,
Expand All @@ -10,34 +7,34 @@ import {
} from './Query.js';

export declare function ExecutableBase<T extends QueryableConstructor>(
Base?: T
Base?: T,
): {
new (...args: any[]): {
execute<T extends QueryResult>(
sql: string,
callback?:
| ((err: QueryError | null, result: T, fields: FieldPacket[]) => any)
| undefined
| undefined,
): Query;
execute<T extends QueryResult>(
sql: string,
values: any,
callback?:
| ((err: QueryError | null, result: T, fields: FieldPacket[]) => any)
| undefined
| undefined,
): Query;
execute<T extends QueryResult>(
options: QueryOptions,
callback?:
| ((err: QueryError | null, result: T, fields?: FieldPacket[]) => any)
| undefined
| undefined,
): Query;
execute<T extends QueryResult>(
options: QueryOptions,
values: any,
callback?:
| ((err: QueryError | null, result: T, fields: FieldPacket[]) => any)
| undefined
| undefined,
): Query;
};
} & T;
12 changes: 8 additions & 4 deletions typings/mysql/lib/protocol/sequences/Prepare.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ export class PrepareStatementInfo {
| RowDataPacket[]
| OkPacket
| OkPacket[]
| ResultSetHeader
| ResultSetHeader,
>(
parameters: any | any[] | { [param: string]: any },
callback?: (err: QueryError | null, result: T, fields: FieldPacket[]) => any
callback?: (
err: QueryError | null,
result: T,
fields: FieldPacket[],
) => any,
): Query;
}

Expand Down Expand Up @@ -53,11 +57,11 @@ declare class Prepare extends Sequence {
on(event: 'error', listener: (err: QueryError) => any): this;
on(
event: 'fields',
listener: (fields: FieldPacket, index: number) => any
listener: (fields: FieldPacket, index: number) => any,
): this;
on(
event: 'result',
listener: (result: RowDataPacket | OkPacket, index: number) => any
listener: (result: RowDataPacket | OkPacket, index: number) => any,
): this;
on(event: 'end', listener: () => any): this;
}
Expand Down
15 changes: 6 additions & 9 deletions typings/mysql/lib/protocol/sequences/QueryableBase.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
FieldPacket,
QueryResult,
} from '../packets/index.js';
import { FieldPacket, QueryResult } from '../packets/index.js';
import {
Query,
QueryError,
Expand All @@ -10,34 +7,34 @@ import {
} from './Query.js';

export declare function QueryableBase<T extends QueryableConstructor>(
Base?: T
Base?: T,
): {
new (...args: any[]): {
query<T extends QueryResult>(
sql: string,
callback?:
| ((err: QueryError | null, result: T, fields: FieldPacket[]) => any)
| undefined
| undefined,
): Query;
query<T extends QueryResult>(
sql: string,
values: any,
callback?:
| ((err: QueryError | null, result: T, fields: FieldPacket[]) => any)
| undefined
| undefined,
): Query;
query<T extends QueryResult>(
options: QueryOptions,
callback?:
| ((err: QueryError | null, result: T, fields?: FieldPacket[]) => any)
| undefined
| undefined,
): Query;
query<T extends QueryResult>(
options: QueryOptions,
values: any,
callback?:
| ((err: QueryError | null, result: T, fields: FieldPacket[]) => any)
| undefined
| undefined,
): Query;
};
} & T;
17 changes: 6 additions & 11 deletions typings/mysql/lib/protocol/sequences/promise/ExecutableBase.d.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
import {
FieldPacket,
QueryResult,
} from '../../packets/index.js';
import { FieldPacket, QueryResult } from '../../packets/index.js';
import { QueryOptions, QueryableConstructor } from '../Query.js';

export declare function ExecutableBase<T extends QueryableConstructor>(
Base?: T
Base?: T,
): {
new (...args: any[]): {
execute<T extends QueryResult>(
sql: string
): Promise<[T, FieldPacket[]]>;
execute<T extends QueryResult>(sql: string): Promise<[T, FieldPacket[]]>;
execute<T extends QueryResult>(
sql: string,
values: any
values: any,
): Promise<[T, FieldPacket[]]>;
execute<T extends QueryResult>(
options: QueryOptions
options: QueryOptions,
): Promise<[T, FieldPacket[]]>;
execute<T extends QueryResult>(
options: QueryOptions,
values: any
values: any,
): Promise<[T, FieldPacket[]]>;
};
} & T;
Loading

0 comments on commit 5d21d68

Please sign in to comment.