From d9e1ab9753fc3d7c32fe34dff8743f96fc7cb573 Mon Sep 17 00:00:00 2001 From: Harry Chen Date: Fri, 1 Feb 2019 13:38:31 +0800 Subject: [PATCH] fix: fix lint --- package.json | 1 + packages/midway-core/package.json | 2 +- packages/midway-core/src/loading.ts | 4 +--- packages/midway-core/test/base.test.ts | 2 +- .../test/fixtures/base-app-async/src/config/plugin.ts | 2 +- .../fixtures/base-app-constructor/src/config/plugin.ts | 2 +- .../fixtures/base-app-constructor/src/lib/service.ts | 1 - .../base-app-decorator/src/app/controller/api.ts | 2 +- .../fixtures/base-app-decorator/src/config/plugin.ts | 2 +- .../base-app-function/src/app/controller/error.ts | 2 +- .../base-app-function/src/config/config.default.ts | 1 - .../test/fixtures/base-app-function/src/lib/adapter.ts | 4 +--- .../test/fixtures/base-app-function/src/lib/factory.ts | 9 ++++----- .../fixtures/base-app-function/src/lib/otherFactory.ts | 1 - .../test/fixtures/base-app-function/src/lib/service.ts | 1 - packages/midway-core/test/fixtures/midway/index.ts | 8 ++++---- .../midway-core/test/fixtures/ts-app-inject/app.ts | 5 ++--- packages/midway-core/test/midwayContainer.test.ts | 4 ++-- packages/midway-web/package.json | 2 +- .../enhance/base-app-constructor/src/lib/service.ts | 1 - .../src/app/controller/api.ts | 3 +-- .../src/app/controller/my.ts | 2 +- .../src/app/controller/api.ts | 3 +-- .../base-app-controller/src/app/controller/api.ts | 3 +-- .../base-app-controller/src/app/controller/my.ts | 2 +- .../base-app-decorator/src/app/controller/hello.ts | 4 ++-- .../enhance/base-app-decorator/src/lib/HelloService.ts | 5 ++--- .../base-app-function/src/config/config.default.ts | 1 - .../enhance/base-app-function/src/lib/adapter.ts | 1 - .../enhance/base-app-function/src/lib/factory.ts | 5 ++--- .../enhance/base-app-function/src/lib/service.ts | 1 - .../test/fixtures/enhance/ts-app-inject/app.ts | 5 ++--- tslint.json | 10 ++++------ 33 files changed, 40 insertions(+), 61 deletions(-) diff --git a/package.json b/package.json index 6ffdb952d8a1..86749211a0be 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "opencollective-postinstall": "^2.0.1", "tree-kill": "^1.2.0", "tslint": "^5.12.0", + "tslint-no-unused-expression-chai": "^0.1.4", "typedoc": "^0.11.1", "typescript": "^3.2.0", "vuepress": "^0.14.8" diff --git a/packages/midway-core/package.json b/packages/midway-core/package.json index 53c8ff09248e..ef557edc578d 100644 --- a/packages/midway-core/package.json +++ b/packages/midway-core/package.json @@ -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 --fix 'src/**/*.ts'", + "lint": "../../node_modules/.bin/tslint --format prose -c ../../tslint.json --fix 'src/**/*.ts' 'test/**/*.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" diff --git a/packages/midway-core/src/loading.ts b/packages/midway-core/src/loading.ts index 986879bfeef1..c0c1b82334b8 100644 --- a/packages/midway-core/src/loading.ts +++ b/packages/midway-core/src/loading.ts @@ -1,7 +1,6 @@ /** * Midway Loading 文件加载 */ -/* tslint:disable:no-unused-expression */ const debug = require('debug')('midway:loading'); const is = require('is-type-of'); const globby = require('globby'); @@ -18,7 +17,7 @@ function inject(obj, properties, result) { obj[property] = result; return; } - obj[property] || (obj[property] = {}); + obj[property] = obj[property] || {}; inject(obj[property], properties, result); } @@ -98,4 +97,3 @@ export function loading(files, options) { return results; } -/* tslint:enable:no-unused-expression */ diff --git a/packages/midway-core/test/base.test.ts b/packages/midway-core/test/base.test.ts index d20265d80110..80d943a1c0cf 100644 --- a/packages/midway-core/test/base.test.ts +++ b/packages/midway-core/test/base.test.ts @@ -4,7 +4,7 @@ import * as extend2 from 'extend2'; describe('/test/base.test.ts', () => { it('should proxy app when set property', () => { let app = {}; - let pluginContext = {}; + const pluginContext = {}; app = new Proxy(app, { defineProperty(target, prop, attributes) { diff --git a/packages/midway-core/test/fixtures/base-app-async/src/config/plugin.ts b/packages/midway-core/test/fixtures/base-app-async/src/config/plugin.ts index e598173ff4ea..3ef9a51a57e7 100644 --- a/packages/midway-core/test/fixtures/base-app-async/src/config/plugin.ts +++ b/packages/midway-core/test/fixtures/base-app-async/src/config/plugin.ts @@ -10,4 +10,4 @@ module.exports = { enable: true, path: path.join(__dirname, '../plugins/plugin2'), } -}; \ No newline at end of file +}; diff --git a/packages/midway-core/test/fixtures/base-app-constructor/src/config/plugin.ts b/packages/midway-core/test/fixtures/base-app-constructor/src/config/plugin.ts index e598173ff4ea..3ef9a51a57e7 100644 --- a/packages/midway-core/test/fixtures/base-app-constructor/src/config/plugin.ts +++ b/packages/midway-core/test/fixtures/base-app-constructor/src/config/plugin.ts @@ -10,4 +10,4 @@ module.exports = { enable: true, path: path.join(__dirname, '../plugins/plugin2'), } -}; \ No newline at end of file +}; diff --git a/packages/midway-core/test/fixtures/base-app-constructor/src/lib/service.ts b/packages/midway-core/test/fixtures/base-app-constructor/src/lib/service.ts index 3bfaa9a03442..e784a0861389 100644 --- a/packages/midway-core/test/fixtures/base-app-constructor/src/lib/service.ts +++ b/packages/midway-core/test/fixtures/base-app-constructor/src/lib/service.ts @@ -1,7 +1,6 @@ import {config, plugin} from '../../../../../src/decorators'; import {provide, async, init, inject} from 'injection'; - @provide() export class A { config = { diff --git a/packages/midway-core/test/fixtures/base-app-decorator/src/app/controller/api.ts b/packages/midway-core/test/fixtures/base-app-decorator/src/app/controller/api.ts index 6c86c4324116..16044ac3b7b2 100644 --- a/packages/midway-core/test/fixtures/base-app-decorator/src/app/controller/api.ts +++ b/packages/midway-core/test/fixtures/base-app-decorator/src/app/controller/api.ts @@ -11,4 +11,4 @@ exports.baseService = async (ctx, next) => { const context = ctx.app.applicationContext; const baseService = await context.getAsync(BaseService); ctx.body = baseService.config.c + baseService.plugin2.text; -}; \ No newline at end of file +}; diff --git a/packages/midway-core/test/fixtures/base-app-decorator/src/config/plugin.ts b/packages/midway-core/test/fixtures/base-app-decorator/src/config/plugin.ts index e598173ff4ea..3ef9a51a57e7 100644 --- a/packages/midway-core/test/fixtures/base-app-decorator/src/config/plugin.ts +++ b/packages/midway-core/test/fixtures/base-app-decorator/src/config/plugin.ts @@ -10,4 +10,4 @@ module.exports = { enable: true, path: path.join(__dirname, '../plugins/plugin2'), } -}; \ No newline at end of file +}; diff --git a/packages/midway-core/test/fixtures/base-app-function/src/app/controller/error.ts b/packages/midway-core/test/fixtures/base-app-function/src/app/controller/error.ts index b4ccdc37d3d1..3d6958118c62 100644 --- a/packages/midway-core/test/fixtures/base-app-function/src/app/controller/error.ts +++ b/packages/midway-core/test/fixtures/base-app-function/src/app/controller/error.ts @@ -9,4 +9,4 @@ exports.error = async (ctx, next) => { } ctx.body = 'error'; -}; \ No newline at end of file +}; diff --git a/packages/midway-core/test/fixtures/base-app-function/src/config/config.default.ts b/packages/midway-core/test/fixtures/base-app-function/src/config/config.default.ts index 6c3f40334fa2..a7960fac6a8b 100644 --- a/packages/midway-core/test/fixtures/base-app-function/src/config/config.default.ts +++ b/packages/midway-core/test/fixtures/base-app-function/src/config/config.default.ts @@ -11,5 +11,4 @@ export const plugins = { plugin2: true }; - export const adapterName = 'google'; diff --git a/packages/midway-core/test/fixtures/base-app-function/src/lib/adapter.ts b/packages/midway-core/test/fixtures/base-app-function/src/lib/adapter.ts index 39c94079cf0e..f235356c6c47 100644 --- a/packages/midway-core/test/fixtures/base-app-function/src/lib/adapter.ts +++ b/packages/midway-core/test/fixtures/base-app-function/src/lib/adapter.ts @@ -1,5 +1,4 @@ -import {provide} from 'injection'; -import { autowire } from 'injection'; +import { autowire, provide } from 'injection'; @provide() @autowire(false) @@ -10,4 +9,3 @@ export class GoogleAdapter { @provide() export class BaiduAdapter { } - diff --git a/packages/midway-core/test/fixtures/base-app-function/src/lib/factory.ts b/packages/midway-core/test/fixtures/base-app-function/src/lib/factory.ts index b1d8c14aa8aa..24eb4d8461b2 100644 --- a/packages/midway-core/test/fixtures/base-app-function/src/lib/factory.ts +++ b/packages/midway-core/test/fixtures/base-app-function/src/lib/factory.ts @@ -3,12 +3,12 @@ import {IApplicationContext} from 'injection'; export function adapterFactory(context: IApplicationContext) { return async (adapterName: string) => { - if(adapterName === 'google') { - return await context.getAsync('googleAdapter'); + if (adapterName === 'google') { + return context.getAsync('googleAdapter'); } - if(adapterName === 'baidu') { - return await context.getAsync('baiduAdapter'); + if (adapterName === 'baidu') { + return context.getAsync('baiduAdapter'); } }; } @@ -19,4 +19,3 @@ providerWrapper([ provider: adapterFactory } ]); - diff --git a/packages/midway-core/test/fixtures/base-app-function/src/lib/otherFactory.ts b/packages/midway-core/test/fixtures/base-app-function/src/lib/otherFactory.ts index 30ab80353e48..ffdc8802770b 100644 --- a/packages/midway-core/test/fixtures/base-app-function/src/lib/otherFactory.ts +++ b/packages/midway-core/test/fixtures/base-app-function/src/lib/otherFactory.ts @@ -49,7 +49,6 @@ export function otherFactory3(context: IApplicationContext) { return new MyTestAuto('test'); } - providerWrapper([ { id: 'otherFactory', diff --git a/packages/midway-core/test/fixtures/base-app-function/src/lib/service.ts b/packages/midway-core/test/fixtures/base-app-function/src/lib/service.ts index 4a1dd7001b9e..c2fa6f4ed0c1 100644 --- a/packages/midway-core/test/fixtures/base-app-function/src/lib/service.ts +++ b/packages/midway-core/test/fixtures/base-app-function/src/lib/service.ts @@ -1,7 +1,6 @@ import {config, plugin} from '../../../../../src/decorators'; import {provide, async, init, inject} from 'injection'; - @provide() export class A { config = { diff --git a/packages/midway-core/test/fixtures/midway/index.ts b/packages/midway-core/test/fixtures/midway/index.ts index 476b066d1ce6..dcd1d994e532 100644 --- a/packages/midway-core/test/fixtures/midway/index.ts +++ b/packages/midway-core/test/fixtures/midway/index.ts @@ -51,9 +51,9 @@ export class AgentWorkerLoader extends MidwayLoader { } -class MidwayApplication extends (<{ +class MidwayApplication extends (Application as { new(...x) -}> Application) { +}) { get [Symbol.for('egg#loader')]() { return AppWorkerLoader; @@ -68,9 +68,9 @@ class MidwayApplication extends (<{ } } -class MidwayAgent extends (<{ +class MidwayAgent extends (Agent as { new(...x) -}> Agent) { +}) { get [Symbol.for('egg#loader')]() { return AgentWorkerLoader; diff --git a/packages/midway-core/test/fixtures/ts-app-inject/app.ts b/packages/midway-core/test/fixtures/ts-app-inject/app.ts index ffc552e53818..cfdc88c03508 100644 --- a/packages/midway-core/test/fixtures/ts-app-inject/app.ts +++ b/packages/midway-core/test/fixtures/ts-app-inject/app.ts @@ -1,6 +1,5 @@ -import {Loader} from './loader'; -import {provide} from 'injection'; -import {inject} from 'injection'; +import { inject, provide } from 'injection'; +import { Loader } from './loader'; @provide() export class App { diff --git a/packages/midway-core/test/midwayContainer.test.ts b/packages/midway-core/test/midwayContainer.test.ts index 55bcc53a1e47..505f361aebfc 100644 --- a/packages/midway-core/test/midwayContainer.test.ts +++ b/packages/midway-core/test/midwayContainer.test.ts @@ -12,7 +12,7 @@ describe('/test/midwayContainer.test.ts', () => { loadDir: path.join(__dirname, './fixtures/ts-app-inject') }); - const app = container.get('app'); + const app = container.get('app') as App; expect(app.loader).not.to.be.undefined; expect(app.getConfig().a).to.equal(3); // 其实这里循环依赖了 @@ -25,7 +25,7 @@ describe('/test/midwayContainer.test.ts', () => { loadDir: path.join(__dirname, './fixtures/js-app-inject') }); - const app = container.get('app'); + const app = container.get('app') as App; expect(app.getConfig().a).to.equal(1); }); diff --git a/packages/midway-web/package.json b/packages/midway-web/package.json index 3ffe5bacf426..8f1342dcc20c 100644 --- a/packages/midway-web/package.json +++ b/packages/midway-web/package.json @@ -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 --fix 'src/**/*.ts'", + "lint": "../../node_modules/.bin/tslint --format prose -c ../../tslint.json --fix 'src/**/*.ts' 'test/**/*.ts'", "test": "npm run lint && midway-bin clean && NODE_ENV=test midway-bin test --ts", "cov": "midway-bin cov --ts", "ci": "npm run test", diff --git a/packages/midway-web/test/fixtures/enhance/base-app-constructor/src/lib/service.ts b/packages/midway-web/test/fixtures/enhance/base-app-constructor/src/lib/service.ts index 262c92b79b19..6c95dff00dfd 100644 --- a/packages/midway-web/test/fixtures/enhance/base-app-constructor/src/lib/service.ts +++ b/packages/midway-web/test/fixtures/enhance/base-app-constructor/src/lib/service.ts @@ -1,7 +1,6 @@ import {config, plugin} from 'midway-core'; import {provide, async, init, inject} from 'injection'; - @provide() export class A { config = { diff --git a/packages/midway-web/test/fixtures/enhance/base-app-controller-conflicts/src/app/controller/api.ts b/packages/midway-web/test/fixtures/enhance/base-app-controller-conflicts/src/app/controller/api.ts index af4aaac66f12..ab6cd4ae7c75 100644 --- a/packages/midway-web/test/fixtures/enhance/base-app-controller-conflicts/src/app/controller/api.ts +++ b/packages/midway-web/test/fixtures/enhance/base-app-controller-conflicts/src/app/controller/api.ts @@ -1,6 +1,5 @@ 'use strict'; - import { inject, provide, scope, ScopeEnum } from 'injection'; import { controller, get } from '../../../../../../../src/'; @@ -26,4 +25,4 @@ export class My { assert(this.logger.constructor.name === 'ContextLogger'); ctx.body = 'hello'; } -} \ No newline at end of file +} diff --git a/packages/midway-web/test/fixtures/enhance/base-app-controller-conflicts/src/app/controller/my.ts b/packages/midway-web/test/fixtures/enhance/base-app-controller-conflicts/src/app/controller/my.ts index 05df29d43dcb..44902af7415b 100644 --- a/packages/midway-web/test/fixtures/enhance/base-app-controller-conflicts/src/app/controller/my.ts +++ b/packages/midway-web/test/fixtures/enhance/base-app-controller-conflicts/src/app/controller/my.ts @@ -8,4 +8,4 @@ export class My { async index(ctx) { ctx.body = 'root_test'; } -} \ No newline at end of file +} diff --git a/packages/midway-web/test/fixtures/enhance/base-app-controller-default-export/src/app/controller/api.ts b/packages/midway-web/test/fixtures/enhance/base-app-controller-default-export/src/app/controller/api.ts index 53678646d6ff..20a89f43a056 100644 --- a/packages/midway-web/test/fixtures/enhance/base-app-controller-default-export/src/app/controller/api.ts +++ b/packages/midway-web/test/fixtures/enhance/base-app-controller-default-export/src/app/controller/api.ts @@ -1,6 +1,5 @@ 'use strict'; - import { inject, provide, scope, ScopeEnum } from 'injection'; import { controller, get } from '../../../../../../../src/'; @@ -26,4 +25,4 @@ export class Api { assert(this.logger.constructor.name === 'ContextLogger'); ctx.body = 'hello'; } -} \ No newline at end of file +} diff --git a/packages/midway-web/test/fixtures/enhance/base-app-controller/src/app/controller/api.ts b/packages/midway-web/test/fixtures/enhance/base-app-controller/src/app/controller/api.ts index 53678646d6ff..20a89f43a056 100644 --- a/packages/midway-web/test/fixtures/enhance/base-app-controller/src/app/controller/api.ts +++ b/packages/midway-web/test/fixtures/enhance/base-app-controller/src/app/controller/api.ts @@ -1,6 +1,5 @@ 'use strict'; - import { inject, provide, scope, ScopeEnum } from 'injection'; import { controller, get } from '../../../../../../../src/'; @@ -26,4 +25,4 @@ export class Api { assert(this.logger.constructor.name === 'ContextLogger'); ctx.body = 'hello'; } -} \ No newline at end of file +} diff --git a/packages/midway-web/test/fixtures/enhance/base-app-controller/src/app/controller/my.ts b/packages/midway-web/test/fixtures/enhance/base-app-controller/src/app/controller/my.ts index 05df29d43dcb..44902af7415b 100644 --- a/packages/midway-web/test/fixtures/enhance/base-app-controller/src/app/controller/my.ts +++ b/packages/midway-web/test/fixtures/enhance/base-app-controller/src/app/controller/my.ts @@ -8,4 +8,4 @@ export class My { async index(ctx) { ctx.body = 'root_test'; } -} \ No newline at end of file +} diff --git a/packages/midway-web/test/fixtures/enhance/base-app-decorator/src/app/controller/hello.ts b/packages/midway-web/test/fixtures/enhance/base-app-decorator/src/app/controller/hello.ts index 974b3c1a4125..9ff9e1b8e2e2 100644 --- a/packages/midway-web/test/fixtures/enhance/base-app-decorator/src/app/controller/hello.ts +++ b/packages/midway-web/test/fixtures/enhance/base-app-decorator/src/app/controller/hello.ts @@ -6,9 +6,9 @@ import { HelloService } from '../../lib/HelloService'; @provide() @controller('/hello') export class HelloController { - name: Array = ['a', 'b']; + name: string[] = ['a', 'b']; - xxx: string = 'hjjj'; + xxx = 'hjjj'; aaaa; diff --git a/packages/midway-web/test/fixtures/enhance/base-app-decorator/src/lib/HelloService.ts b/packages/midway-web/test/fixtures/enhance/base-app-decorator/src/lib/HelloService.ts index ccadceaf4c3c..3564c6dfae0a 100644 --- a/packages/midway-web/test/fixtures/enhance/base-app-decorator/src/lib/HelloService.ts +++ b/packages/midway-web/test/fixtures/enhance/base-app-decorator/src/lib/HelloService.ts @@ -1,10 +1,9 @@ import {provide, inject} from 'injection'; import { BaseService } from './service'; - @provide() export class HelloService { - xxx: Array = ['a', 'b']; + xxx: string[] = ['a', 'b']; name: string; @@ -17,4 +16,4 @@ export class HelloService { } return `${this.xxx.join(',')}`; } -} \ No newline at end of file +} diff --git a/packages/midway-web/test/fixtures/enhance/base-app-function/src/config/config.default.ts b/packages/midway-web/test/fixtures/enhance/base-app-function/src/config/config.default.ts index 6c3f40334fa2..a7960fac6a8b 100644 --- a/packages/midway-web/test/fixtures/enhance/base-app-function/src/config/config.default.ts +++ b/packages/midway-web/test/fixtures/enhance/base-app-function/src/config/config.default.ts @@ -11,5 +11,4 @@ export const plugins = { plugin2: true }; - export const adapterName = 'google'; diff --git a/packages/midway-web/test/fixtures/enhance/base-app-function/src/lib/adapter.ts b/packages/midway-web/test/fixtures/enhance/base-app-function/src/lib/adapter.ts index 3afbb131842a..3798e0b7d10c 100644 --- a/packages/midway-web/test/fixtures/enhance/base-app-function/src/lib/adapter.ts +++ b/packages/midway-web/test/fixtures/enhance/base-app-function/src/lib/adapter.ts @@ -9,4 +9,3 @@ export class GoogleAdapter { export class BaiduAdapter { } - diff --git a/packages/midway-web/test/fixtures/enhance/base-app-function/src/lib/factory.ts b/packages/midway-web/test/fixtures/enhance/base-app-function/src/lib/factory.ts index ec31021169af..5479cdc40783 100644 --- a/packages/midway-web/test/fixtures/enhance/base-app-function/src/lib/factory.ts +++ b/packages/midway-web/test/fixtures/enhance/base-app-function/src/lib/factory.ts @@ -4,11 +4,11 @@ import { IApplicationContext } from 'injection'; export function adapterFactory(context: IApplicationContext) { return async (adapterName: string) => { if (adapterName === 'google') { - return await context.getAsync('googleAdapter'); + return context.getAsync('googleAdapter'); } if (adapterName === 'baidu') { - return await context.getAsync('baiduAdapter'); + return context.getAsync('baiduAdapter'); } }; } @@ -30,4 +30,3 @@ providerWrapper([ provider: contextHandler } ]); - diff --git a/packages/midway-web/test/fixtures/enhance/base-app-function/src/lib/service.ts b/packages/midway-web/test/fixtures/enhance/base-app-function/src/lib/service.ts index e65196561c7a..c8a1e31c636e 100644 --- a/packages/midway-web/test/fixtures/enhance/base-app-function/src/lib/service.ts +++ b/packages/midway-web/test/fixtures/enhance/base-app-function/src/lib/service.ts @@ -1,7 +1,6 @@ import { config, plugin } from 'midway-core'; import { async, init, inject, provide } from 'injection'; - @provide() export class A { config = { diff --git a/packages/midway-web/test/fixtures/enhance/ts-app-inject/app.ts b/packages/midway-web/test/fixtures/enhance/ts-app-inject/app.ts index ffc552e53818..cfdc88c03508 100644 --- a/packages/midway-web/test/fixtures/enhance/ts-app-inject/app.ts +++ b/packages/midway-web/test/fixtures/enhance/ts-app-inject/app.ts @@ -1,6 +1,5 @@ -import {Loader} from './loader'; -import {provide} from 'injection'; -import {inject} from 'injection'; +import { inject, provide } from 'injection'; +import { Loader } from './loader'; @provide() export class App { diff --git a/tslint.json b/tslint.json index 78a596ec884c..58a2fe333db1 100644 --- a/tslint.json +++ b/tslint.json @@ -1,8 +1,6 @@ { - "extends": "./packages/tslint-midway-contrib/tslint.json", - "linterOptions": { - "exclude": [ - "**/test/**" - ] - } + "extends": [ + "./packages/tslint-midway-contrib/tslint.json", + "tslint-no-unused-expression-chai" + ] }