Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: eslint format #128

Merged
merged 2 commits into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
lib
coverage
25 changes: 25 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"extends": [
"@artus/eslint-config-artus/typescript",
"plugin:import/recommended",
"plugin:import/typescript"
],
"parserOptions": {
"project": "./tsconfig.json"
},
"rules": {
"@typescript-eslint/ban-types": "off",
"no-unused-vars": "off",
Beace marked this conversation as resolved.
Show resolved Hide resolved
"@typescript-eslint/no-unused-vars": ["error", { "varsIgnorePattern": "^_", "argsIgnorePattern": "^_" }]
},
"overrides": [
{
"files": [
"test/**/*"
],
"rules": {
"@typescript-eslint/no-var-requires": "off"
}
}
]
}
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
"scripts": {
"build": "tsc -p ./tsconfig.build.json",
"test": "jest --detectOpenHandles",
"ci": "npm run test"
"ci": "npm run lint && npm run test",
"lint:fix": "eslint . --ext .ts --fix",
"lint": "eslint . --ext .ts"
},
"repository": {
"type": "git",
Expand All @@ -42,6 +44,7 @@
},
"homepage": "https://github.com/artusjs/core#readme",
"devDependencies": {
"@artus/eslint-config-artus": "0.0.1",
"@artus/tsconfig": "0.0.1",
"@types/jest": "^27.4.1",
"@types/js-yaml": "^4.0.5",
Expand All @@ -50,6 +53,8 @@
"axios": "^0.26.1",
"babel-jest": "^27.5.1",
"egg-ci": "^1.19.0",
"eslint": "^8.19.0",
"eslint-plugin-import": "^2.26.0",
"jest": "^27.5.1",
"koa": "^2.13.4",
"reflect-metadata": "^0.1.13",
Expand Down
6 changes: 2 additions & 4 deletions src/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class ArtusApplication implements Application {
protected container: Container;
protected lifecycleManager: LifecycleManager;
protected loaderFactory: LoaderFactory;
protected defaultClazzLoaded: boolean = false;
protected defaultClazzLoaded = false;

constructor(opts?: ApplicationInitOptions) {
this.container = new Container(opts?.containerName ?? ArtusInjectEnum.DefaultContainerName);
Expand Down Expand Up @@ -97,7 +97,7 @@ export class ArtusApplication implements Application {
this.lifecycleManager.registerHook(hookName, hookFn);
}

async close(exit: boolean = false) {
async close(exit = false) {
try {
await this.lifecycleManager.emitHook('beforeClose');
} catch (e) {
Expand All @@ -116,5 +116,3 @@ export class ArtusApplication implements Application {
return this.exceptionHandler.create(code);
}
}

export { Application };
2 changes: 1 addition & 1 deletion src/configuration/decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ export function DefineConfigHandle(handleName?: string): PropertyDecorator {
}
Reflect.defineMetadata(`${HOOK_CONFIG_HANDLE}${handleName}`, propertyKey, target.constructor);
};
};
}
2 changes: 1 addition & 1 deletion src/configuration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default class ConfigurationHandler {
static getEnvFromFilename(filename: string): string {
let [_, env, extname] = filename.split('.');
if (!extname) {
env = ARTUS_DEFAULT_CONFIG_ENV.DEFAULT;
env = ARTUS_DEFAULT_CONFIG_ENV.DEFAULT;
}
return env;
}
Expand Down
4 changes: 2 additions & 2 deletions src/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export enum ARTUS_DEFAULT_CONFIG_ENV {
DEV = 'development',
PROD = 'production',
DEFAULT = 'default',
};
}

export const HOOK_NAME_META_PREFIX = 'hookName:';
export const CONSTRUCTOR_PARAMS = 'constructor:params';
Expand All @@ -40,7 +40,7 @@ export const DEFAULT_EXCLUDES = [
'*.d.ts',
'jest.config.*',
'meta.*',
'LICENSE'
'LICENSE',
];

export const FRAMEWORK_PATTERN = 'framework.*';
Expand Down
6 changes: 3 additions & 3 deletions src/decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function LifecycleHookUnit(): ClassDecorator {
// Ready to remove?
Reflect.defineMetadata(HOOK_FILE_LOADER, { loader: 'lifecycle-hook-unit' }, target);
};
};
}

export function LifecycleHook(hookName?: string): PropertyDecorator {
return (target: any, propertyKey: string | symbol) => {
Expand All @@ -21,7 +21,7 @@ export function LifecycleHook(hookName?: string): PropertyDecorator {
}
Reflect.defineMetadata(`${HOOK_NAME_META_PREFIX}${propertyKey}`, hookName ?? propertyKey, target.constructor);
};
};
}

