Skip to content

Commit 4141432

Browse files
committed
Add tslint and fix linting errors
1 parent 00e588d commit 4141432

File tree

28 files changed

+1120
-1014
lines changed

28 files changed

+1120
-1014
lines changed

.travis.yml

+3
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ language: node_js
22
node_js:
33
- "4.1"
44
- "4.0"
5+
script:
6+
- npm run lint
7+
- npm run test

package.json

+10-6
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
"type": "git",
1717
"url": "[email protected]:YousefED/typescript-json-schema.git"
1818
},
19-
"licenses": [{
20-
"type": "Apache",
21-
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
22-
}],
19+
"licenses": [
20+
{
21+
"type": "Apache",
22+
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
23+
}
24+
],
2325
"optionalDependencies": {},
2426
"keywords": [
2527
"typescript",
@@ -36,10 +38,12 @@
3638
"devDependencies": {
3739
"chai": "^3.5.0",
3840
"mocha": "^2.4.5",
39-
"source-map-support": "^0.4.0"
41+
"source-map-support": "^0.4.0",
42+
"tslint": "^3.15.1"
4043
},
4144
"scripts": {
4245
"test": "npm run build && mocha -t 5000 --require source-map-support/register test",
43-
"build": "tsc -p ."
46+
"build": "tsc -p .",
47+
"lint": "tslint -c tslint.json 'typescript-json-schema.ts' 'test/**/*.ts' --exclude '**/*.d.ts'"
4448
}
4549
}

test/programs/array-and-description/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ export interface MyObject {
55
name?: string;
66
description?: string;
77
test: any[];
8-
}
8+
}

test/programs/array-types/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
interface MyArray {
22
[index: number]: string | number;
3-
}
3+
}

test/programs/comments-override/main.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
* @additionalProperties true
55
*/
66
export interface MySubObject {
7-
value : string;
7+
value: string;
88
}
99

1010
export interface MyObject {
11-
list : MySubObject[];
12-
13-
sub1 : MySubObject;
11+
list: MySubObject[];
12+
13+
sub1: MySubObject;
1414

1515
/**
1616
* Property-level description
1717
* @additionalProperties false
1818
*/
19-
sub2 : MySubObject;
20-
}
19+
sub2: MySubObject;
20+
}

test/programs/comments/main.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ interface MyObject {
2323
* @minimum 0
2424
* @maximum 100
2525
*/
26-
opacity : number;
27-
26+
opacity: number;
27+
2828
/**
2929
* Description of field position, of aliased type Vector3D, which should inherit its annotations
3030
*/
31-
position : Vector3D;
32-
31+
position: Vector3D;
32+
3333
/**
3434
* Description of rotation, a field with an anonymous type
3535
*/
@@ -40,7 +40,5 @@ interface MyObject {
4040
* @maximum 90
4141
*/
4242
yaw: number;
43-
}
44-
43+
};
4544
}
46-

test/programs/enums-mixed/main.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
enum Enum {
22
A, // = 0
3-
B = 1,
4-
C = true as any,
5-
D = 'str' as any,
3+
B = 1,
4+
C = true as any,
5+
D = "str" as any,
66
E = null
77
}
88

99
interface MyObject {
10-
foo: Enum
10+
foo: Enum;
1111
}

test/programs/enums-number/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ enum Enum {
44
}
55

66
interface MyObject {
7-
foo: Enum
7+
foo: Enum;
88
}

test/programs/enums-string/main.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
enum Enum {
2-
X = 'x' as any,
3-
Y = 'y' as any
2+
X = "x" as any,
3+
Y = "y" as any
44
}
55

66
interface MyObject {
7-
foo: Enum
7+
foo: Enum;
88
}

test/programs/map-types/main.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
interface MyType {}
33

44
interface MyMap1 {
5-
[id : string] : MyType;
5+
[id: string]: MyType;
66
}
77

88
/**
99
* The additionalProperties annotation should be ignored
1010
* @additionalProperties false
1111
*/
1212
interface MyMap2 {
13-
[id : string] : (string | number);
13+
[id: string]: (string | number);
1414
}
1515

1616
interface MyObject {
17-
map1 : MyMap1;
18-
map2 : MyMap2;
19-
}
17+
map1: MyMap1;
18+
map2: MyMap2;
19+
}

test/programs/namespace/main.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export namespace Types {
2-
export const X: 'x' = 'x';
3-
export const Y: 'y' = 'y';
2+
export const X: "x" = "x";
3+
export const Y: "y" = "y";
44
}
55

