type-coverage-core
Advanced tools
Comparing version 2.13.3 to 2.14.0
@@ -7,3 +7,3 @@ "use strict"; | ||
function collectAny(node, context, kind) { | ||
const { file, sourceFile, typeCheckResult, ingoreMap, debug, processAny } = context; | ||
const { file, sourceFile, typeCheckResult, ingoreMap, ignoreUnreadAnys, debug, processAny } = context; | ||
if (processAny !== undefined) { | ||
@@ -16,2 +16,8 @@ return processAny(node, context); | ||
} | ||
if (ignoreUnreadAnys && isEvolvingAssignment(node)) { | ||
if (debug) { | ||
console.log(`Ignoring assignment to implicit any type: ${file}:${line + 1}:${character + 1}: ${node.parent.getText(sourceFile)}`); | ||
} | ||
return false; | ||
} | ||
if (debug) { | ||
@@ -68,2 +74,15 @@ console.log(`type === any(${kind}): ${file}:${line + 1}:${character + 1}: ${node.getText(sourceFile)}`); | ||
} | ||
// See https://github.com/plantain-00/type-coverage/issues/28 | ||
function isEvolvingAssignment(node) { | ||
const { parent } = node; | ||
if (typescript_1.default.isVariableDeclaration(parent)) { | ||
// Match "let foo" and "let foo = null" but not "let foo: any". | ||
return !parent.type; | ||
} | ||
if (typescript_1.default.isBinaryExpression(parent)) { | ||
// Match "foo = 123". | ||
return parent.operatorToken.kind === typescript_1.default.SyntaxKind.EqualsToken; | ||
} | ||
return false; | ||
} | ||
function checkNodes(nodes, context) { | ||
@@ -70,0 +89,0 @@ if (nodes === undefined) { |
@@ -87,2 +87,3 @@ "use strict"; | ||
ignoreCatch: lintOptions.ignoreCatch, | ||
ignoreUnreadAnys: lintOptions.ignoreUnreadAnys, | ||
catchVariables: {}, | ||
@@ -137,2 +138,3 @@ debug: lintOptions.debug, | ||
ignoreFiles: undefined, | ||
ignoreUnreadAnys: false, | ||
fileCounts: false, | ||
@@ -188,2 +190,3 @@ }; | ||
ignoreCatch: lintOptions.ignoreCatch, | ||
ignoreUnreadAnys: lintOptions.ignoreUnreadAnys, | ||
catchVariables: {}, | ||
@@ -190,0 +193,0 @@ debug: lintOptions.debug, |
@@ -41,2 +41,3 @@ import ts from 'typescript'; | ||
ignoreFiles?: string | string[]; | ||
ignoreUnreadAnys: boolean; | ||
fileCounts: boolean; | ||
@@ -54,2 +55,3 @@ absolutePath?: boolean; | ||
ignoreCatch: boolean; | ||
ignoreUnreadAnys: boolean; | ||
catchVariables: { | ||
@@ -56,0 +58,0 @@ [variable: string]: boolean; |
{ | ||
"name": "type-coverage-core", | ||
"version": "2.13.3", | ||
"version": "2.14.0", | ||
"description": "A library to check type coverage for typescript code", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
50991
1283