Skip to content

Commit

Permalink
ESLint v9 & Prettier v4
Browse files Browse the repository at this point in the history
  • Loading branch information
surol committed Oct 9, 2024
1 parent 76a004e commit e0ad446
Show file tree
Hide file tree
Showing 21 changed files with 45 additions and 82 deletions.
33 changes: 0 additions & 33 deletions .eslintrc.cjs

This file was deleted.

1 change: 0 additions & 1 deletion .prettierrc.cjs

This file was deleted.

3 changes: 3 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import configs from '@run-z/eslint-config';

export default configs;
15 changes: 5 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,17 @@
},
"devDependencies": {
"@jest/globals": "^29.7.0",
"@run-z/eslint-config": "^4.2.0",
"@run-z/prettier-config": "^2.0.0",
"@run-z/eslint-config": "^5.0.0",
"@run-z/prettier-config": "^3.0.0",
"@run-z/project-config": "^0.20.4",
"@swc/core": "^1.7.26",
"@swc/jest": "^0.2.36",
"@types/node": "^20.16.11",
"@typescript-eslint/eslint-plugin": "^7.18.0",
"@typescript-eslint/parser": "^7.18.0",
"eslint": "^8.57.1",
"eslint-plugin-jest": "^28.8.3",
"eslint": "^9.12.0",
"gh-pages": "^6.1.1",
"jest": "^29.7.0",
"jest-junit": "^16.0.0",
"jest-mock": "^29.7.0",
"prettier": "^2.8.8",
"prettier-eslint-cli": "^7.1.0",
"prettier": "^3.3.3",
"rollup": "^4.24.0",
"run-z": "^2.1.0",
"ts-jest": "^29.2.5",
Expand All @@ -87,7 +82,7 @@
"clean": "run-z +z --then clean-z",
"doc": "run-z +z --then typedoc",
"doc:publish": "run-z doc --then gh-pages --dist target/typedoc --dotfiles",
"format": "run-z +z --then prettier-eslint --write --include-dot-files \"src/**/*.*\" \"*.{js,cjs,json,md}\"",
"format": "run-z +z --then prettier --write \"src/**/*.*\" \"*.{js,cjs,json,md}\"",
"lint": "run-z +z --then eslint .",
"test": "run-z +z env:NODE_OPTIONS=\"--experimental-vm-modules --no-warnings\" --then test-z",
"z": "run-z +cmd:build-z,+cmd:typedoc,+cmd:eslint,+cmd:test-z"
Expand Down
3 changes: 3 additions & 0 deletions prettier.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import config from '@run-z/prettier-config';

export default config;
3 changes: 2 additions & 1 deletion src/core/dispatch-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export function dispatchError<TMeans>(
onError: RequestHandler<TMeans & ErrorMeans>,
handler: RequestHandler<TMeans>,
): RequestHandler<TMeans> {
return context => context
return context =>
context
.next(handler)
.catch(error => context.next<ErrorMeans>(onError, requestExtension({ error })));
}
12 changes: 7 additions & 5 deletions src/core/logging/logging.capability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export interface Logging<TInput = unknown, TLogger extends RequestLogger = Reque
*/
class LoggingCapability<TInput, TLogger extends RequestLogger>
extends RequestCapability<TInput, LoggerMeans<TLogger>>
implements Logging<TInput, TLogger> {

implements Logging<TInput, TLogger>
{
readonly for: <TMeans extends TInput>(
handler: RequestHandler<TMeans & LoggerMeans<TLogger>>,
) => RequestHandler<TMeans>;
Expand All @@ -43,7 +43,8 @@ class LoggingCapability<TInput, TLogger extends RequestLogger>
this.for =
<TMeans extends TInput>(
handler: RequestHandler<TMeans & LoggerMeans<TLogger>>,
): RequestHandler<TMeans> => context => {
): RequestHandler<TMeans> =>
context => {
if ((context as Partial<LoggerMeans>).log) {
return context.next(handler);
}
Expand All @@ -54,14 +55,15 @@ class LoggingCapability<TInput, TLogger extends RequestLogger>
this.for =
<TMeans extends TInput>(
handler: RequestHandler<TMeans & LoggerMeans<TLogger>>,
): RequestHandler<TMeans> => context => context.next(handler, requestExtension({ log }));
): RequestHandler<TMeans> =>
context =>
context.next(handler, requestExtension({ log }));
}
}

logBy<TNewLogger extends RequestLogger>(log: TNewLogger): Logging<TInput, TNewLogger> {
return new LoggingCapability(log);
}

}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/core/logging/logging.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { beforeEach, describe, expect, it, jest } from '@jest/globals';
import { consoleLogger, silentLogger } from '@proc7ts/logger';
import { noop } from '@proc7ts/primitives';
import type { Mock } from 'jest-mock';
import type { RequestContext } from '../request-context.js';
import type { RequestHandler } from '../request-handler.js';
import type { RequestProcessor } from '../request-processor.js';
Expand All @@ -11,7 +10,7 @@ import { Logging } from './logging.capability.js';
import type { RequestLogger } from './request-logger.js';