66
export type Type = typeof Types.X | typeof Types.Y;
+7-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
1+
22
class MyObject {
33
val: number;
4-
val_nullable: number | null;
5-
val_undef: number | undefined;
6-
val_opt?: number;
4+
valNullable: number | null;
5+
valUndef: number | undefined;
6+
valOpt?: number;
77

8-
val_true_opt?: true;
9-
val_true_or_null: true|null;
10-
val_true: true|true; // twice to check that it will appear only once
8+
valTrueOpt?: true;
9+
valTrueOrNull: true|null;
10+
valTrue: true|true; // twice to check that it will appear only once
1111
}

test/programs/strict-null-checks/schema.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,27 @@
44
"val": {
55
"type": "number"
66
},
7-
"val_nullable": {
7+
"valNullable": {
88
"type": [
99
"null",
1010
"number"
1111
]
1212
},
13-
"val_undef": {
13+
"valUndef": {
1414
"type": "number"
1515
},
16-
"val_opt": {
16+
"valOpt": {
1717
"type": "number"
1818
},
19-
"val_true": {
19+
"valTrue": {
2020
"enum": [ true ],
2121
"type": "boolean"
2222
},
23-
"val_true_opt": {
23+
"valTrueOpt": {
2424
"enum": [ true ],
2525
"type": "boolean"
2626
},
27-
"val_true_or_null": {
27+
"valTrueOrNull": {
2828
"anyOf": [
2929
{ "enum": [ true ], "type": "boolean" },
3030
{ "type": "null" }
@@ -33,9 +33,9 @@
3333
},
3434
"required": [
3535
"val",
36-
"val_nullable",
37-
"val_true_or_null",
38-
"val_true"
36+
"valNullable",
37+
"valTrueOrNull",
38+
"valTrue"
3939
],
4040
"$schema": "http://json-schema.org/draft-04/schema#"
4141
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
class MyObject {
2-
foo: "ok" | "fail" | "abort"
3-
}
2+
foo: "ok" | "fail" | "abort";
3+
}

test/programs/string-literals/main.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
type result = "ok" | "fail" | "abort";
22

33
class MyObject {
4-
foo: result
5-
}
4+
foo: result;
5+
}

test/programs/type-aliases-multitype-array/main.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11

22
type BasicArray = (string | number)[];
33

4-
interface MyObject
5-
{
4+
interface MyObject {
65
array: BasicArray;
76
}
87

test/programs/type-aliases/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
type MyString = string;
1+
type MyString = string;

test/programs/type-anonymous/main.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
FieldWithAnonType: {
33
SubfieldA: number;
44
SubfieldB: (string | number);
5-
SubfieldC : {
5+
SubfieldC: {
66
SubsubfieldA: number[];
77
}
8-
}
9-
}
8+
};
9+
}

test/programs/type-intersection/main.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ interface Type2 {
55
value2: number;
66
}
77

8-
interface MyObject
9-
{
8+
interface MyObject {
109
value: Type1 & Type2;
11-
}
10+
}

test/programs/type-nullable/main.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@ type Ref = { foo: number };
1717
type MyType5 = Ref;
1818

1919

20-
interface MyObject
21-
{
22-
var1 : MyType1;
23-
var2 : MyType2;
24-
var3 : MyType3;
25-
var4 : MyType4;
26-
var5 : MyType5;
20+
interface MyObject {
21+
var1: MyType1;
22+
var2: MyType2;
23+
var3: MyType3;
24+
var4: MyType4;
25+
var5: MyType5;
2726
}

test/programs/type-primitives/main.ts

+22-23
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
1-
2-
// Special type, should not appear in the schema
3-
type integer = number;
4-
5-
class MyObject {
6-
7-
boolean1: boolean = true;
8-
9-
number1: number = 1;
10-
11-
/** @type integer */
12-
integer1: number = 1;
13-
integer2: integer = 1;
14-
15-
string1: string = "defaultValue";
16-
17-
array1: Array<any> = null;
18-
array2: Array<number> = null;
19-
20-
object1: any = null;
21-
object2: {} = null;
22-
23-
}
1+
// Special type, should not appear in the schema
2+
type integer = number;
3+
4+
class MyObject {
5+
6+
boolean1: boolean = true;
7+
8+
number1: number = 1;
9+
10+
/** @type integer */
11+
integer1: number = 1;
12+
integer2: integer = 1;
13+
14+
string1: string = "defaultValue";
15+
16+
array1: Array<any> = null;
17+
array2: Array<number> = null;
18+
19+
object1: any = null;
20+
object2: {} = null;
21+
22+
}

test/programs/type-union/main.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ type MyType1 = string | number;
55
// Non-simple union (generates a "oneOf"/"anyOf")
66
type MyType2 = string | number[];
77

8-
interface MyObject
9-
{
10-
var1 : MyType1;
11-
var2 : MyType2;
8+
interface MyObject {
9+
var1: MyType1;
10+
var2: MyType2;
1211
}

0 commit comments

Comments
 (0)