Skip to content

Commit ba0e10d

Browse files
Gerrit0mrkurt
authored andcommitted
Stricter lint config (TypeStrong#840)
* Enable no-unnecessary-type-assertion Also turns on strictFunctionTypes, which required an update to the `ComponentClass` interface.
1 parent 7a30a84 commit ba0e10d

File tree

21 files changed

+53
-60
lines changed

21 files changed

+53
-60
lines changed

.travis.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,8 @@ before_install: >
1414
npm install --global npm@^4
1515
else
1616
npm install --global npm@latest
17-
fi
17+
fi
18+
19+
script:
20+
- npm test
21+
- npm run lint

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
"scripts": {
7777
"test": "grunt test",
7878
"build": "grunt build_and_test",
79+
"lint": "tslint --project .",
7980
"prepublishOnly": "grunt build_and_test",
8081
"prepare": "grunt default",
8182
"grunt": "grunt",

src/lib/converter/nodes/block.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class BlockConverter extends ConverterNodeComponent<ts.SourceFile|ts.Bloc
4949
*/
5050
convert(context: Context, node: ts.SourceFile|ts.Block|ts.ModuleBlock): Reflection {
5151
if (node.kind === ts.SyntaxKind.SourceFile) {
52-
this.convertSourceFile(context, <ts.SourceFile> node);
52+
this.convertSourceFile(context, node);
5353
} else {
5454
this.convertStatements(context, node);
5555
}

src/lib/converter/nodes/export.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ export class ExportConverter extends ConverterNodeComponent<ts.ExportAssignment>
3636

3737
const reflection = project.reflections[id];
3838
if (node.isExportEquals && reflection instanceof DeclarationReflection) {
39-
(<DeclarationReflection> reflection).setFlag(ReflectionFlag.ExportAssignment, true);
39+
reflection.setFlag(ReflectionFlag.ExportAssignment, true);
4040
}
4141
markAsExported(reflection);
4242
});
4343
}
4444

