style: applied linter rules for all files

This commit is contained in:
atassis 2022-07-09 17:40:49 +08:00
parent 91d9207ba6
commit 9935b87d45
No known key found for this signature in database
GPG Key ID: 263A448CB2BE27A4
10 changed files with 35 additions and 34 deletions

View File

@ -1,6 +1,5 @@
import { createListenerDecorator } from '../../utils';
import { Scenes } from 'telegraf';
export const SceneEnter = createListenerDecorator<Scenes.BaseScene<never>>(
'enter',
);
export const SceneEnter =
createListenerDecorator<Scenes.BaseScene<never>>('enter');

View File

@ -1,6 +1,5 @@
import { createListenerDecorator } from '../../utils';
import { Scenes } from 'telegraf';
export const SceneLeave = createListenerDecorator<Scenes.BaseScene<never>>(
'leave',
);
export const SceneLeave =
createListenerDecorator<Scenes.BaseScene<never>>('leave');

View File

@ -4,7 +4,8 @@ import { TgArgumentsHost } from './tg-arguments-host.interface';
export class TelegrafArgumentsHost
extends ExecutionContextHost
implements TgArgumentsHost {
implements TgArgumentsHost
{
static create(context: ArgumentsHost): TelegrafArgumentsHost {
const type = context.getType();
const tgContext = new TelegrafArgumentsHost(context.getArgs());

View File

@ -6,7 +6,8 @@ export type TelegrafContextType = 'telegraf' | ContextType;
export class TelegrafExecutionContext
extends ExecutionContextHost
implements TgArgumentsHost {
implements TgArgumentsHost
{
static create(context: ExecutionContext): TelegrafExecutionContext {
const type = context.getType();
const tgContext = new TelegrafExecutionContext(

View File

@ -11,7 +11,9 @@ export interface TelegrafModuleOptions {
}
export interface TelegrafOptionsFactory {
createTelegrafOptions(): Promise<TelegrafModuleOptions> | TelegrafModuleOptions;
createTelegrafOptions():
| Promise<TelegrafModuleOptions>
| TelegrafModuleOptions;
}
export interface TelegrafModuleAsyncOptions

View File

@ -162,7 +162,7 @@ export class ListenersExplorerService
{},
);
const steps = Object.values(group).map((stepsMetadata) => {
wizard.steps = Object.values(group).map((stepsMetadata) => {
const composer = new Composer();
stepsMetadata.forEach((stepMethod) => {
this.registerIfListener(
@ -175,8 +175,6 @@ export class ListenersExplorerService
});
return composer.middleware();
});
wizard.steps = steps;
}
private registerIfListener(
@ -187,7 +185,8 @@ export class ListenersExplorerService
defaultMetadata?: ListenerMetadata[],
): void {
const methodRef = prototype[methodName];
const metadata = this.metadataAccessor.getListenerMetadata(methodRef) || defaultMetadata;
const metadata =
this.metadataAccessor.getListenerMetadata(methodRef) || defaultMetadata;
if (!metadata || metadata.length < 1) {
return undefined;
}
@ -222,7 +221,7 @@ export class ListenersExplorerService
methodName: string,
) {
const paramsFactory = this.telegrafParamsFactory;
const resolverCallback = this.externalContextCreator.create<
return this.externalContextCreator.create<
Record<number, ParamMetadata>,
TelegrafContextType
>(
@ -236,6 +235,5 @@ export class ListenersExplorerService
undefined,
'telegraf',
);
return resolverCallback;
}
}

View File

@ -1,4 +1,4 @@
import { Composer, Middleware, Telegraf } from 'telegraf';
import { Composer, Middleware } from 'telegraf';
export type Filter<T extends any[], F> = T extends []
? []
@ -14,5 +14,5 @@ export type OnlyFunctionPropertyNames<T> = {
export type ComposerMethodArgs<
T extends Composer<never>,
U extends OnlyFunctionPropertyNames<T> = OnlyFunctionPropertyNames<T>
U extends OnlyFunctionPropertyNames<T> = OnlyFunctionPropertyNames<T>,
> = Filter<Parameters<T[U]>, Middleware<never>>;

View File

@ -19,8 +19,9 @@ export function createListenerDecorator<
args,
} as ListenerMetadata,
];
const previousValue = Reflect.getMetadata(LISTENERS_METADATA, descriptor.value) || [];
const previousValue =
Reflect.getMetadata(LISTENERS_METADATA, descriptor.value) || [];
const value = [...previousValue, ...metadata];
Reflect.defineMetadata(LISTENERS_METADATA, value, descriptor.value);
return descriptor;

View File

@ -5,8 +5,10 @@ import { PARAM_ARGS_METADATA } from '../telegraf.constants';
export type ParamData = object | string | number;
export const createTelegrafParamDecorator = (paramtype: TelegrafParamtype) => {
return (data?: ParamData): ParameterDecorator => (target, key, index) => {
export const createTelegrafParamDecorator =
(paramtype: TelegrafParamtype) =>
(data?: ParamData): ParameterDecorator =>
(target, key, index) => {
const args =
Reflect.getMetadata(PARAM_ARGS_METADATA, target.constructor, key) || {};
Reflect.defineMetadata(
@ -16,16 +18,16 @@ export const createTelegrafParamDecorator = (paramtype: TelegrafParamtype) => {
key,
);
};
};
export const createTelegrafPipesParamDecorator = (
paramtype: TelegrafParamtype,
) => (
data?: any,
...pipes: (Type<PipeTransform> | PipeTransform)[]
): ParameterDecorator => (target, key, index) => {
addPipesMetadata(paramtype, data, pipes, target, key, index);
};
export const createTelegrafPipesParamDecorator =
(paramtype: TelegrafParamtype) =>
(
data?: any,
...pipes: (Type<PipeTransform> | PipeTransform)[]
): ParameterDecorator =>
(target, key, index) => {
addPipesMetadata(paramtype, data, pipes, target, key, index);
};
export const addPipesMetadata = (
paramtype: TelegrafParamtype,

6
package-lock.json generated
View File

@ -5062,8 +5062,7 @@
"version": "5.3.2",
"resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.2.tgz",
"integrity": "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==",
"dev": true,
"requires": {}
"dev": true
},
"acorn-walk": {
"version": "8.2.0",
@ -5620,8 +5619,7 @@
"version": "8.5.0",
"resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-8.5.0.tgz",
"integrity": "sha512-obmWKLUNCnhtQRKc+tmnYuQl0pFU1ibYJQ5BGhTVB08bHe9wC8qUeG7c08dj9XX+AuPj1YSGSQIHl1pnDHZR0Q==",
"dev": true,
"requires": {}
"dev": true
},
"eslint-plugin-prettier": {
"version": "4.2.1",