const WithConstructorParams = (tag: string): ParameterDecorator => {
return (target: any, _propertyKey: string | symbol, parameterIndex: number) => {
Expand All @@ -33,7 +33,7 @@ const WithConstructorParams = (tag: string): ParameterDecorator => {
Reflect.defineMetadata(CONSTRUCTOR_PARAMS, paramsMd, target); // for constructor
}
};
}
};

export function WithApplication(): ParameterDecorator {
return WithConstructorParams(CONSTRUCTOR_PARAMS_APP);
Expand Down
12 changes: 6 additions & 6 deletions src/exception/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ export const ErrorCodeUtils = {
return exceptionItem.desc;
}
return exceptionItem.desc[currentLocale];
}
},
};

export class ArtusStdError extends Error {
name: string = 'ArtusStdError';
name = 'ArtusStdError';
private _code: string;
private _codeMap: Map<string, ExceptionItem>;

constructor (code: string, codeMap: Map<string, ExceptionItem>) {
super(`[${code}] This is Artus standard error, Please check on https://github.com/artusjs/error-code`);
this._code = code;
this._codeMap = codeMap
super(`[${code}] This is Artus standard error, Please check on https://github.com/artusjs/error-code`);
this._code = code;
this._codeMap = codeMap;
}

get code(): string {
return this._code;
return this._code;
}

get desc(): string {
Expand Down
2 changes: 1 addition & 1 deletion src/exception/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import ExceptionHandler from './handler';
export * from './error';

export {
ExceptionHandler
ExceptionHandler,
};
4 changes: 2 additions & 2 deletions src/framework/handler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'path';
import ConfigurationHandler, { ConfigObject } from '../configuration';
import { ManifestItem } from '../types';
import { ManifestItem } from '../loader/types';

export interface FrameworkConfig {
path?: string,
Expand All @@ -27,7 +27,7 @@ export class FrameworkHandler {
}

try {
let baseFrameworkPath = config.path ?? path.dirname(require.resolve(config.package ?? '', { paths: [root] }));
const baseFrameworkPath = config.path ?? path.dirname(require.resolve(config.package ?? '', { paths: [root] }));
return baseFrameworkPath;
} catch (err) {
throw new Error(`load framework faild: ${err}, framework config: ${JSON.stringify(config)}`);
Expand Down
9 changes: 1 addition & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@

export {
Inject,
Injectable
Injectable,
} from '@artus/injection';

export {
ArtusInjectEnum
} from './constant';
export * from './loader';
export * from './logger';
export * from './lifecycle';
Expand All @@ -24,7 +21,3 @@ export { ConfigurationHandler };

import Trigger from './trigger';
export { Trigger };

export type {
Manifest
} from './loader/types';
16 changes: 8 additions & 8 deletions src/lifecycle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
CONSTRUCTOR_PARAMS,
CONSTRUCTOR_PARAMS_APP,
CONSTRUCTOR_PARAMS_CONTAINER,
HOOK_NAME_META_PREFIX
HOOK_NAME_META_PREFIX,
} from '../constant';

export type HookFunction = <T = unknown>(hookProps : {
Expand All @@ -20,7 +20,7 @@ export class LifecycleManager {
'didLoad', // 文件加载完成
'willReady', // 插件启动完毕
'didReady', // 应用启动完成
'beforeClose' // 应用即将关闭
'beforeClose', // 应用即将关闭
];
hookFnMap: Map<string, HookFunction[]> = new Map();
private app: Application;
Expand All @@ -32,7 +32,7 @@ export class LifecycleManager {
}

insertHook(existHookName: string, newHookName: string) {
const startIndex = this.hookList.findIndex((val) => val === existHookName);
const startIndex = this.hookList.findIndex(val => val === existHookName);
this.hookList.splice(startIndex, 0, newHookName);
}

Expand All @@ -45,7 +45,7 @@ export class LifecycleManager {
this.hookFnMap.get(hookName)?.push(hookFn);
} else {
this.hookFnMap.set(hookName, [
hookFn
hookFn,
]);
}
}
Expand All @@ -55,9 +55,9 @@ export class LifecycleManager {
const constructorParams = Reflect.getMetadata(CONSTRUCTOR_PARAMS, extClazz) ?? [];
const paramsMap = {
[CONSTRUCTOR_PARAMS_APP]: this.app,
[CONSTRUCTOR_PARAMS_CONTAINER]: this.container
[CONSTRUCTOR_PARAMS_CONTAINER]: this.container,
};
const extClazzInstance = new extClazz(...constructorParams.map((param) => paramsMap[param]));
const extClazzInstance = new extClazz(...constructorParams.map(param => paramsMap[param]));
for (const fnMetaKey of fnMetaKeys) {
if (typeof fnMetaKey !== 'string' || !fnMetaKey.startsWith(HOOK_NAME_META_PREFIX)) {
continue;
Expand All @@ -80,8 +80,8 @@ export class LifecycleManager {
await hookFn({
app: this.app,
lifecycleManager: this,
payload
payload,
});
}
}
};
}
16 changes: 8 additions & 8 deletions src/loader/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,28 +46,28 @@ export class LoaderFactory {
after: () => {
this.container.set({
id: ArtusInjectEnum.Config,
value: this.configurationHandler.getMergedConfig()
value: this.configurationHandler.getMergedConfig(),
});
this.lifecycleManager.emitHook('configDidLoad');
}
},
},
'framework-config': {
after: () => this.container.set({
id: ArtusInjectEnum.Frameworks,
value: this.configurationHandler.getFrameworkConfig()
})
value: this.configurationHandler.getFrameworkConfig(),
}),
},
'package-json': {
after: () => this.container.set({
id: ArtusInjectEnum.Packages,
value: this.configurationHandler.getPackages()
})
}
value: this.configurationHandler.getPackages(),
}),
},
}, root);
}