4545
function markAsExported(reflection: Reflection) {
4646
if (reflection instanceof DeclarationReflection) {
47-
(<DeclarationReflection> reflection).setFlag(ReflectionFlag.Exported, true);
47+
reflection.setFlag(ReflectionFlag.Exported, true);
4848
}
4949

5050
reflection.traverse(markAsExported);

src/lib/converter/nodes/signature-call.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class SignatureConverter extends ConverterNodeComponent<ts.FunctionExpres
2828
const scope = <DeclarationReflection> context.scope;
2929
if (scope instanceof DeclarationReflection) {
3030
const name = scope.kindOf(ReflectionKind.FunctionOrMethod) ? scope.name : '__call';
31-
const signature = createSignature(context, <ts.SignatureDeclaration> node, name, ReflectionKind.CallSignature);
31+
const signature = createSignature(context, node, name, ReflectionKind.CallSignature);
3232
if (!scope.signatures) {
3333
scope.signatures = [];
3434
}

src/lib/converter/nodes/variable-statement.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class VariableStatementConverter extends ConverterNodeComponent<ts.Variab
2525
if (node.declarationList && node.declarationList.declarations) {
2626
node.declarationList.declarations.forEach((variableDeclaration) => {
2727
if (_ts.isBindingPattern(variableDeclaration.name)) {
28-
this.convertBindingPattern(context, <ts.BindingPattern> variableDeclaration.name);
28+
this.convertBindingPattern(context, variableDeclaration.name);
2929
} else {
3030
this.owner.convertNode(context, variableDeclaration);
3131
}
@@ -46,7 +46,7 @@ export class VariableStatementConverter extends ConverterNodeComponent<ts.Variab
4646
this.owner.convertNode(context, element);
4747

4848
if (_ts.isBindingPattern(element.name)) {
49-
this.convertBindingPattern(context, <ts.BindingPattern> element.name);
49+
this.convertBindingPattern(context, element.name);
5050
}
5151
});
5252
}

src/lib/converter/plugins/CategoryPlugin.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,12 @@ export class CategoryPlugin extends ConverterComponent {
3636
*/
3737
private onResolve(context: Context, reflection: Reflection) {
3838
if (reflection instanceof ContainerReflection) {
39-
const container = <ContainerReflection> reflection;
40-
if (container.children && container.children.length > 0) {
41-
container.children.sort(GroupPlugin.sortCallback);
42-
container.categories = CategoryPlugin.getReflectionCategories(container.children);
39+
if (reflection.children && reflection.children.length > 0) {
40+
reflection.children.sort(GroupPlugin.sortCallback);
41+
reflection.categories = CategoryPlugin.getReflectionCategories(reflection.children);
4342
}
44-
if (container.categories && container.categories.length > 1) {
45-
container.categories.sort(CategoryPlugin.sortCatCallback);
43+
if (reflection.categories && reflection.categories.length > 1) {
44+
reflection.categories.sort(CategoryPlugin.sortCatCallback);
4645
}
4746
}
4847
}

src/lib/converter/plugins/GroupPlugin.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,9 @@ export class GroupPlugin extends ConverterComponent {
8787
reflection.kindString = GroupPlugin.getKindSingular(reflection.kind);
8888

8989
if (reflection instanceof ContainerReflection) {
90-
const container = <ContainerReflection> reflection;
91-
if (container.children && container.children.length > 0) {
92-
container.children.sort(GroupPlugin.sortCallback);
93-
container.groups = GroupPlugin.getReflectionGroups(container.children);
90+
if (reflection.children && reflection.children.length > 0) {
91+
reflection.children.sort(GroupPlugin.sortCallback);
92+
reflection.groups = GroupPlugin.getReflectionGroups(reflection.children);
9493
}
9594
}
9695
}

src/lib/converter/plugins/ImplementsPlugin.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,8 @@ export class ImplementsPlugin extends ConverterComponent {
109109
return;
110110
}
111111

112-
const source = <DeclarationReflection> (<ReferenceType> type).reflection;
113-
if (source && source.kindOf(ReflectionKind.Interface)) {
114-
this.analyzeClass(context, reflection, source);
112+
if (type.reflection && type.reflection.kindOf(ReflectionKind.Interface)) {
113+
this.analyzeClass(context, reflection, <DeclarationReflection> type.reflection);
115114
}
116115
});
117116
}

src/lib/converter/plugins/TypePlugin.ts

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ export class TypePlugin extends ConverterComponent {
6969
if (!types) {
7070
return;
7171
}
72-
types.forEach((type: ReferenceType) => {
72+
types.forEach(type => {
7373
if (!(type instanceof ReferenceType)) {
7474
return;
7575
}
7676
if (!type.reflection || !(type.reflection instanceof DeclarationReflection)) {
7777
return;
7878
}
79-
callback(<DeclarationReflection> type.reflection);
79+
callback(type.reflection);
8080
});
8181
}
8282

@@ -91,28 +91,19 @@ export class TypePlugin extends ConverterComponent {
9191

9292
function resolveType(reflection: Reflection, type: Type) {
9393
if (type instanceof ReferenceType) {
94-
const referenceType: ReferenceType = <ReferenceType> type;
95-
if (referenceType.symbolID === ReferenceType.SYMBOL_ID_RESOLVE_BY_NAME) {
96-
referenceType.reflection = reflection.findReflectionByName(referenceType.name);
97-
} else if (!referenceType.reflection && referenceType.symbolID !== ReferenceType.SYMBOL_ID_RESOLVED) {
98-
referenceType.reflection = project.reflections[project.symbolMapping[referenceType.symbolID]];
94+
if (type.symbolID === ReferenceType.SYMBOL_ID_RESOLVE_BY_NAME) {
95+
type.reflection = reflection.findReflectionByName(type.name);
96+
} else if (!type.reflection && type.symbolID !== ReferenceType.SYMBOL_ID_RESOLVED) {
97+
type.reflection = project.reflections[project.symbolMapping[type.symbolID]];
9998
}
10099

101-
if (referenceType.typeArguments) {
102-
referenceType.typeArguments.forEach((typeArgument: Type) => {
103-
resolveType(reflection, typeArgument);
104-
});
100+
if (type.typeArguments) {
101+
resolveTypes(reflection, type.typeArguments);
105102
}
106103
} else if (type instanceof TupleType) {
107-
const tupleType: TupleType = <TupleType> type;
108-
for (let index = 0, count = tupleType.elements.length; index < count; index++) {
109-
resolveType(reflection, tupleType.elements[index]);
110-
}
104+
resolveTypes(reflection, type.elements);
111105
} else if (type instanceof UnionType || type instanceof IntersectionType) {
112-
const unionOrIntersectionType: UnionType | IntersectionType = <UnionType | IntersectionType> type;
113-
for (let index = 0, count = unionOrIntersectionType.types.length; index < count; index++) {
114-
resolveType(reflection, unionOrIntersectionType.types[index]);
115-
}
106+
resolveTypes(reflection, type.types);
116107
} else if (type instanceof ArrayType) {
117108
resolveType(reflection, type.elementType);
118109
}

0 commit comments

Comments
 (0)