Skip to content

Commit 6ea0f05

Browse files
committedFeb 21, 2018
Linting
1 parent 90ff4c0 commit 6ea0f05

13 files changed

+440
-260
lines changed
 

‎package-lock.json

+98
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
"main": "dist/index.js",
66
"scripts": {
77
"build": "rimraf ./dist ./types && tsc -p ./src",
8-
"test": "jest",
8+
"test": "npm run lint && jest",
99
"test:coverage": "jest --coverage",
10+
"lint": "tslint -p src && tslint -p tests",
1011
"prepush": "npm test"
1112
},
1213
"repository": {
@@ -67,6 +68,8 @@
6768
"jest": "^22.2.2",
6869
"rimraf": "^2.6.2",
6970
"ts-jest": "^22.0.4",
71+
"tslint": "^5.9.1",
72+
"tslint-eslint-rules": "^5.0.0",
7073
"typescript": "^2.6.1"
7174
}
7275
}

‎src/decorators.ts

+24-24
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import "reflect-metadata";
22

3-
import {instance as globalContainer, typeInfo} from "./dependency-container";
4-
import { InjectionToken, Provider } from "./providers";
5-
import { constructor, RegistrationOptions } from "./types";
63
import {INJECTION_TOKEN_METADATA_KEY, getParamInfo} from "./reflection-helpers";
4+
import {InjectionToken, Provider} from "./providers";
5+
import {RegistrationOptions, constructor} from "./types";
6+
import {instance as globalContainer, typeInfo} from "./dependency-container";
77

88
/**
99
* Class decorator factory that allows the class' dependencies to be injected
@@ -12,9 +12,9 @@ import {INJECTION_TOKEN_METADATA_KEY, getParamInfo} from "./reflection-helpers";
1212
* @return {Function} The class decorator
1313
*/
1414
export function injectable<T>(): (target: constructor<T>) => void {
15-
return function(target: constructor<T>): void {
16-
typeInfo.set(target, getParamInfo(target));
17-
};
15+
return function(target: constructor<T>): void {
16+
typeInfo.set(target, getParamInfo(target));
17+
};
1818
}
1919

2020
/**
@@ -26,15 +26,15 @@ export function injectable<T>(): (target: constructor<T>) => void {
2626
* @return {Function} The class decorator
2727
*/
2828
export function autoInjectable(): (target: constructor<any>) => any {
29-
return function(target: constructor<any>): constructor<any> {
30-
const paramInfo = getParamInfo(target);
29+
return function(target: constructor<any>): constructor<any> {
30+
const paramInfo = getParamInfo(target);
3131

32-
return class extends target {
33-
constructor(...args: any[]) {
34-
super(...args.concat(paramInfo.slice(args.length).map(type => globalContainer.resolve(type))));
35-
}
36-
}
37-
}
32+
return class extends target {
33+
constructor(...args: any[]) {
34+
super(...args.concat(paramInfo.slice(args.length).map(type => globalContainer.resolve(type))));
35+
}
36+
};
37+
};
3838
}
3939

4040
/**
@@ -43,22 +43,22 @@ export function autoInjectable(): (target: constructor<any>) => any {
4343
* @return {Function} The parameter decorator
4444
*/
4545
export function inject(token: InjectionToken<any>): (target: any, propertyKey: string | symbol, parameterIndex: number) => any {
46-
return function(target: any, _propertyKey: string | symbol, parameterIndex: number): any {
47-
const injectionTokens = Reflect.getOwnMetadata(INJECTION_TOKEN_METADATA_KEY, target) || {};
48-
injectionTokens[parameterIndex] = token;
49-
Reflect.defineMetadata(INJECTION_TOKEN_METADATA_KEY, injectionTokens, target);
50-
};
46+
return function(target: any, _propertyKey: string | symbol, parameterIndex: number): any {
47+
const injectionTokens = Reflect.getOwnMetadata(INJECTION_TOKEN_METADATA_KEY, target) || {};
48+
injectionTokens[parameterIndex] = token;
49+
Reflect.defineMetadata(INJECTION_TOKEN_METADATA_KEY, injectionTokens, target);
50+
};
5151
}
5252

5353
/**
5454
* Class decorator factory that allows constructor dependencies to be registered at runtime.
5555
*
5656
* @return {Function} The class decorator
5757
*/
58-
export function registry(registrations: ({token: InjectionToken, options?: RegistrationOptions} & Provider<any>)[] = []): (target: any) => any {
59-
return function(target: any): any {
60-
registrations.forEach(({token, options, ...provider}) => globalContainer.register(token, <any>provider, options));
58+
export function registry(registrations: ({ token: InjectionToken, options?: RegistrationOptions } & Provider<any>)[] = []): (target: any) => any {
59+
return function(target: any): any {
60+
registrations.forEach(({token, options, ...provider}) => globalContainer.register(token, <any>provider, options));
6161

62-
return target;
63-
};
62+
return target;
63+
};
6464
}

0 commit comments

Comments
 (0)