async loadItemList(itemList: ManifestItem[] = [], hookMap?: Record<string, LoaderHookUnit>, root?: string): Promise<void> {
let prevLoader: string = '';
let prevLoader = '';
for (const item of itemList) {
item.path = root ? path.join(root, item.path) : item.path;
const curLoader = item.loader ?? DEFAULT_LOADER;
Expand Down
10 changes: 5 additions & 5 deletions src/loader/impl/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ class ConfigLoader implements Loader {
}

protected static isConfigDir(opts: LoaderFindOptions): boolean {
const { configDir, baseDir, root } = opts;
return path.join(baseDir, configDir) === root;
const { configDir, baseDir, root } = opts;
return path.join(baseDir, configDir) === root;
}

async load(item: ManifestItem) {
const { namespace, env } = await this.getConfigFileMeta(item);
let configObj = await this.loadConfigFile(item);
if (namespace) {
configObj = {
[namespace]: configObj
[namespace]: configObj,
};
}
this.configurationHandler.setConfig(env, configObj);
Expand All @@ -59,12 +59,12 @@ class ConfigLoader implements Loader {
env = ARTUS_DEFAULT_CONFIG_ENV.DEFAULT;
}
const meta: ConfigFileMeta = {
env
env,
};
if (namespace !== 'config') {
meta.namespace = namespace;
}
return meta
return meta;
}

protected async loadConfigFile(item: ManifestItem): Promise<Record<string, any>> {
Expand Down
4 changes: 0 additions & 4 deletions src/loader/impl/framework_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ import { isMatch } from '../../utils';

@DefineLoader('framework-config')
class FrameworkConfigLoader extends ConfigLoader implements Loader {
constructor(container) {
super(container);
}

static async is(opts: LoaderFindOptions): Promise<boolean> {
if (this.isConfigDir(opts)) {
return isMatch(opts.filename, FRAMEWORK_PATTERN);
Expand Down
2 changes: 1 addition & 1 deletion src/loader/impl/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ModuleLoader implements Loader {
const moduleClazz = await compatibleRequire(item.path);
const opts: Partial<InjectableDefinition> = {
path: item.path,
type: moduleClazz
type: moduleClazz,
};
if (item.id) {
opts.id = item.id;
Expand Down
4 changes: 2 additions & 2 deletions src/loader/impl/plugin_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class PluginConfigLoader extends ConfigLoader implements Loader {

async load(item: ManifestItem) {
const { env } = await this.getConfigFileMeta(item);
let configObj = await this.loadConfigFile(item);
const configObj = await this.loadConfigFile(item);
for (const pluginName of Object.keys(configObj)) {
const pluginConfigItem: PluginConfigItem = configObj[pluginName];
if (pluginConfigItem.package) {
Expand All @@ -34,7 +34,7 @@ class PluginConfigLoader extends ConfigLoader implements Loader {
}
}
this.configurationHandler.setConfig(env, {
plugin: configObj
plugin: configObj,
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/loader/impl/plugin_meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class PluginMetaLoader implements Loader {
const pluginMeta: PluginMetadata = await loadMetaFile<PluginMetadata>(item);
this.container.set({
id: `pluginMeta_${pluginMeta.name}`,
value: pluginMeta
value: pluginMeta,
});
}
}
Expand Down
Loading