Skip to content

Commit

Permalink
fix: fix more lint
Browse files Browse the repository at this point in the history
  • Loading branch information
czy88840616 committed Feb 1, 2019
1 parent 0bc9686 commit 12873dc
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 59 deletions.
2 changes: 1 addition & 1 deletion packages/midway-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"typings": "dist/index.d.ts",
"scripts": {
"build": "npm run lint && midway-bin build -c",
"lint": "../../node_modules/.bin/tslint --format prose -c ../../tslint.json src/**/*.ts test/**/*.ts",
"lint": "../../node_modules/.bin/tslint --format prose -c ../../tslint.json --fix 'src/**/*.ts'",
"test": "npm run lint && midway-bin clean && NODE_ENV=test midway-bin test --ts",
"cov": "midway-bin clean && midway-bin cov --ts",
"autod": "midway-bin autod"
Expand Down
36 changes: 18 additions & 18 deletions packages/midway-core/src/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class LoggerResolver implements IManagedResolver {
}

resolve(managed: IManagedInstance): any {
const log: ManagedLogger = <ManagedLogger>managed;
const log: ManagedLogger = managed as ManagedLogger;
if (log.name) {
return this.container.handlerMap.get(MidwayHandlerKey.LOGGER)(log.name);
}
Expand Down Expand Up @@ -151,7 +151,7 @@ class PluginResolver implements IManagedResolver {
}

resolve(managed: IManagedInstance): any {
const p = <ManagedPlugin>managed;
const p = managed as ManagedPlugin;
return this.container.handlerMap.get(MidwayHandlerKey.PLUGIN)(p.name);
}

Expand All @@ -161,8 +161,8 @@ class PluginResolver implements IManagedResolver {
}

export class MidwayContainer extends Container implements IContainer {
controllersIds: Array<string> = [];
middlewaresIds: Array<string> = [];
controllersIds: string[] = [];
middlewaresIds: string[] = [];
handlerMap: Map<string, (handlerKey: string) => any>;
// 仅仅用于兼容requestContainer的ctx
ctx = {};
Expand Down Expand Up @@ -206,8 +206,8 @@ export class MidwayContainer extends Container implements IContainer {
}) {
const loadDirs = [].concat(opts.loadDir || []);

for (let dir of loadDirs) {
let fileResults = globby.sync(['**/**.ts', '**/**.js', '!**/**.d.ts'].concat(opts.pattern || []), {
for (const dir of loadDirs) {
const fileResults = globby.sync(['**/**.ts', '**/**.js', '!**/**.d.ts'].concat(opts.pattern || []), {
cwd: dir,
ignore: [
'**/node_modules/**',
Expand All @@ -219,15 +219,15 @@ export class MidwayContainer extends Container implements IContainer {
].concat(opts.ignore || []),
});

for (let name of fileResults) {
for (const name of fileResults) {
const file = path.join(dir, name);
debug(`binding file => ${file}`);
let exports = require(file);
const exports = require(file);

if (is.class(exports) || is.function(exports)) {
this.bindClass(exports);
} else {
for (let m in exports) {
for (const m in exports) {
const module = exports[m];
if (is.class(module) || is.function(module)) {
this.bindClass(module);
Expand All @@ -238,17 +238,17 @@ export class MidwayContainer extends Container implements IContainer {
}
}

private bindClass(module) {
protected bindClass(module) {
if (is.class(module)) {
let metaData = <TagClsMetadata>Reflect.getMetadata(TAGGED_CLS, module);
const metaData = Reflect.getMetadata(TAGGED_CLS, module) as TagClsMetadata;
if (metaData) {
this.bind(metaData.id, module);
} else {
// inject by name in js
this.bind(camelcase(module.name), module);
}
} else {
let info: {
const info: {
id: ObjectIdentifier,
provider: (context?: IApplicationContext) => any,
scope?: Scope,
Expand Down Expand Up @@ -283,8 +283,8 @@ export class MidwayContainer extends Container implements IContainer {
}
// lack of field
if (constructorMetaData && constructorArgs) {
for (let idx in constructorMetaData) {
let index = parseInt(idx, 10);
for (const idx in constructorMetaData) {
const index = parseInt(idx, 10);
const propertyMeta = constructorMetaData[index];
let result;

Expand Down Expand Up @@ -345,7 +345,7 @@ export class MidwayContainer extends Container implements IContainer {
* @param target
* @returns {Array<string>}
*/
private getClzSetterProps(setterClzKey, target): Array<string> {
private getClzSetterProps(setterClzKey, target): string[] {
return Reflect.getMetadata(setterClzKey, target);
}

Expand All @@ -359,8 +359,8 @@ export class MidwayContainer extends Container implements IContainer {
*/
private defineGetterPropertyValue(setterProps, metadataKey, instance, getterHandler) {
if (setterProps && getterHandler) {
for (let prop of setterProps) {
let propertyKey = Reflect.getMetadata(metadataKey, instance, prop);
for (const prop of setterProps) {
const propertyKey = Reflect.getMetadata(metadataKey, instance, prop);
if (propertyKey) {
Object.defineProperty(instance, prop, {
get: () => getterHandler(propertyKey),
Expand All @@ -380,7 +380,7 @@ export class MidwayContainer extends Container implements IContainer {
super.registerCustomBinding(objectDefinition, target);

// Override the default scope to request
let objDefOptions: ObjectDefinitionOptions = Reflect.getMetadata(OBJ_DEF_CLS, target);
const objDefOptions: ObjectDefinitionOptions = Reflect.getMetadata(OBJ_DEF_CLS, target);
if (objDefOptions && !objDefOptions.scope) {
debug(`register @scope to default value(request), id=${objectDefinition.id}`);
objectDefinition.scope = ScopeEnum.Request;
Expand Down
8 changes: 4 additions & 4 deletions packages/midway-core/src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class MidwayLoader extends EggLoader {
}

const name = plugin.package || plugin.name;
let lookupDirs = [];
const lookupDirs = [];

// 尝试在以下目录找到匹配的插件
// -> {APP_PATH}/node_modules
Expand Down Expand Up @@ -144,7 +144,7 @@ export class MidwayLoader extends EggLoader {

protected loadApplicationContext() {
// this.app.options.container 测试用例编写方便点
let containerConfig = this.config.container || this.app.options.container || {};
const containerConfig = this.config.container || this.app.options.container || {};
// 在 super contructor 中会调用到getAppInfo,之后会被赋值
// 如果是typescript会加上 dist 或者 src 目录
this.applicationContext = new MidwayContainer(this.baseDir);
Expand Down Expand Up @@ -196,7 +196,7 @@ export class MidwayLoader extends EggLoader {
if (!self.pluginLoaded && isPluginName(prop) && !(prop in pluginContainerProps)) {
// save to context when called app.xxx = xxx
// now we can get plugin from context
debug(`pluginContext register [${<string>prop}]`);
debug(`pluginContext register [${prop as string}]`);
self.pluginContext.registerObject(prop, attributes.value);
}
return Object.defineProperty(target, prop, attributes);
Expand All @@ -206,7 +206,7 @@ export class MidwayLoader extends EggLoader {
this.getLoadUnits()
.forEach(unit => {
// 兼容旧插件加载方式
let ret = this.loadFile(this.resolveModule(path.join(unit.path, fileName)));
const ret = this.loadFile(this.resolveModule(path.join(unit.path, fileName)));
if (ret) {
// midway 的插件会返回对象
debug(`pluginContext register [${unit.name}]`);
Expand Down
20 changes: 11 additions & 9 deletions packages/midway-core/src/loading.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**!
/**
* Midway Loading 文件加载
*/
/* tslint:disable:no-unused-expression */
const debug = require('debug')('midway:loading');
const is = require('is-type-of');
const globby = require('globby');
Expand All @@ -26,13 +27,13 @@ export function loading(files, options) {

options = Object.assign({
call: true,
ignore: function(exports, file, dir) {
ignore(exports, file, dir) {
return false;
},
resultHandler: function(result, file, dir, exports) {
resultHandler(result, file, dir, exports) {
return result;
},
propertyHandler: function(properties, name, file) {
propertyHandler(properties, name, file) {
return properties;
}
}, options);
Expand All @@ -41,16 +42,16 @@ export function loading(files, options) {

const into = is.object(options.into) && options.into;
const flatten = !!options.flatten;
let results = [];
let loadDirs = [].concat(options.loadDirs);
const results = [];
const loadDirs = [].concat(options.loadDirs);

loadDirs.forEach((dir) => {
let fileResults = globby.sync(files, {cwd: dir});
const fileResults = globby.sync(files, {cwd: dir});

fileResults.forEach((name) => {
const file = path.join(dir, name);
debug(`LoadFiles => [${file}]: will load`);
let exports = require(file);
const exports = require(file);
if (options.ignore(exports, file, dir)) {
return;
}
Expand All @@ -67,7 +68,7 @@ export function loading(files, options) {
const reg = /^[a-z][\.a-z0-9_-]*$/i; // 不支持 comma(,)
let properties = name.replace(/\.js$/, '')
.split('/')
.map( property => {
.map(property => {
if (!reg.test(property)) {
throw new Error(`${property} does not match ${reg} in ${name}`);
}
Expand Down Expand Up @@ -97,3 +98,4 @@ export function loading(files, options) {

return results;
}
/* tslint:enable:no-unused-expression */
4 changes: 2 additions & 2 deletions packages/midway-core/src/requestContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ export class MidwayRequestContainer extends MidwayContainer {
definition.constructorArgs = [valueManagedIns];
}
// create object from applicationContext definition for requestScope
return await this.resolverFactory.createAsync(definition, args);
return this.resolverFactory.createAsync(definition, args);
}

if (this.parent) {
return await this.parent.getAsync<T>(identifier, args);
return this.parent.getAsync<T>(identifier, args);
}
}
}
2 changes: 1 addition & 1 deletion packages/midway-mock/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"typings": "dist/index.d.ts",
"scripts": {
"build": "npm run lint && midway-bin build -c",
"lint": "../../node_modules/.bin/tslint --format prose -c ../../tslint.json src/**/*.ts test/**/*.ts",
"lint": "../../node_modules/.bin/tslint --format prose -c ../../tslint.json --fix 'src/**/*.ts'",
"test": "npm run lint && midway-bin clean && midway-bin test --ts",
"cov": "midway-bin cov --ts",
"ci": "midway-bin test",
Expand Down
2 changes: 1 addition & 1 deletion packages/midway-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"typings": "dist/index.d.ts",
"scripts": {
"build": "npm run lint && midway-bin build -c",
"lint": "../../node_modules/.bin/tslint --format prose -c ../../tslint.json src/**/*.ts test/**/*.ts",
"lint": "../../node_modules/.bin/tslint --format prose -c ../../tslint.json --fix 'src/**/*.ts'",
"test": "npm run lint && midway-bin clean && NODE_ENV=test midway-bin test --ts",
"cov": "midway-bin cov --ts",
"ci": "npm run test",
Expand Down
2 changes: 1 addition & 1 deletion packages/midway-web/src/baseController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Route {
}

export class BaseController {
routes: Array<Route> = [];
routes: Route[] = [];

constructor() {
this.init();
Expand Down
16 changes: 8 additions & 8 deletions packages/midway-web/src/loading.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**!
/**
* Midway Loading 文件加载
*/
const debug = require('debug')('midway:loading');
Expand All @@ -13,29 +13,29 @@ export function loading(files, options) {

options = Object.assign({
call: true,
ignore: function(exports, file, dir) {
ignore(exports, file, dir) {
return false;
},
resultHandler: function(result, file, dir, exports) {
resultHandler(result, file, dir, exports) {
return result;
},
propertyHandler: function(properties, name, file) {
propertyHandler(properties, name, file) {
return properties;
}
}, options);

files = [].concat(files);

let results = [];
let loadDirs = [].concat(options.loadDirs);
const results = [];
const loadDirs = [].concat(options.loadDirs);

loadDirs.forEach((dir) => {
let fileResults = globby.sync(files, {cwd: dir});
const fileResults = globby.sync(files, {cwd: dir});

fileResults.forEach((name) => {
const file = path.join(dir, name);
debug(`LoadFiles => [${file}]: will load`);
let exports = require(file);
const exports = require(file);
if (options.ignore(exports, file, dir)) {
return;
}
Expand Down
18 changes: 9 additions & 9 deletions packages/midway-web/src/midway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import * as path from 'path';

const MIDWAY_PATH = path.dirname(__dirname);

class MidwayApplication extends (<{
class MidwayApplication extends (Application as {
new(...x)
}> Application) {
}) {

get [Symbol.for('egg#loader')]() {
return AppWorkerLoader;
Expand All @@ -35,15 +35,15 @@ class MidwayApplication extends (<{
}

getPluginContext() {
return (<AppWorkerLoader>this.loader).pluginContext;
return (this.loader as AppWorkerLoader).pluginContext;
}

getApplicationContext() {
return (<AppWorkerLoader>this.loader).applicationContext;
return (this.loader as AppWorkerLoader).applicationContext;
}

generateController(controllerMapping: string) {
return (<AppWorkerLoader>this.loader).generateController(controllerMapping);
return (this.loader as AppWorkerLoader).generateController(controllerMapping);
}

/**
Expand Down Expand Up @@ -90,9 +90,9 @@ class MidwayApplication extends (<{
}
}

class MidwayAgent extends (<{
class MidwayAgent extends (Agent as {
new(...x)
}> Agent) {
}) {

get [Symbol.for('egg#loader')]() {
return AgentWorkerLoader;
Expand All @@ -115,11 +115,11 @@ class MidwayAgent extends (<{
}

getPluginContext() {
return (<AgentWorkerLoader>this.loader).pluginContext;
return (this.loader as AgentWorkerLoader).pluginContext;
}

getApplicationContext() {
return (<AgentWorkerLoader>this.loader).applicationContext;
return (this.loader as AgentWorkerLoader).applicationContext;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions packages/midway-web/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'reflect-metadata';
export function attachMetaDataOnClass(clz, key, value) {
// save method name on class
let classMetaValue = Reflect.getMetadata(key, clz);
if(classMetaValue) {
if (classMetaValue) {
classMetaValue = classMetaValue.concat(value);
} else {
classMetaValue = [value];
Expand Down Expand Up @@ -42,15 +42,15 @@ export function getMethodNames(obj) {
const allOwnKeysOnPrototype = Object.getOwnPropertyNames(proto);
// get methods from es6 class
allOwnKeysOnPrototype.forEach(k => {
if(typeof obj[k] === 'function' && k !== 'constructor') {
if (typeof obj[k] === 'function' && k !== 'constructor') {
result.push(k);
}
});
}
while(proto && proto !== Object.prototype);
while (proto && proto !== Object.prototype);

// leave out those methods on Object's prototype
return result.filter(k => {
return ownKeysOnObjectPrototype.indexOf(k) === -1;
});
}
}
Loading

0 comments on commit 12873dc

Please sign in to comment.