@fimbul/mimir
Advanced tools
Comparing version 0.20.0-dev.20190201 to 0.20.0-dev.20190203
{ | ||
"name": "@fimbul/mimir", | ||
"version": "0.20.0-dev.20190201", | ||
"version": "0.20.0-dev.20190203", | ||
"description": "Core rules of the Fimbullinter project", | ||
@@ -5,0 +5,0 @@ "main": "recommended.yaml", |
@@ -9,3 +9,4 @@ import { TypedRule } from '@fimbul/ymir'; | ||
private checkTypeAssertion; | ||
private reportUselessTypeAssertion; | ||
private getSafeContextualType; | ||
} |
@@ -68,6 +68,9 @@ "use strict"; | ||
checkTypeAssertion(node) { | ||
if (tsutils_1.isConstAssertion(node)) | ||
if (tsutils_1.isConstAssertion(node)) { | ||
if (tsutils_1.isInConstContext(node)) | ||
this.reportUselessTypeAssertion(node, 'This assertion is unnecessary as it is already in a const context.'); | ||
return; | ||
} | ||
let targetType = this.checker.getTypeFromTypeNode(node.type); | ||
if (targetType.flags & ts.TypeFlags.Literal || | ||
if ((targetType.flags & ts.TypeFlags.Literal) !== 0 && !tsutils_1.isInConstContext(node) || | ||
tsutils_1.isObjectType(targetType) && (targetType.objectFlags & ts.ObjectFlags.Tuple || couldBeTupleType(targetType))) | ||
@@ -91,2 +94,5 @@ return; | ||
} | ||
this.reportUselessTypeAssertion(node, message); | ||
} | ||
reportUselessTypeAssertion(node, message) { | ||
if (node.kind === ts.SyntaxKind.AsExpression) { | ||
@@ -93,0 +99,0 @@ this.addFinding(node.type.pos - 'as'.length, node.end, message, ymir_1.Replacement.delete(node.expression.end, node.end)); |
Sorry, the diff of this file is not supported yet
401093
4729