Skip to content

Commit 2cc464a

Browse files
authored
Merge pull request #14 from abraham/tslint
Add tslint
2 parents a9f714c + 151da14 commit 2cc464a

File tree

3 files changed

+54
-13
lines changed

3 files changed

+54
-13
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
"scripts": {
99
"build": "tsc && rollup -c",
1010
"clean": "rimraf dist",
11+
"lint": "tslint --project tsconfig.json",
1112
"prebuild": "npm run clean",
1213
"prepare": "npm run build",
1314
"prepublishOnly": "pkg-ok",
1415
"start": "jest --watch",
15-
"test": "jest"
16+
"test": "jest && npm run lint"
1617
},
1718
"repository": {
1819
"type": "git",
@@ -40,6 +41,7 @@
4041
"rimraf": "2.6.2",
4142
"rollup": "0.63.4",
4243
"ts-jest": "23.0.1",
44+
"tslint": "5.11.0",
4345
"typescript": "2.9.2"
4446
},
4547
"jest": {

src/index.ts

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,32 @@ export const Reflection = Object.assign(Reflect, {
88
});
99

1010
export type Decorator = ClassDecorator | MemberDecorator;
11-
export type MemberDecorator = <T>(target: Target, propertyKey: PropertyKey, descriptor?: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T> | void;
11+
export type MemberDecorator = <T>(target: Target,
12+
propertyKey: PropertyKey,
13+
descriptor?: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T> | void;
1214
export type MetadataKey = string;
1315
export type MetadataValue = Function;
1416
export type PropertyKey = string | symbol;
1517
export type Target = object | Function;
1618

1719
const Metadata = new WeakMap();
1820

19-
export function defineMetadata(metadataKey: MetadataKey, metadataValue: MetadataValue, target: Target, propertyKey?: PropertyKey) {
21+
export function defineMetadata(metadataKey: MetadataKey,
22+
metadataValue: MetadataValue,
23+
target: Target, propertyKey?: PropertyKey) {
2024
return ordinaryDefineOwnMetadata(metadataKey, metadataValue, target, propertyKey);
2125
}
2226

23-
export function decorate(decorators: ClassDecorator[], target: Function): Function
24-
export function decorate(decorators: MemberDecorator[], target: object, propertyKey?: PropertyKey, attributes?: PropertyDescriptor): PropertyDescriptor | undefined
25-
export function decorate(decorators: Decorator[], target: Target, propertyKey?: PropertyKey, attributes?: PropertyDescriptor): Function | PropertyDescriptor | undefined {
26-
if (decorators.length === 0) throw new TypeError();
27+
export function decorate(decorators: ClassDecorator[], target: Function): Function;
28+
export function decorate(decorators: MemberDecorator[],
29+
target: object,
30+
propertyKey?: PropertyKey,
31+
attributes?: PropertyDescriptor): PropertyDescriptor | undefined;
32+
export function decorate(decorators: Decorator[],
33+
target: Target,
34+
propertyKey?: PropertyKey,
35+
attributes?: PropertyDescriptor): Function | PropertyDescriptor | undefined {
36+
if (decorators.length === 0) { throw new TypeError(); }
2737

2838
if (typeof target === 'function') {
2939
return decorateConstructor(decorators as ClassDecorator[], target);
@@ -61,30 +71,40 @@ function decorateConstructor(decorators: ClassDecorator[], target: Function): Fu
6171
return target;
6272
}
6373

64-
function decorateProperty(decorators: MemberDecorator[], target: Target, propertyKey: PropertyKey, descriptor?: PropertyDescriptor): PropertyDescriptor | undefined {
74+
function decorateProperty(decorators: MemberDecorator[],
75+
target: Target,
76+
propertyKey: PropertyKey,
77+
descriptor?: PropertyDescriptor): PropertyDescriptor | undefined {
6578
decorators.reverse().forEach((decorator: MemberDecorator) => {
6679
descriptor = decorator(target, propertyKey, descriptor) || descriptor;
6780
});
6881
return descriptor;
6982
}
7083

71-
function ordinaryDefineOwnMetadata(metadataKey: MetadataKey, metadataValue: MetadataValue, target: Target, propertyKey?: PropertyKey): void {
72-
if (propertyKey && !['string', 'symbol'].includes(typeof propertyKey)) throw new TypeError();
84+
function ordinaryDefineOwnMetadata(metadataKey: MetadataKey,
85+
metadataValue: MetadataValue,
86+
target: Target,
87+
propertyKey?: PropertyKey): void {
88+
if (propertyKey && !['string', 'symbol'].includes(typeof propertyKey)) { throw new TypeError(); }
7389

7490
(getMetadataMap(target, propertyKey) || createMetadataMap(target, propertyKey))
7591
.set(metadataKey, metadataValue);
7692
}
7793

78-
function ordinaryGetMetadata(metadataKey: MetadataKey, target: Target, propertyKey?: PropertyKey): Function | undefined {
94+
function ordinaryGetMetadata(metadataKey: MetadataKey,
95+
target: Target,
96+
propertyKey?: PropertyKey): Function | undefined {
7997
return !!ordinaryGetOwnMetadata(metadataKey, target, propertyKey)
8098
? ordinaryGetOwnMetadata(metadataKey, target, propertyKey)
8199
: Object.getPrototypeOf(target)
82100
? ordinaryGetMetadata(metadataKey, Object.getPrototypeOf(target), propertyKey)
83101
: undefined;
84102
}
85103

86-
function ordinaryGetOwnMetadata(metadataKey: MetadataKey, target: Target, propertyKey?: PropertyKey): Function | undefined {
87-
if (target === undefined) throw new TypeError();
104+
function ordinaryGetOwnMetadata(metadataKey: MetadataKey,
105+
target: Target,
106+
propertyKey?: PropertyKey): Function | undefined {
107+
if (target === undefined) { throw new TypeError(); }
88108
const metadataMap = getMetadataMap(target, propertyKey);
89109
return metadataMap && metadataMap.get(metadataKey);
90110
}

tslint.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"defaultSeverity": "error",
3+
"extends": [
4+
"tslint:recommended"
5+
],
6+
"jsRules": {},
7+
"rules": {
8+
"quotemark": [true, "single"],
9+
"ban-types": [
10+
true,
11+
["Object", "Avoid using the `Object` type. Did you mean `object`?"],
12+
["Boolean", "Avoid using the `Boolean` type. Did you mean `boolean`?"],
13+
["Number", "Avoid using the `Number` type. Did you mean `number`?"],
14+
["String", "Avoid using the `String` type. Did you mean `string`?"],
15+
["Symbol", "Avoid using the `Symbol` type. Did you mean `symbol`?"]
16+
]
17+
},
18+
"rulesDirectory": []
19+
}

0 commit comments

Comments
 (0)