describe('Logging', () => {
let handler: Mock<(context: RequestContext<LoggerMeans>) => void>;
let handler: jest.Mock<(context: RequestContext<LoggerMeans>) => void>;

beforeEach(() => {
handler = jest.fn();
Expand Down
2 changes: 0 additions & 2 deletions src/core/request-capability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import type { RequestHandler } from './request-handler.js';
* @typeParam TExt - A type of extension to request processing means this capability applies.
*/
export abstract class RequestCapability<TInput, TExt = object> {

/**
* Builds request capability by the given `provider`.
*
Expand Down Expand Up @@ -101,7 +100,6 @@ export abstract class RequestCapability<TInput, TExt = object> {
): RequestCapability<TInput, TExt & TNext> {
return RequestCapability.combine<TInput, TExt, TNext>(this, next);
}

}

export namespace RequestCapability {
Expand Down
6 changes: 4 additions & 2 deletions src/core/request-handler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ describe('requestHandler', () => {
const error = new Error('test');
const calls: number[] = [];

const call = async (): Promise<unknown> => await requestHandler([
const call = async (): Promise<unknown> =>
await requestHandler([
() => {
calls.push(1);
},
Expand All @@ -69,7 +70,8 @@ describe('requestHandler', () => {
});
it('stops handlers execution once response written', async () => {
const calls: number[] = [];
const call = async (): Promise<unknown> => await requestHandler([
const call = async (): Promise<unknown> =>
await requestHandler([
() => {
calls.push(1);
},
Expand Down
2 changes: 0 additions & 2 deletions src/http/http-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import type { DueLog, Loggable } from '@proc7ts/logger';
* @see HttpConfig.errorHandler
*/
export class HttpError extends Error implements Loggable {

readonly #statusCode: number;
readonly #statusMessage?: string | undefined;
readonly #details?: string | undefined;
Expand Down Expand Up @@ -76,7 +75,6 @@ export class HttpError extends Error implements Loggable {

return report;
}

}

function httpErrorMessage(
Expand Down
3 changes: 1 addition & 2 deletions src/http/http-listener.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
} from '@jest/globals';
import { consoleLogger } from '@proc7ts/logger';
import { noop } from '@proc7ts/primitives';
import type { Mock } from 'jest-mock';
import { ErrorMeans } from '../core/error.means.js';
import { RequestContext } from '../core/request-context.js';
import { TestHttpServer } from '../testing/test-http-server.js';
Expand All @@ -33,7 +32,7 @@ describe('httpListener', () => {
server.listenBy(noop);
});

let logErrorSpy: Mock<(...args: unknown[]) => void>;
let logErrorSpy: jest.Mock<(...args: unknown[]) => void>;

beforeEach(() => {
logErrorSpy = jest.spyOn(consoleLogger, 'error').mockImplementation(noop) as typeof logErrorSpy;
Expand Down
8 changes: 5 additions & 3 deletions src/http/http-listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ function fullHttpHandler<TExt, TRequest extends IncomingMessage, TResponse exten
): RequestHandler<HttpMeans<TRequest, TResponse> & TExt> {
const defaultHandler = defaultHttpHandler(config);

return dispatchError(httpErrorHandler(config), ({ next }) => next(handler).then(ok => ok || next(defaultHandler)));
return dispatchError(httpErrorHandler(config), ({ next }) =>
next(handler).then(ok => ok || next(defaultHandler)),
);
}

/**
Expand Down Expand Up @@ -226,8 +228,8 @@ function httpErrorHandler<
? renderHttpError
: errorHandler
: defaultHandler
? renderEmptyHttpResponse
: noop;
? renderEmptyHttpResponse
: noop;

if (!logError) {
return onError;
Expand Down
7 changes: 4 additions & 3 deletions src/http/middleware.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
} from '@jest/globals';
import { silentLogger } from '@proc7ts/logger';
import { noop } from '@proc7ts/primitives';
import type { Mock } from 'jest-mock';
import { Logging } from '../core/logging/logging.capability.js';
import { TestHttpServer } from '../testing/test-http-server.js';
import { HttpError } from './http-error.js';
Expand All @@ -31,7 +30,7 @@ describe('middleware', () => {
server.listenBy(noop);
});

let ware: Mock<Middleware>;
let ware: jest.Mock<Middleware>;

beforeEach(() => {
ware = jest.fn((_request, _response, next) => next());
Expand Down Expand Up @@ -64,7 +63,9 @@ describe('middleware', () => {
expect(ware).toHaveBeenCalledTimes(1);
});
it('allows middleware to error', async () => {
ware.mockImplementation((_request, _response, next) => next(new HttpError(503, { statusMessage: 'Custom Error' })));
ware.mockImplementation((_request, _response, next) =>
next(new HttpError(503, { statusMessage: 'Custom Error' })),
);

server.handleBy(
{
Expand Down
3 changes: 2 additions & 1 deletion src/http/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export function middleware<TInput extends HttpMeans>(
function middlewareProvider<TMeans extends TInput>(
handler: RequestHandler<TMeans>,
): RequestHandler<TMeans> {
return async ({ request, response, next }: RequestContext<TMeans>) => await new Promise<void>((resolve, reject) => {
return async ({ request, response, next }: RequestContext<TMeans>) =>
await new Promise<void>((resolve, reject) => {
const mdNext = (error?: unknown): void => {
if (error !== undefined) {
reject(error);
Expand Down
2 changes: 0 additions & 2 deletions src/http/render/rendering.capability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import type { RenderMeans } from './render.means.js';
* @internal
*/
class RenderingCapability extends RequestCapability<HttpMeans, RenderMeans> {

for<TMeans extends HttpMeans>(
handler: RequestHandler<TMeans & RenderMeans>,
): RequestHandler<TMeans> {
Expand Down Expand Up @@ -42,7 +41,6 @@ class RenderingCapability extends RequestCapability<HttpMeans, RenderMeans> {
);
};
}

}

/**
Expand Down
5 changes: 2 additions & 3 deletions src/http/request/form-decoding.capability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ export interface FormDecoding<TInput extends HttpMeans = HttpMeans, TBody = URLS
*/
class FormDecodingCapability<TInput extends HttpMeans, TBody>
extends RequestCapability<TInput, RequestBodyMeans<TBody>>
implements FormDecoding<TInput, TBody> {

implements FormDecoding<TInput, TBody>
{
readonly #transform: RequestValueTransformer<TInput, URLSearchParams, TBody>;

constructor(transform: RequestValueTransformer<TInput, URLSearchParams, TBody>) {
Expand Down Expand Up @@ -89,7 +89,6 @@ class FormDecodingCapability<TInput extends HttpMeans, TBody>
): FormDecoding<TMeans, TTransformed> {
return new FormDecodingCapability<TMeans, TTransformed>(transformer);
}

}

/**
Expand Down
2 changes: 0 additions & 2 deletions src/http/request/http-forwarding.capability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export interface HttpForwarding extends RequestCapability<HttpMeans> {
* @internal
*/
class HttpForwardingCapability extends RequestCapability<HttpMeans> implements HttpForwarding {

readonly #trust: HttpForwardTrust;

constructor(trust: HttpForwardTrust) {
Expand Down Expand Up @@ -60,7 +59,6 @@ class HttpForwardingCapability extends RequestCapability<HttpMeans> implements H
with(trust: HttpForwardTrust): HttpForwarding {
return new HttpForwardingCapability(trust);
}

}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/http/request/json-parsing.capability.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
} from '@jest/globals';
import { consoleLogger } from '@proc7ts/logger';
import { noop } from '@proc7ts/primitives';
import type { Mock } from 'jest-mock';
import { TestHttpServer } from '../../testing/test-http-server.js';
import { HttpError } from '../http-error.js';
import { Rendering } from '../render/rendering.capability.js';
Expand All @@ -26,7 +25,7 @@ describe('JsonParsing', () => {
await server.stop();
});

let logErrorSpy: Mock<(...args: unknown[]) => void>;
let logErrorSpy: jest.Mock<(...args: unknown[]) => void>;

beforeEach(() => {
logErrorSpy = jest.spyOn(consoleLogger, 'error').mockImplementation(noop) as typeof logErrorSpy;
Expand Down
5 changes: 2 additions & 3 deletions src/http/request/json-parsing.capability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ export interface JsonParsing<TInput extends HttpMeans = HttpMeans, TBody = any>
*/
class JsonParsingCapability<TInput extends HttpMeans, TBody>
extends RequestCapability<TInput, RequestBodyMeans<TBody>>
implements JsonParsing<TInput, TBody> {

implements JsonParsing<TInput, TBody>
{
readonly #transform: RequestValueTransformer<TInput, any, TBody>;

constructor(transform: RequestValueTransformer<TInput, any, TBody>) {
Expand Down Expand Up @@ -96,7 +96,6 @@ class JsonParsingCapability<TInput extends HttpMeans, TBody>
): FormDecoding<TMeans, TTransformed> {
return new JsonParsingCapability<TMeans, TTransformed>(transformer);
}

}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/testing/test-http-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { readAll } from '../impl/read-all.js';
* Testing HTTP server and client.
*/
export class TestHttpServer {

/**
* Starts new test HTTP server and binds it ro random port ad localhost.
*
Expand Down Expand Up @@ -117,7 +116,9 @@ export class TestHttpServer {
*/
#start(): Promise<TestHttpServer> {
return new Promise((resolve, reject) => {
const server = (this.#server = createServer((request, response) => this.#listener(request, response)));
const server = (this.#server = createServer((request, response) =>
this.#listener(request, response),
));

server.on('error', reject);
server.on('listening', () => resolve(this));
Expand Down Expand Up @@ -183,7 +184,6 @@ export class TestHttpServer {
stop(): Promise<void> {
return promisify(this.server.close.bind(this.server))();
}

}

export namespace TestHttpServer {
Expand Down

0 comments on commit e0ad446

Please sign in to comment.