Socket
Socket
Sign inDemoInstall

type-coverage

Package Overview
Dependencies
Maintainers
1
Versions
131
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.9.1 to 1.10.0

dist/interfaces.d.ts

10

dist/core.d.ts
import ts from 'typescript';
export declare function lint(project: string, detail: boolean, debug: boolean, files?: string[], oldProgram?: ts.Program, strict?: boolean): Promise<{
import { AnyInfo } from './interfaces';
export declare function lint(project: string, detail: boolean, debug: boolean, files?: string[], oldProgram?: ts.Program, strict?: boolean, enableCache?: boolean): Promise<{
correctCount: number;
totalCount: number;
anys: {
file: string;
line: number;
character: number;
text: string;
}[];
anys: AnyInfo[];
program: ts.Program;
}>;

@@ -7,5 +7,11 @@ "use strict";

const utils = tslib_1.__importStar(require("tsutils/util"));
const fs = tslib_1.__importStar(require("fs"));
const util_1 = require("util");
const crypto = tslib_1.__importStar(require("crypto"));
const tsconfig_1 = require("./tsconfig");
const readFileAsync = util_1.promisify(fs.readFile);
const writeFileAsync = util_1.promisify(fs.writeFile);
const mkdirAsync = util_1.promisify(fs.mkdir);
// tslint:disable-next-line:no-big-function cognitive-complexity
async function lint(project, detail, debug, files, oldProgram, strict = false) {
async function lint(project, detail, debug, files, oldProgram, strict = false, enableCache = false) {
const { configFilePath, dirname } = tsconfig_1.getTsConfigFilePath(project);

@@ -20,7 +26,4 @@ const config = tsconfig_1.getTsConfig(configFilePath, dirname);

const checker = program.getTypeChecker();
let correctCount = 0;
let totalCount = 0;
let anys = [];
const ingoreMap = {};
function collectAny(node, file, sourceFile, type) {
function collectAny(node, { file, sourceFile, typeCheckResult }) {
const { line, character } = typescript_1.default.getLineAndCharacterOfPosition(sourceFile, node.getStart(sourceFile));

@@ -34,8 +37,8 @@ if (ingoreMap[file] && ingoreMap[file].has(line)) {

else if (detail) {
anys.push({ file, line, character, text: node.getText(sourceFile) });
typeCheckResult.anys.push({ file, line, character, text: node.getText(sourceFile) });
}
return true;
}
function collectNotAny(node, file, sourceFile, type) {
correctCount++;
function collectNotAny(node, { file, sourceFile, typeCheckResult }, type) {
typeCheckResult.correctCount++;
if (debug) {

@@ -46,18 +49,18 @@ const { line, character } = typescript_1.default.getLineAndCharacterOfPosition(sourceFile, node.getStart(sourceFile));

}
function collectData(node, file, sourceFile) {
function collectData(node, context) {
const type = checker.getTypeAtLocation(node);
if (type) {
totalCount++;
context.typeCheckResult.totalCount++;
if (typeIsStrictAny(type, strict)) {
const success = collectAny(node, file, sourceFile, type);
const success = collectAny(node, context);
if (!success) {
collectNotAny(node, file, sourceFile, type);
collectNotAny(node, context, type);
}
}
else {
collectNotAny(node, file, sourceFile, type);
collectNotAny(node, context, type);
}
}
}
function handleNodes(nodes, file, sourceFile) {
function handleNodes(nodes, context) {
if (nodes === undefined) {

@@ -67,7 +70,7 @@ return;

for (const node of nodes) {
handleNode(node, file, sourceFile);
handleNode(node, context);
}
}
// tslint:disable-next-line:no-big-function
function handleNode(node, file, sourceFile) {
function handleNode(node, context) {
if (node === undefined) {

@@ -77,7 +80,7 @@ return;

if (debug) {
const { line, character } = typescript_1.default.getLineAndCharacterOfPosition(sourceFile, node.getStart(sourceFile));
console.log(`node: ${file}:${line + 1}:${character + 1}: ${node.getText(sourceFile)} ${node.kind}(kind)`);
const { line, character } = typescript_1.default.getLineAndCharacterOfPosition(context.sourceFile, node.getStart(context.sourceFile));
console.log(`node: ${context.file}:${line + 1}:${character + 1}: ${node.getText(context.sourceFile)} ${node.kind}(kind)`);
}
handleNodes(node.decorators, file, sourceFile);
handleNodes(node.modifiers, file, sourceFile);
handleNodes(node.decorators, context);
handleNodes(node.modifiers, context);
// tslint:disable-next-line:max-switch-cases

@@ -158,3 +161,3 @@ switch (node.kind) {

case typescript_1.default.SyntaxKind.Identifier:
collectData(node, file, sourceFile);
collectData(node, context);
break;

@@ -190,3 +193,3 @@ case typescript_1.default.SyntaxKind.BreakKeyword:

case typescript_1.default.SyntaxKind.ThisKeyword:
collectData(node, file, sourceFile);
collectData(node, context);
break;

@@ -242,49 +245,49 @@ case typescript_1.default.SyntaxKind.ThrowKeyword:

const qualifiedName = node;
handleNode(qualifiedName.left, file, sourceFile);
handleNode(qualifiedName.right, file, sourceFile);
handleNode(qualifiedName.left, context);
handleNode(qualifiedName.right, context);
break;
case typescript_1.default.SyntaxKind.ComputedPropertyName:
const computedPropertyName = node;
handleNode(computedPropertyName.expression, file, sourceFile);
handleNode(computedPropertyName.expression, context);
break;
case typescript_1.default.SyntaxKind.TypeParameter:
const typeParameterDeclaration = node;
handleNode(typeParameterDeclaration.name, file, sourceFile);
handleNode(typeParameterDeclaration.default, file, sourceFile);
handleNode(typeParameterDeclaration.expression, file, sourceFile);
handleNode(typeParameterDeclaration.constraint, file, sourceFile);
handleNode(typeParameterDeclaration.name, context);
handleNode(typeParameterDeclaration.default, context);
handleNode(typeParameterDeclaration.expression, context);
handleNode(typeParameterDeclaration.constraint, context);
break;
case typescript_1.default.SyntaxKind.Parameter:
const parameterDeclaration = node;
handleNode(parameterDeclaration.dotDotDotToken, file, sourceFile);
handleNode(parameterDeclaration.name, file, sourceFile);
handleNode(parameterDeclaration.initializer, file, sourceFile);
handleNode(parameterDeclaration.type, file, sourceFile);
handleNode(parameterDeclaration.questionToken, file, sourceFile);
handleNode(parameterDeclaration.dotDotDotToken, context);
handleNode(parameterDeclaration.name, context);
handleNode(parameterDeclaration.initializer, context);
handleNode(parameterDeclaration.type, context);
handleNode(parameterDeclaration.questionToken, context);
break;
case typescript_1.default.SyntaxKind.Decorator:
const decorator = node;
handleNode(decorator.expression, file, sourceFile);
handleNode(decorator.expression, context);
break;
case typescript_1.default.SyntaxKind.PropertySignature:
const propertySignature = node;
handleNode(propertySignature.name, file, sourceFile);
handleNode(propertySignature.questionToken, file, sourceFile);
handleNode(propertySignature.type, file, sourceFile);
handleNode(propertySignature.initializer, file, sourceFile);
handleNode(propertySignature.name, context);
handleNode(propertySignature.questionToken, context);
handleNode(propertySignature.type, context);
handleNode(propertySignature.initializer, context);
break;
case typescript_1.default.SyntaxKind.PropertyDeclaration:
const propertyDeclaration = node;
handleNode(propertyDeclaration.name, file, sourceFile);
handleNode(propertyDeclaration.initializer, file, sourceFile);
handleNode(propertyDeclaration.type, file, sourceFile);
handleNode(propertyDeclaration.questionToken, file, sourceFile);
handleNode(propertyDeclaration.name, context);
handleNode(propertyDeclaration.initializer, context);
handleNode(propertyDeclaration.type, context);
handleNode(propertyDeclaration.questionToken, context);
break;
case typescript_1.default.SyntaxKind.MethodSignature:
const methodSignature = node;
handleNode(methodSignature.name, file, sourceFile);
handleNodes(methodSignature.parameters, file, sourceFile);
handleNode(methodSignature.questionToken, file, sourceFile);
handleNode(methodSignature.type, file, sourceFile);
handleNodes(methodSignature.typeParameters, file, sourceFile);
handleNode(methodSignature.name, context);
handleNodes(methodSignature.parameters, context);
handleNode(methodSignature.questionToken, context);
handleNode(methodSignature.type, context);
handleNodes(methodSignature.typeParameters, context);
break;

@@ -296,43 +299,43 @@ case typescript_1.default.SyntaxKind.MethodDeclaration:

const functionLikeDeclarationBase = node;
handleNode(functionLikeDeclarationBase.name, file, sourceFile);
handleNodes(functionLikeDeclarationBase.parameters, file, sourceFile);
handleNode(functionLikeDeclarationBase.body, file, sourceFile);
handleNode(functionLikeDeclarationBase.asteriskToken, file, sourceFile);
handleNode(functionLikeDeclarationBase.questionToken, file, sourceFile);
handleNode(functionLikeDeclarationBase.type, file, sourceFile);
handleNodes(functionLikeDeclarationBase.typeParameters, file, sourceFile);
handleNode(functionLikeDeclarationBase.name, context);
handleNodes(functionLikeDeclarationBase.parameters, context);
handleNode(functionLikeDeclarationBase.body, context);
handleNode(functionLikeDeclarationBase.asteriskToken, context);
handleNode(functionLikeDeclarationBase.questionToken, context);
handleNode(functionLikeDeclarationBase.type, context);
handleNodes(functionLikeDeclarationBase.typeParameters, context);
break;
case typescript_1.default.SyntaxKind.CallSignature:
const callSignatureDeclaration = node;
handleNode(callSignatureDeclaration.name, file, sourceFile);
handleNodes(callSignatureDeclaration.parameters, file, sourceFile);
handleNode(callSignatureDeclaration.questionToken, file, sourceFile);
handleNode(callSignatureDeclaration.type, file, sourceFile);
handleNodes(callSignatureDeclaration.typeParameters, file, sourceFile);
handleNode(callSignatureDeclaration.name, context);
handleNodes(callSignatureDeclaration.parameters, context);
handleNode(callSignatureDeclaration.questionToken, context);
handleNode(callSignatureDeclaration.type, context);
handleNodes(callSignatureDeclaration.typeParameters, context);
break;
case typescript_1.default.SyntaxKind.ConstructSignature:
const constructSignatureDeclaration = node;
handleNode(constructSignatureDeclaration.name, file, sourceFile);
handleNodes(constructSignatureDeclaration.parameters, file, sourceFile);
handleNode(constructSignatureDeclaration.questionToken, file, sourceFile);
handleNode(constructSignatureDeclaration.type, file, sourceFile);
handleNodes(constructSignatureDeclaration.typeParameters, file, sourceFile);
handleNode(constructSignatureDeclaration.name, context);
handleNodes(constructSignatureDeclaration.parameters, context);
handleNode(constructSignatureDeclaration.questionToken, context);
handleNode(constructSignatureDeclaration.type, context);
handleNodes(constructSignatureDeclaration.typeParameters, context);
break;
case typescript_1.default.SyntaxKind.IndexSignature:
const indexSignatureDeclaration = node;
handleNode(indexSignatureDeclaration.name, file, sourceFile);
handleNodes(indexSignatureDeclaration.parameters, file, sourceFile);
handleNode(indexSignatureDeclaration.questionToken, file, sourceFile);
handleNode(indexSignatureDeclaration.type, file, sourceFile);
handleNodes(indexSignatureDeclaration.typeParameters, file, sourceFile);
handleNode(indexSignatureDeclaration.name, context);
handleNodes(indexSignatureDeclaration.parameters, context);
handleNode(indexSignatureDeclaration.questionToken, context);
handleNode(indexSignatureDeclaration.type, context);
handleNodes(indexSignatureDeclaration.typeParameters, context);
break;
case typescript_1.default.SyntaxKind.TypePredicate:
const typePredicateNode = node;
handleNode(typePredicateNode.type, file, sourceFile);
handleNode(typePredicateNode.parameterName, file, sourceFile);
handleNode(typePredicateNode.type, context);
handleNode(typePredicateNode.parameterName, context);
break;
case typescript_1.default.SyntaxKind.TypeReference:
const typeReferenceNode = node;
handleNode(typeReferenceNode.typeName, file, sourceFile);
handleNodes(typeReferenceNode.typeArguments, file, sourceFile);
handleNode(typeReferenceNode.typeName, context);
handleNodes(typeReferenceNode.typeArguments, context);
break;

@@ -342,22 +345,22 @@ case typescript_1.default.SyntaxKind.FunctionType:

const signatureDeclarationBase = node;
handleNode(signatureDeclarationBase.name, file, sourceFile);
handleNodes(signatureDeclarationBase.parameters, file, sourceFile);
handleNode(signatureDeclarationBase.type, file, sourceFile);
handleNodes(signatureDeclarationBase.typeParameters, file, sourceFile);
handleNode(signatureDeclarationBase.name, context);
handleNodes(signatureDeclarationBase.parameters, context);
handleNode(signatureDeclarationBase.type, context);
handleNodes(signatureDeclarationBase.typeParameters, context);
break;
case typescript_1.default.SyntaxKind.TypeQuery:
const typeQueryNode = node;
handleNode(typeQueryNode.exprName, file, sourceFile);
handleNode(typeQueryNode.exprName, context);
break;
case typescript_1.default.SyntaxKind.TypeLiteral:
const typeLiteralNode = node;
handleNodes(typeLiteralNode.members, file, sourceFile);
handleNodes(typeLiteralNode.members, context);
break;
case typescript_1.default.SyntaxKind.ArrayType:
const arrayTypeNode = node;
handleNode(arrayTypeNode.elementType, file, sourceFile);
handleNode(arrayTypeNode.elementType, context);
break;
case typescript_1.default.SyntaxKind.TupleType:
const tupleTypeNode = node;
handleNodes(tupleTypeNode.elementTypes, file, sourceFile);
handleNodes(tupleTypeNode.elementTypes, context);
break;

@@ -368,26 +371,26 @@ case typescript_1.default.SyntaxKind.OptionalType:

const restTypeNode = node;
handleNode(restTypeNode.type, file, sourceFile);
handleNode(restTypeNode.type, context);
break;
case typescript_1.default.SyntaxKind.UnionType:
const unionTypeNode = node;
handleNodes(unionTypeNode.types, file, sourceFile);
handleNodes(unionTypeNode.types, context);
break;
case typescript_1.default.SyntaxKind.IntersectionType:
const intersectionTypeNode = node;
handleNodes(intersectionTypeNode.types, file, sourceFile);
handleNodes(intersectionTypeNode.types, context);
break;
case typescript_1.default.SyntaxKind.ConditionalType:
const conditionalTypeNode = node;
handleNode(conditionalTypeNode.checkType, file, sourceFile);
handleNode(conditionalTypeNode.extendsType, file, sourceFile);
handleNode(conditionalTypeNode.trueType, file, sourceFile);
handleNode(conditionalTypeNode.falseType, file, sourceFile);
handleNode(conditionalTypeNode.checkType, context);
handleNode(conditionalTypeNode.extendsType, context);
handleNode(conditionalTypeNode.trueType, context);
handleNode(conditionalTypeNode.falseType, context);
break;
case typescript_1.default.SyntaxKind.InferType:
const inferTypeNode = node;
handleNode(inferTypeNode.typeParameter, file, sourceFile);
handleNode(inferTypeNode.typeParameter, context);
break;
case typescript_1.default.SyntaxKind.ParenthesizedType:
const parenthesizedTypeNode = node;
handleNode(parenthesizedTypeNode.type, file, sourceFile);
handleNode(parenthesizedTypeNode.type, context);
break;

@@ -398,162 +401,162 @@ case typescript_1.default.SyntaxKind.ThisType:

const typeOperatorNode = node;
handleNode(typeOperatorNode.type, file, sourceFile);
handleNode(typeOperatorNode.type, context);
break;
case typescript_1.default.SyntaxKind.IndexedAccessType:
const indexedAccessTypeNode = node;
handleNode(indexedAccessTypeNode.objectType, file, sourceFile);
handleNode(indexedAccessTypeNode.indexType, file, sourceFile);
handleNode(indexedAccessTypeNode.objectType, context);
handleNode(indexedAccessTypeNode.indexType, context);
break;
case typescript_1.default.SyntaxKind.MappedType:
const mappedTypeNode = node;
handleNode(mappedTypeNode.questionToken, file, sourceFile);
handleNode(mappedTypeNode.readonlyToken, file, sourceFile);
handleNode(mappedTypeNode.type, file, sourceFile);
handleNode(mappedTypeNode.typeParameter, file, sourceFile);
handleNode(mappedTypeNode.questionToken, context);
handleNode(mappedTypeNode.readonlyToken, context);
handleNode(mappedTypeNode.type, context);
handleNode(mappedTypeNode.typeParameter, context);
break;
case typescript_1.default.SyntaxKind.LiteralType:
const literalTypeNode = node;
handleNode(literalTypeNode.literal, file, sourceFile);
handleNode(literalTypeNode.literal, context);
break;
case typescript_1.default.SyntaxKind.ImportType:
const importTypeNode = node;
handleNode(importTypeNode.qualifier, file, sourceFile);
handleNode(importTypeNode.argument, file, sourceFile);
handleNodes(importTypeNode.typeArguments, file, sourceFile);
handleNode(importTypeNode.qualifier, context);
handleNode(importTypeNode.argument, context);
handleNodes(importTypeNode.typeArguments, context);
break;
case typescript_1.default.SyntaxKind.ObjectBindingPattern:
const objectBindingPattern = node;
handleNodes(objectBindingPattern.elements, file, sourceFile);
handleNodes(objectBindingPattern.elements, context);
break;
case typescript_1.default.SyntaxKind.ArrayBindingPattern:
const arrayBindingPattern = node;
handleNodes(arrayBindingPattern.elements, file, sourceFile);
handleNodes(arrayBindingPattern.elements, context);
break;
case typescript_1.default.SyntaxKind.BindingElement:
const bindingElement = node;
handleNode(bindingElement.name, file, sourceFile);
handleNode(bindingElement.initializer, file, sourceFile);
handleNode(bindingElement.dotDotDotToken, file, sourceFile);
handleNode(bindingElement.propertyName, file, sourceFile);
handleNode(bindingElement.name, context);
handleNode(bindingElement.initializer, context);
handleNode(bindingElement.dotDotDotToken, context);
handleNode(bindingElement.propertyName, context);
break;
case typescript_1.default.SyntaxKind.ArrayLiteralExpression:
const arrayLiteralExpression = node;
handleNodes(arrayLiteralExpression.elements, file, sourceFile);
handleNodes(arrayLiteralExpression.elements, context);
break;
case typescript_1.default.SyntaxKind.ObjectLiteralExpression:
const objectLiteralExpression = node;
handleNodes(objectLiteralExpression.properties, file, sourceFile);
handleNodes(objectLiteralExpression.properties, context);
break;
case typescript_1.default.SyntaxKind.PropertyAccessExpression:
const propertyAccessExpression = node;
handleNode(propertyAccessExpression.expression, file, sourceFile);
handleNode(propertyAccessExpression.name, file, sourceFile);
handleNode(propertyAccessExpression.expression, context);
handleNode(propertyAccessExpression.name, context);
break;
case typescript_1.default.SyntaxKind.ElementAccessExpression:
const elementAccessExpression = node;
handleNode(elementAccessExpression.expression, file, sourceFile);
handleNode(elementAccessExpression.argumentExpression, file, sourceFile);
handleNode(elementAccessExpression.expression, context);
handleNode(elementAccessExpression.argumentExpression, context);
break;
case typescript_1.default.SyntaxKind.CallExpression:
const callExpression = node;
handleNode(callExpression.expression, file, sourceFile);
handleNodes(callExpression.arguments, file, sourceFile);
handleNodes(callExpression.typeArguments, file, sourceFile);
handleNode(callExpression.expression, context);
handleNodes(callExpression.arguments, context);
handleNodes(callExpression.typeArguments, context);
break;
case typescript_1.default.SyntaxKind.NewExpression:
const newExpression = node;
handleNode(newExpression.expression, file, sourceFile);
handleNodes(newExpression.arguments, file, sourceFile);
handleNodes(newExpression.typeArguments, file, sourceFile);
handleNode(newExpression.expression, context);
handleNodes(newExpression.arguments, context);
handleNodes(newExpression.typeArguments, context);
break;
case typescript_1.default.SyntaxKind.TaggedTemplateExpression:
const taggedTemplateExpression = node;
handleNode(taggedTemplateExpression.template, file, sourceFile);
handleNode(taggedTemplateExpression.template, context);
break;
case typescript_1.default.SyntaxKind.TypeAssertionExpression:
const typeAssertion = node;
handleNode(typeAssertion.expression, file, sourceFile);
handleNode(typeAssertion.type, file, sourceFile);
handleNode(typeAssertion.expression, context);
handleNode(typeAssertion.type, context);
break;
case typescript_1.default.SyntaxKind.ParenthesizedExpression:
const parenthesizedExpression = node;
handleNode(parenthesizedExpression.expression, file, sourceFile);
handleNode(parenthesizedExpression.expression, context);
break;
case typescript_1.default.SyntaxKind.FunctionExpression:
const functionExpression = node;
handleNode(functionExpression.name, file, sourceFile);
handleNodes(functionExpression.parameters, file, sourceFile);
handleNode(functionExpression.body, file, sourceFile);
handleNode(functionExpression.asteriskToken, file, sourceFile);
handleNode(functionExpression.questionToken, file, sourceFile);
handleNode(functionExpression.type, file, sourceFile);
handleNodes(functionExpression.typeParameters, file, sourceFile);
handleNode(functionExpression.name, context);
handleNodes(functionExpression.parameters, context);
handleNode(functionExpression.body, context);
handleNode(functionExpression.asteriskToken, context);
handleNode(functionExpression.questionToken, context);
handleNode(functionExpression.type, context);
handleNodes(functionExpression.typeParameters, context);
break;
case typescript_1.default.SyntaxKind.ArrowFunction:
const arrowFunction = node;
handleNode(arrowFunction.name, file, sourceFile);
handleNodes(arrowFunction.parameters, file, sourceFile);
handleNode(arrowFunction.body, file, sourceFile);
handleNode(arrowFunction.asteriskToken, file, sourceFile);
handleNode(arrowFunction.questionToken, file, sourceFile);
handleNode(arrowFunction.type, file, sourceFile);
handleNodes(arrowFunction.typeParameters, file, sourceFile);
handleNode(arrowFunction.equalsGreaterThanToken, file, sourceFile);
handleNode(arrowFunction.name, context);
handleNodes(arrowFunction.parameters, context);
handleNode(arrowFunction.body, context);
handleNode(arrowFunction.asteriskToken, context);
handleNode(arrowFunction.questionToken, context);
handleNode(arrowFunction.type, context);
handleNodes(arrowFunction.typeParameters, context);
handleNode(arrowFunction.equalsGreaterThanToken, context);
break;
case typescript_1.default.SyntaxKind.DeleteExpression:
const deleteExpression = node;
handleNode(deleteExpression.expression, file, sourceFile);
handleNode(deleteExpression.expression, context);
break;
case typescript_1.default.SyntaxKind.TypeOfExpression:
const typeOfExpression = node;
handleNode(typeOfExpression.expression, file, sourceFile);
handleNode(typeOfExpression.expression, context);
break;
case typescript_1.default.SyntaxKind.VoidExpression:
const voidExpression = node;
handleNode(voidExpression.expression, file, sourceFile);
handleNode(voidExpression.expression, context);
break;
case typescript_1.default.SyntaxKind.AwaitExpression:
const awaitExpression = node;
handleNode(awaitExpression.expression, file, sourceFile);
handleNode(awaitExpression.expression, context);
break;
case typescript_1.default.SyntaxKind.PrefixUnaryExpression:
const prefixUnaryExpression = node;
handleNode(prefixUnaryExpression.operand, file, sourceFile);
handleNode(prefixUnaryExpression.operand, context);
break;
case typescript_1.default.SyntaxKind.PostfixUnaryExpression:
const postfixUnaryExpression = node;
handleNode(postfixUnaryExpression.operand, file, sourceFile);
handleNode(postfixUnaryExpression.operand, context);
break;
case typescript_1.default.SyntaxKind.BinaryExpression:
const binaryExpression = node;
handleNode(binaryExpression.left, file, sourceFile);
handleNode(binaryExpression.right, file, sourceFile);
handleNode(binaryExpression.operatorToken, file, sourceFile);
handleNode(binaryExpression.left, context);
handleNode(binaryExpression.right, context);
handleNode(binaryExpression.operatorToken, context);
break;
case typescript_1.default.SyntaxKind.ConditionalExpression:
const conditionalExpression = node;
handleNode(conditionalExpression.condition, file, sourceFile);
handleNode(conditionalExpression.colonToken, file, sourceFile);
handleNode(conditionalExpression.questionToken, file, sourceFile);
handleNode(conditionalExpression.whenTrue, file, sourceFile);
handleNode(conditionalExpression.whenFalse, file, sourceFile);
handleNode(conditionalExpression.condition, context);
handleNode(conditionalExpression.colonToken, context);
handleNode(conditionalExpression.questionToken, context);
handleNode(conditionalExpression.whenTrue, context);
handleNode(conditionalExpression.whenFalse, context);
break;
case typescript_1.default.SyntaxKind.TemplateExpression:
const templateExpression = node;
handleNodes(templateExpression.templateSpans, file, sourceFile);
handleNodes(templateExpression.templateSpans, context);
break;
case typescript_1.default.SyntaxKind.YieldExpression:
const yieldExpression = node;
handleNode(yieldExpression.asteriskToken, file, sourceFile);
handleNode(yieldExpression.expression, file, sourceFile);
handleNode(yieldExpression.asteriskToken, context);
handleNode(yieldExpression.expression, context);
break;
case typescript_1.default.SyntaxKind.SpreadElement:
const spreadElement = node;
handleNode(spreadElement.expression, file, sourceFile);
handleNode(spreadElement.expression, context);
break;
case typescript_1.default.SyntaxKind.ClassExpression:
const classExpression = node;
handleNode(classExpression.name, file, sourceFile);
handleNodes(classExpression.typeParameters, file, sourceFile);
handleNodes(classExpression.members, file, sourceFile);
handleNodes(classExpression.heritageClauses, file, sourceFile);
handleNode(classExpression.name, context);
handleNodes(classExpression.typeParameters, context);
handleNodes(classExpression.members, context);
handleNodes(classExpression.heritageClauses, context);
break;

@@ -564,34 +567,34 @@ case typescript_1.default.SyntaxKind.OmittedExpression:

const expressionWithTypeArguments = node;
handleNode(expressionWithTypeArguments.expression, file, sourceFile);
handleNodes(expressionWithTypeArguments.typeArguments, file, sourceFile);
handleNode(expressionWithTypeArguments.expression, context);
handleNodes(expressionWithTypeArguments.typeArguments, context);
break;
case typescript_1.default.SyntaxKind.AsExpression:
const asExpression = node;
handleNode(asExpression.expression, file, sourceFile);
handleNode(asExpression.type, file, sourceFile);
handleNode(asExpression.expression, context);
handleNode(asExpression.type, context);
break;
case typescript_1.default.SyntaxKind.NonNullExpression:
const nonNullExpression = node;
handleNode(nonNullExpression.expression, file, sourceFile);
handleNode(nonNullExpression.expression, context);
break;
case typescript_1.default.SyntaxKind.MetaProperty:
const metaProperty = node;
handleNode(metaProperty.name, file, sourceFile);
handleNode(metaProperty.name, context);
break;
case typescript_1.default.SyntaxKind.TemplateSpan:
const templateSpan = node;
handleNode(templateSpan.expression, file, sourceFile);
handleNode(templateSpan.literal, file, sourceFile);
handleNode(templateSpan.expression, context);
handleNode(templateSpan.literal, context);
break;
case typescript_1.default.SyntaxKind.SemicolonClassElement:
const semicolonClassElement = node;
handleNode(semicolonClassElement.name, file, sourceFile);
handleNode(semicolonClassElement.name, context);
break;
case typescript_1.default.SyntaxKind.Block:
const block = node;
handleNodes(block.statements, file, sourceFile);
handleNodes(block.statements, context);
break;
case typescript_1.default.SyntaxKind.VariableStatement:
const variableStatement = node;
handleNode(variableStatement.declarationList, file, sourceFile);
handleNode(variableStatement.declarationList, context);
break;

@@ -602,39 +605,39 @@ case typescript_1.default.SyntaxKind.EmptyStatement:

const expressionStatement = node;
handleNode(expressionStatement.expression, file, sourceFile);
handleNode(expressionStatement.expression, context);
break;
case typescript_1.default.SyntaxKind.IfStatement:
const ifStatement = node;
handleNode(ifStatement.expression, file, sourceFile);
handleNode(ifStatement.thenStatement, file, sourceFile);
handleNode(ifStatement.elseStatement, file, sourceFile);
handleNode(ifStatement.expression, context);
handleNode(ifStatement.thenStatement, context);
handleNode(ifStatement.elseStatement, context);
break;
case typescript_1.default.SyntaxKind.DoStatement:
const doStatement = node;
handleNode(doStatement.expression, file, sourceFile);
handleNode(doStatement.statement, file, sourceFile);
handleNode(doStatement.expression, context);
handleNode(doStatement.statement, context);
break;
case typescript_1.default.SyntaxKind.WhileStatement:
const whileStatement = node;
handleNode(whileStatement.statement, file, sourceFile);
handleNode(whileStatement.expression, file, sourceFile);
handleNode(whileStatement.statement, context);
handleNode(whileStatement.expression, context);
break;
case typescript_1.default.SyntaxKind.ForStatement:
const forStatement = node;
handleNode(forStatement.initializer, file, sourceFile);
handleNode(forStatement.condition, file, sourceFile);
handleNode(forStatement.incrementor, file, sourceFile);
handleNode(forStatement.statement, file, sourceFile);
handleNode(forStatement.initializer, context);
handleNode(forStatement.condition, context);
handleNode(forStatement.incrementor, context);
handleNode(forStatement.statement, context);
break;
case typescript_1.default.SyntaxKind.ForInStatement:
const forInStatement = node;
handleNode(forInStatement.initializer, file, sourceFile);
handleNode(forInStatement.expression, file, sourceFile);
handleNode(forInStatement.statement, file, sourceFile);
handleNode(forInStatement.initializer, context);
handleNode(forInStatement.expression, context);
handleNode(forInStatement.statement, context);
break;
case typescript_1.default.SyntaxKind.ForOfStatement:
const forOfStatement = node;
handleNode(forOfStatement.initializer, file, sourceFile);
handleNode(forOfStatement.statement, file, sourceFile);
handleNode(forOfStatement.expression, file, sourceFile);
handleNode(forOfStatement.awaitModifier, file, sourceFile);
handleNode(forOfStatement.initializer, context);
handleNode(forOfStatement.statement, context);
handleNode(forOfStatement.expression, context);
handleNode(forOfStatement.awaitModifier, context);
break;

@@ -646,28 +649,28 @@ case typescript_1.default.SyntaxKind.ContinueStatement:

const returnStatement = node;
handleNode(returnStatement.expression, file, sourceFile);
handleNode(returnStatement.expression, context);
break;
case typescript_1.default.SyntaxKind.WithStatement:
const withStatement = node;
handleNode(withStatement.expression, file, sourceFile);
handleNode(withStatement.statement, file, sourceFile);
handleNode(withStatement.expression, context);
handleNode(withStatement.statement, context);
break;
case typescript_1.default.SyntaxKind.SwitchStatement:
const switchStatement = node;
handleNode(switchStatement.expression, file, sourceFile);
handleNode(switchStatement.caseBlock, file, sourceFile);
handleNode(switchStatement.expression, context);
handleNode(switchStatement.caseBlock, context);
break;
case typescript_1.default.SyntaxKind.LabeledStatement:
const labeledStatement = node;
handleNode(labeledStatement.label, file, sourceFile);
handleNode(labeledStatement.statement, file, sourceFile);
handleNode(labeledStatement.label, context);
handleNode(labeledStatement.statement, context);
break;
case typescript_1.default.SyntaxKind.ThrowStatement:
const throwStatement = node;
handleNode(throwStatement.expression, file, sourceFile);
handleNode(throwStatement.expression, context);
break;
case typescript_1.default.SyntaxKind.TryStatement:
const tryStatement = node;
handleNode(tryStatement.tryBlock, file, sourceFile);
handleNode(tryStatement.catchClause, file, sourceFile);
handleNode(tryStatement.finallyBlock, file, sourceFile);
handleNode(tryStatement.tryBlock, context);
handleNode(tryStatement.catchClause, context);
handleNode(tryStatement.finallyBlock, context);
break;

@@ -678,143 +681,143 @@ case typescript_1.default.SyntaxKind.DebuggerStatement:

const variableDeclaration = node;
handleNode(variableDeclaration.name, file, sourceFile);
handleNode(variableDeclaration.type, file, sourceFile);
handleNode(variableDeclaration.initializer, file, sourceFile);
handleNode(variableDeclaration.name, context);
handleNode(variableDeclaration.type, context);
handleNode(variableDeclaration.initializer, context);
break;
case typescript_1.default.SyntaxKind.VariableDeclarationList:
const declarationList = node;
handleNodes(declarationList.declarations, file, sourceFile);
handleNodes(declarationList.declarations, context);
break;
case typescript_1.default.SyntaxKind.FunctionDeclaration:
const functionDeclaration = node;
handleNode(functionDeclaration.name, file, sourceFile);
handleNodes(functionDeclaration.parameters, file, sourceFile);
handleNode(functionDeclaration.body, file, sourceFile);
handleNode(functionDeclaration.asteriskToken, file, sourceFile);
handleNode(functionDeclaration.questionToken, file, sourceFile);
handleNode(functionDeclaration.type, file, sourceFile);
handleNodes(functionDeclaration.typeParameters, file, sourceFile);
handleNode(functionDeclaration.name, context);
handleNodes(functionDeclaration.parameters, context);
handleNode(functionDeclaration.body, context);
handleNode(functionDeclaration.asteriskToken, context);
handleNode(functionDeclaration.questionToken, context);
handleNode(functionDeclaration.type, context);
handleNodes(functionDeclaration.typeParameters, context);
break;
case typescript_1.default.SyntaxKind.ClassDeclaration:
const classDeclaration = node;
handleNode(classDeclaration.name, file, sourceFile);
handleNodes(classDeclaration.members, file, sourceFile);
handleNodes(classDeclaration.typeParameters, file, sourceFile);
handleNodes(classDeclaration.heritageClauses, file, sourceFile);
handleNode(classDeclaration.name, context);
handleNodes(classDeclaration.members, context);
handleNodes(classDeclaration.typeParameters, context);
handleNodes(classDeclaration.heritageClauses, context);
break;
case typescript_1.default.SyntaxKind.InterfaceDeclaration:
const interfaceDeclaration = node;
handleNode(interfaceDeclaration.name, file, sourceFile);
handleNodes(interfaceDeclaration.members, file, sourceFile);
handleNodes(interfaceDeclaration.typeParameters, file, sourceFile);
handleNodes(interfaceDeclaration.heritageClauses, file, sourceFile);
handleNode(interfaceDeclaration.name, context);
handleNodes(interfaceDeclaration.members, context);
handleNodes(interfaceDeclaration.typeParameters, context);
handleNodes(interfaceDeclaration.heritageClauses, context);
break;
case typescript_1.default.SyntaxKind.TypeAliasDeclaration:
const typeAliasDeclaration = node;
handleNode(typeAliasDeclaration.name, file, sourceFile);
handleNode(typeAliasDeclaration.type, file, sourceFile);
handleNodes(typeAliasDeclaration.typeParameters, file, sourceFile);
handleNode(typeAliasDeclaration.name, context);
handleNode(typeAliasDeclaration.type, context);
handleNodes(typeAliasDeclaration.typeParameters, context);
break;
case typescript_1.default.SyntaxKind.EnumDeclaration:
const enumDeclaration = node;
handleNode(enumDeclaration.name, file, sourceFile);
handleNodes(enumDeclaration.members, file, sourceFile);
handleNode(enumDeclaration.name, context);
handleNodes(enumDeclaration.members, context);
break;
case typescript_1.default.SyntaxKind.ModuleDeclaration:
const moduleDeclaration = node;
handleNode(moduleDeclaration.name, file, sourceFile);
handleNode(moduleDeclaration.body, file, sourceFile);
handleNode(moduleDeclaration.name, context);
handleNode(moduleDeclaration.body, context);
break;
case typescript_1.default.SyntaxKind.ModuleBlock:
const moduleBlock = node;
handleNodes(moduleBlock.statements, file, sourceFile);
handleNodes(moduleBlock.statements, context);
break;
case typescript_1.default.SyntaxKind.CaseBlock:
const caseBlock = node;
handleNodes(caseBlock.clauses, file, sourceFile);
handleNodes(caseBlock.clauses, context);
break;
case typescript_1.default.SyntaxKind.NamespaceExportDeclaration:
const namespaceExportDeclaration = node;
handleNode(namespaceExportDeclaration.name, file, sourceFile);
handleNode(namespaceExportDeclaration.name, context);
break;
case typescript_1.default.SyntaxKind.ImportEqualsDeclaration:
const importEqualsDeclaration = node;
handleNode(importEqualsDeclaration.name, file, sourceFile);
handleNode(importEqualsDeclaration.moduleReference, file, sourceFile);
handleNode(importEqualsDeclaration.name, context);
handleNode(importEqualsDeclaration.moduleReference, context);
break;
case typescript_1.default.SyntaxKind.ImportDeclaration:
const importDeclaration = node;
handleNode(importDeclaration.importClause, file, sourceFile);
handleNode(importDeclaration.moduleSpecifier, file, sourceFile);
handleNode(importDeclaration.importClause, context);
handleNode(importDeclaration.moduleSpecifier, context);
break;
case typescript_1.default.SyntaxKind.ImportClause:
const importClause = node;
handleNode(importClause.name, file, sourceFile);
handleNode(importClause.namedBindings, file, sourceFile);
handleNode(importClause.name, context);
handleNode(importClause.namedBindings, context);
break;
case typescript_1.default.SyntaxKind.NamespaceImport:
const namespaceImport = node;
handleNode(namespaceImport.name, file, sourceFile);
handleNode(namespaceImport.name, context);
break;
case typescript_1.default.SyntaxKind.NamedImports:
const namedImports = node;
handleNodes(namedImports.elements, file, sourceFile);
handleNodes(namedImports.elements, context);
break;
case typescript_1.default.SyntaxKind.ImportSpecifier:
const importSpecifier = node;
handleNode(importSpecifier.name, file, sourceFile);
handleNode(importSpecifier.propertyName, file, sourceFile);
handleNode(importSpecifier.name, context);
handleNode(importSpecifier.propertyName, context);
break;
case typescript_1.default.SyntaxKind.ExportAssignment:
const exportAssignment = node;
handleNode(exportAssignment.name, file, sourceFile);
handleNode(exportAssignment.expression, file, sourceFile);
handleNode(exportAssignment.name, context);
handleNode(exportAssignment.expression, context);
break;
case typescript_1.default.SyntaxKind.ExportDeclaration:
const exportDeclaration = node;
handleNode(exportDeclaration.exportClause, file, sourceFile);
handleNode(exportDeclaration.name, file, sourceFile);
handleNode(exportDeclaration.moduleSpecifier, file, sourceFile);
handleNode(exportDeclaration.exportClause, context);
handleNode(exportDeclaration.name, context);
handleNode(exportDeclaration.moduleSpecifier, context);
break;
case typescript_1.default.SyntaxKind.NamedExports:
const namedExports = node;
handleNodes(namedExports.elements, file, sourceFile);
handleNodes(namedExports.elements, context);
break;
case typescript_1.default.SyntaxKind.ExportSpecifier:
const exportSpecifier = node;
handleNode(exportSpecifier.name, file, sourceFile);
handleNode(exportSpecifier.propertyName, file, sourceFile);
handleNode(exportSpecifier.name, context);
handleNode(exportSpecifier.propertyName, context);
break;
case typescript_1.default.SyntaxKind.MissingDeclaration:
const missingDeclaration = node;
handleNode(missingDeclaration.name, file, sourceFile);
handleNode(missingDeclaration.name, context);
break;
case typescript_1.default.SyntaxKind.ExternalModuleReference:
const externalModuleReference = node;
handleNode(externalModuleReference.expression, file, sourceFile);
handleNode(externalModuleReference.expression, context);
break;
case typescript_1.default.SyntaxKind.JsxElement:
const jsxElement = node;
handleNode(jsxElement.openingElement, file, sourceFile);
handleNode(jsxElement.closingElement, file, sourceFile);
handleNodes(jsxElement.children, file, sourceFile);
handleNode(jsxElement.openingElement, context);
handleNode(jsxElement.closingElement, context);
handleNodes(jsxElement.children, context);
break;
case typescript_1.default.SyntaxKind.JsxSelfClosingElement:
const jsxSelfClosingElement = node;
handleNode(jsxSelfClosingElement.attributes, file, sourceFile);
handleNode(jsxSelfClosingElement.tagName, file, sourceFile);
handleNode(jsxSelfClosingElement.attributes, context);
handleNode(jsxSelfClosingElement.tagName, context);
break;
case typescript_1.default.SyntaxKind.JsxOpeningElement:
const jsxOpeningElement = node;
handleNode(jsxOpeningElement.attributes, file, sourceFile);
handleNode(jsxOpeningElement.tagName, file, sourceFile);
handleNode(jsxOpeningElement.attributes, context);
handleNode(jsxOpeningElement.tagName, context);
break;
case typescript_1.default.SyntaxKind.JsxClosingElement:
const jsxClosingElement = node;
handleNode(jsxClosingElement.tagName, file, sourceFile);
handleNode(jsxClosingElement.tagName, context);
break;
case typescript_1.default.SyntaxKind.JsxFragment:
const jsxFragment = node;
handleNode(jsxFragment.openingFragment, file, sourceFile);
handleNode(jsxFragment.closingFragment, file, sourceFile);
handleNodes(jsxFragment.children, file, sourceFile);
handleNode(jsxFragment.openingFragment, context);
handleNode(jsxFragment.closingFragment, context);
handleNodes(jsxFragment.children, context);
break;

@@ -827,54 +830,54 @@ case typescript_1.default.SyntaxKind.JsxOpeningFragment:

const jsxAttribute = node;
handleNode(jsxAttribute.name, file, sourceFile);
handleNode(jsxAttribute.initializer, file, sourceFile);
handleNode(jsxAttribute.name, context);
handleNode(jsxAttribute.initializer, context);
break;
case typescript_1.default.SyntaxKind.JsxAttributes:
const jsxAttributes = node;
handleNodes(jsxAttributes.properties, file, sourceFile);
handleNodes(jsxAttributes.properties, context);
break;
case typescript_1.default.SyntaxKind.JsxSpreadAttribute:
const jsxSpreadAttribute = node;
handleNode(jsxSpreadAttribute.name, file, sourceFile);
handleNode(jsxSpreadAttribute.expression, file, sourceFile);
handleNode(jsxSpreadAttribute.name, context);
handleNode(jsxSpreadAttribute.expression, context);
break;
case typescript_1.default.SyntaxKind.JsxExpression:
const jsxExpression = node;
handleNode(jsxExpression.dotDotDotToken, file, sourceFile);
handleNode(jsxExpression.expression, file, sourceFile);
handleNode(jsxExpression.dotDotDotToken, context);
handleNode(jsxExpression.expression, context);
break;
case typescript_1.default.SyntaxKind.CaseClause:
const caseClause = node;
handleNodes(caseClause.statements, file, sourceFile);
handleNode(caseClause.expression, file, sourceFile);
handleNodes(caseClause.statements, context);
handleNode(caseClause.expression, context);
break;
case typescript_1.default.SyntaxKind.DefaultClause:
const defaultClause = node;
handleNodes(defaultClause.statements, file, sourceFile);
handleNodes(defaultClause.statements, context);
break;
case typescript_1.default.SyntaxKind.HeritageClause:
const heritageClause = node;
handleNodes(heritageClause.types, file, sourceFile);
handleNodes(heritageClause.types, context);
break;
case typescript_1.default.SyntaxKind.CatchClause:
const catchClause = node;
handleNode(catchClause.variableDeclaration, file, sourceFile);
handleNode(catchClause.block, file, sourceFile);
handleNode(catchClause.variableDeclaration, context);
handleNode(catchClause.block, context);
break;
case typescript_1.default.SyntaxKind.PropertyAssignment:
const propertyAssignmentExpression = node;
handleNode(propertyAssignmentExpression.name, file, sourceFile);
handleNode(propertyAssignmentExpression.questionToken, file, sourceFile);
handleNode(propertyAssignmentExpression.initializer, file, sourceFile);
handleNode(propertyAssignmentExpression.name, context);
handleNode(propertyAssignmentExpression.questionToken, context);
handleNode(propertyAssignmentExpression.initializer, context);
break;
case typescript_1.default.SyntaxKind.ShorthandPropertyAssignment:
const shorthandPropertyAssignment = node;
handleNode(shorthandPropertyAssignment.name, file, sourceFile);
handleNode(shorthandPropertyAssignment.questionToken, file, sourceFile);
handleNode(shorthandPropertyAssignment.equalsToken, file, sourceFile);
handleNode(shorthandPropertyAssignment.objectAssignmentInitializer, file, sourceFile);
handleNode(shorthandPropertyAssignment.name, context);
handleNode(shorthandPropertyAssignment.questionToken, context);
handleNode(shorthandPropertyAssignment.equalsToken, context);
handleNode(shorthandPropertyAssignment.objectAssignmentInitializer, context);
break;
case typescript_1.default.SyntaxKind.SpreadAssignment:
const spreadAssignment = node;
handleNode(spreadAssignment.name, file, sourceFile);
handleNode(spreadAssignment.expression, file, sourceFile);
handleNode(spreadAssignment.name, context);
handleNode(spreadAssignment.expression, context);
break;

@@ -915,2 +918,5 @@ case typescript_1.default.SyntaxKind.EnumMember:

}
const allFiles = [];
const sourceFileInfos = [];
const typeCheckResult = await readCache(enableCache);
for (const sourceFile of program.getSourceFiles()) {

@@ -920,26 +926,117 @@ let file = sourceFile.fileName;

file = path.relative(process.cwd(), file);
utils.forEachComment(sourceFile, (_, comment) => {
const commentText = comment.kind === typescript_1.default.SyntaxKind.SingleLineCommentTrivia
? sourceFile.text.substring(comment.pos + 2, comment.end).trim()
: sourceFile.text.substring(comment.pos + 2, comment.end - 2).trim();
if (commentText.includes('type-coverage:ignore-next-line')) {
if (!ingoreMap[file]) {
ingoreMap[file] = new Set();
}
const line = typescript_1.default.getLineAndCharacterOfPosition(sourceFile, comment.pos).line;
ingoreMap[file].add(line + 1);
allFiles.push(file);
const hash = enableCache ? calculateHash((await readFileAsync(file)).toString()) : '';
const cache = typeCheckResult.cache.find((c) => c.file === file && c.hash === hash);
sourceFileInfos.push({
file,
sourceFile,
hash,
cache
});
}
}
const dependencies = [];
if (enableCache) {
for (const { sourceFile, file } of sourceFileInfos) {
sourceFile.forEachChild(node => {
let source;
if (node.kind === typescript_1.default.SyntaxKind.ImportEqualsDeclaration) {
source = node.name.text;
}
else if (commentText.includes('type-coverage:ignore-line')) {
if (!ingoreMap[file]) {
ingoreMap[file] = new Set();
}
const line = typescript_1.default.getLineAndCharacterOfPosition(sourceFile, comment.pos).line;
ingoreMap[file].add(line);
else if (node.kind === typescript_1.default.SyntaxKind.ImportDeclaration) {
source = node.moduleSpecifier.text;
}
if (source
&& (source.startsWith('.') || source.startsWith('/'))
&& !source.endsWith('.json')
&& !source.endsWith('.node')) {
const resolveResult = resolveImport(path.relative(process.cwd(), path.resolve(path.dirname(file), source)), allFiles);
dependencies.push([file, resolveResult]);
}
});
sourceFile.forEachChild(node => {
handleNode(node, file, sourceFile);
});
}
}
function clearCacheOfDependencies(sourceFileInfo) {
for (const dependency of dependencies) {
if (dependency[1] === sourceFileInfo.file) {
const dependentSourceFileInfo = sourceFileInfos.find((s) => s.file === dependency[0]);
if (dependentSourceFileInfo && dependentSourceFileInfo.cache) {
dependentSourceFileInfo.cache = undefined;
clearCacheOfDependencies(dependentSourceFileInfo);
}
}
}
}
if (enableCache) {
for (const sourceFileInfo of sourceFileInfos) {
if (!sourceFileInfo.cache) {
clearCacheOfDependencies(sourceFileInfo);
}
}
}
let correctCount = 0;
let totalCount = 0;
let anys = [];
for (const { sourceFile, file, hash, cache } of sourceFileInfos) {
if (cache) {
correctCount += cache.correctCount;
totalCount += cache.totalCount;
anys.push(...cache.anys);
continue;
}
const context = {
file,
sourceFile,
typeCheckResult: {
correctCount: 0,
totalCount: 0,
anys: []
}
};
utils.forEachComment(sourceFile, (_, comment) => {
const commentText = comment.kind === typescript_1.default.SyntaxKind.SingleLineCommentTrivia
? sourceFile.text.substring(comment.pos + 2, comment.end).trim()
: sourceFile.text.substring(comment.pos + 2, comment.end - 2).trim();
if (commentText.includes('type-coverage:ignore-next-line')) {
if (!ingoreMap[file]) {
ingoreMap[file] = new Set();
}
const line = typescript_1.default.getLineAndCharacterOfPosition(sourceFile, comment.pos).line;
ingoreMap[file].add(line + 1);
}
else if (commentText.includes('type-coverage:ignore-line')) {
if (!ingoreMap[file]) {
ingoreMap[file] = new Set();
}
const line = typescript_1.default.getLineAndCharacterOfPosition(sourceFile, comment.pos).line;
ingoreMap[file].add(line);
}
});
sourceFile.forEachChild(node => {
handleNode(node, context);
});
correctCount += context.typeCheckResult.correctCount;
totalCount += context.typeCheckResult.totalCount;
anys.push(...context.typeCheckResult.anys);
if (enableCache) {
const resultCache = typeCheckResult.cache.find((c) => c.file === file);
if (resultCache) {
resultCache.hash = hash;
resultCache.correctCount = context.typeCheckResult.correctCount;
resultCache.totalCount = context.typeCheckResult.totalCount;
resultCache.anys = context.typeCheckResult.anys;
}
else {
typeCheckResult.cache.push({
file,
hash,
...context.typeCheckResult
});
}
}
}
if (enableCache) {
await mkdirIfmissing();
await writeFileAsync(path.resolve(dirName, 'result.json'), JSON.stringify(typeCheckResult, null, 2));
}
return { correctCount, totalCount, anys, program };

@@ -960,1 +1057,66 @@ }

}
function calculateHash(str) {
return crypto.createHash('sha256').update(str).digest('hex');
}
const dirName = '.type-coverage';
function statAsync(p) {
return new Promise((resolve) => {
fs.stat(p, (err, stats) => {
if (err) {
resolve(undefined);
}
else {
resolve(stats);
}
});
});
}
async function mkdirIfmissing() {
const stats = await statAsync(dirName);
if (!stats) {
await mkdirAsync(dirName);
}
}
async function readCache(enableCache) {
if (!enableCache) {
return {
cache: []
};
}
const filepath = path.resolve(dirName, 'result.json');
const stats = await statAsync(filepath);
if (stats && stats.isFile()) {
const text = (await readFileAsync(filepath)).toString();
return JSON.parse(text);
}
return {
cache: []
};
}
function resolveImport(moduleName, allFiles) {
let resolveResult = moduleName + '.ts';
if (allFiles.includes(resolveResult)) {
return resolveResult;
}
resolveResult = moduleName + '.tsx';
if (allFiles.includes(resolveResult)) {
return resolveResult;
}
resolveResult = moduleName + '.d.ts';
if (allFiles.includes(resolveResult)) {
return resolveResult;
}
resolveResult = path.resolve(moduleName, 'index.ts');
if (allFiles.includes(resolveResult)) {
return resolveResult;
}
resolveResult = path.resolve(moduleName, 'index.tsx');
if (allFiles.includes(resolveResult)) {
return resolveResult;
}
resolveResult = path.resolve(moduleName, 'index.d.ts');
if (allFiles.includes(resolveResult)) {
return resolveResult;
}
return moduleName;
}

@@ -25,3 +25,3 @@ "use strict";

suppressError = argv.suppressError;
const { correctCount, totalCount, anys } = await core_1.lint(argv.p || argv.project || '.', true, argv.debug, undefined, undefined, argv.strict);
const { correctCount, totalCount, anys } = await core_1.lint(argv.p || argv.project || '.', true, argv.debug, undefined, undefined, argv.strict, argv.cache);
const percent = Math.round(10000 * correctCount / totalCount) / 100;

@@ -28,0 +28,0 @@ const atLeast = await getAtLeast(argv);

{
"name": "type-coverage",
"version": "1.9.1",
"version": "1.10.0",
"description": "A CLI tool to check type coverage for typescript code",

@@ -11,8 +11,8 @@ "main": "dist/core.js",

"devDependencies": {
"@commitlint/cli": "7.3.2",
"@commitlint/config-conventional": "7.3.1",
"@commitlint/cli": "7.5.2",
"@commitlint/config-conventional": "7.5.0",
"@types/glob": "7.1.1",
"@types/jasmine": "3.3.8",
"@types/jasmine": "3.3.9",
"@types/minimist": "1.2.0",
"@types/node": "10.12.18",
"@types/node": "11.9.4",
"clean-release": "2.7.0",

@@ -19,0 +19,0 @@ "clean-scripts": "1.9.2",

@@ -32,2 +32,3 @@ # type-coverage

--strict | boolean? | if the identifiers' type arguments exist and contain at least one `any`, like `any[]`, `ReadonlyArray<any>`, `Promise<any>`, `Foo<number, any>`, it will be considered as `any` too; also, future minor release may introduce stricter type check in this mode, which may lower the code coverage
--cache | boolean? | save and reuse type check result of files that is unchanged and independent of changed files in `.type-coverage` directory, to improve speed

@@ -34,0 +35,0 @@ ## config in package.json

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc