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

type-coverage - npm Package Compare versions

Comparing version 1.2.1 to 1.3.0-alpha.0

dist/core.d.ts

860

dist/index.js

@@ -5,6 +5,4 @@ "use strict";

const minimist_1 = tslib_1.__importDefault(require("minimist"));
const typescript_1 = tslib_1.__importDefault(require("typescript"));
const path = tslib_1.__importStar(require("path"));
const packageJson = tslib_1.__importStar(require("../package.json"));
const tsconfig_1 = require("./tsconfig");
const core_1 = require("./core");
let suppressError = false;

@@ -23,857 +21,3 @@ function showToolVersion() {

suppressError = argv.suppressError;
const { configFilePath, basename } = tsconfig_1.getTsConfigFilePath(argv.p || argv.project || '.');
const config = tsconfig_1.getTsConfig(configFilePath, basename);
const { options: compilerOptions, errors } = typescript_1.default.convertCompilerOptionsFromJson(config.compilerOptions, basename);
if (errors && errors.length > 0) {
throw errors;
}
const rootNames = await tsconfig_1.getRootNames(config, basename);
const program = typescript_1.default.createProgram(rootNames, compilerOptions);
const checker = program.getTypeChecker();
let correctCount = 0;
let totalCount = 0;
const detail = argv.detail;
const debug = argv.debug;
function collectData(node, file, sourceFile) {
const type = checker.getTypeAtLocation(node);
if (type) {
const { line, character } = typescript_1.default.getLineAndCharacterOfPosition(sourceFile, node.getStart(sourceFile));
totalCount++;
if (type.flags === 1 && type.intrinsicName === 'any') {
if (debug) {
console.log(`type === any: ${file}:${line + 1}:${character + 1}: ${node.getText(sourceFile)}`);
}
else if (detail) {
console.log(`${file}:${line + 1}:${character + 1}: ${node.getText(sourceFile)}`);
}
}
else {
correctCount++;
if (debug) {
console.log(`type !== any: ${file}:${line + 1}:${character + 1}: ${node.getText(sourceFile)} ${node.kind}(kind) ${type.flags}(flag) ${type.intrinsicName || ''}`);
}
}
}
}
function handleNodes(nodes, file, sourceFile) {
if (nodes === undefined) {
return;
}
for (const node of nodes) {
handleNode(node, file, sourceFile);
}
}
// tslint:disable-next-line:no-big-function
function handleNode(node, file, sourceFile) {
if (node === undefined) {
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)`);
}
handleNodes(node.decorators, file, sourceFile);
handleNodes(node.modifiers, file, sourceFile);
switch (node.kind) {
case typescript_1.default.SyntaxKind.Unknown:
case typescript_1.default.SyntaxKind.EndOfFileToken:
case typescript_1.default.SyntaxKind.SingleLineCommentTrivia:
case typescript_1.default.SyntaxKind.MultiLineCommentTrivia:
case typescript_1.default.SyntaxKind.NewLineTrivia:
case typescript_1.default.SyntaxKind.WhitespaceTrivia:
case typescript_1.default.SyntaxKind.ShebangTrivia:
case typescript_1.default.SyntaxKind.ConflictMarkerTrivia:
case typescript_1.default.SyntaxKind.NumericLiteral:
case typescript_1.default.SyntaxKind.StringLiteral:
case typescript_1.default.SyntaxKind.JsxText:
case typescript_1.default.SyntaxKind.JsxTextAllWhiteSpaces:
case typescript_1.default.SyntaxKind.RegularExpressionLiteral:
case typescript_1.default.SyntaxKind.NoSubstitutionTemplateLiteral:
case typescript_1.default.SyntaxKind.TemplateHead:
case typescript_1.default.SyntaxKind.TemplateMiddle:
case typescript_1.default.SyntaxKind.TemplateTail:
case typescript_1.default.SyntaxKind.OpenBraceToken:
case typescript_1.default.SyntaxKind.CloseBraceToken:
case typescript_1.default.SyntaxKind.OpenParenToken:
case typescript_1.default.SyntaxKind.CloseParenToken:
case typescript_1.default.SyntaxKind.OpenBracketToken:
case typescript_1.default.SyntaxKind.CloseBracketToken:
case typescript_1.default.SyntaxKind.DotToken:
case typescript_1.default.SyntaxKind.DotDotDotToken:
case typescript_1.default.SyntaxKind.SemicolonToken:
case typescript_1.default.SyntaxKind.CommaToken:
case typescript_1.default.SyntaxKind.LessThanToken:
case typescript_1.default.SyntaxKind.LessThanSlashToken:
case typescript_1.default.SyntaxKind.GreaterThanToken:
case typescript_1.default.SyntaxKind.LessThanEqualsToken:
case typescript_1.default.SyntaxKind.GreaterThanEqualsToken:
case typescript_1.default.SyntaxKind.EqualsEqualsToken:
case typescript_1.default.SyntaxKind.ExclamationEqualsToken:
case typescript_1.default.SyntaxKind.EqualsEqualsEqualsToken:
case typescript_1.default.SyntaxKind.ExclamationEqualsEqualsToken:
case typescript_1.default.SyntaxKind.EqualsGreaterThanToken:
case typescript_1.default.SyntaxKind.PlusToken:
case typescript_1.default.SyntaxKind.MinusToken:
case typescript_1.default.SyntaxKind.AsteriskToken:
case typescript_1.default.SyntaxKind.AsteriskAsteriskToken:
case typescript_1.default.SyntaxKind.SlashToken:
case typescript_1.default.SyntaxKind.PercentToken:
case typescript_1.default.SyntaxKind.PlusPlusToken:
case typescript_1.default.SyntaxKind.MinusMinusToken:
case typescript_1.default.SyntaxKind.LessThanLessThanToken:
case typescript_1.default.SyntaxKind.GreaterThanGreaterThanToken:
case typescript_1.default.SyntaxKind.GreaterThanGreaterThanGreaterThanToken:
case typescript_1.default.SyntaxKind.AmpersandToken:
case typescript_1.default.SyntaxKind.BarToken:
case typescript_1.default.SyntaxKind.CaretToken:
case typescript_1.default.SyntaxKind.ExclamationToken:
case typescript_1.default.SyntaxKind.TildeToken:
case typescript_1.default.SyntaxKind.AmpersandAmpersandToken:
case typescript_1.default.SyntaxKind.BarBarToken:
case typescript_1.default.SyntaxKind.QuestionToken:
case typescript_1.default.SyntaxKind.ColonToken:
case typescript_1.default.SyntaxKind.AtToken:
case typescript_1.default.SyntaxKind.EqualsToken:
case typescript_1.default.SyntaxKind.PlusEqualsToken:
case typescript_1.default.SyntaxKind.MinusEqualsToken:
case typescript_1.default.SyntaxKind.AsteriskEqualsToken:
case typescript_1.default.SyntaxKind.AsteriskAsteriskEqualsToken:
case typescript_1.default.SyntaxKind.SlashEqualsToken:
case typescript_1.default.SyntaxKind.PercentEqualsToken:
case typescript_1.default.SyntaxKind.LessThanLessThanEqualsToken:
case typescript_1.default.SyntaxKind.GreaterThanGreaterThanEqualsToken:
case typescript_1.default.SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken:
case typescript_1.default.SyntaxKind.AmpersandEqualsToken:
case typescript_1.default.SyntaxKind.BarEqualsToken:
case typescript_1.default.SyntaxKind.CaretEqualsToken:
break;
case typescript_1.default.SyntaxKind.Identifier:
collectData(node, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.BreakKeyword:
case typescript_1.default.SyntaxKind.CaseKeyword:
case typescript_1.default.SyntaxKind.CatchKeyword:
case typescript_1.default.SyntaxKind.ClassKeyword:
case typescript_1.default.SyntaxKind.ConstKeyword:
case typescript_1.default.SyntaxKind.ContinueKeyword:
case typescript_1.default.SyntaxKind.DebuggerKeyword:
case typescript_1.default.SyntaxKind.DefaultKeyword:
case typescript_1.default.SyntaxKind.DeleteKeyword:
case typescript_1.default.SyntaxKind.DoKeyword:
case typescript_1.default.SyntaxKind.ElseKeyword:
case typescript_1.default.SyntaxKind.EnumKeyword:
case typescript_1.default.SyntaxKind.ExportKeyword:
case typescript_1.default.SyntaxKind.ExtendsKeyword:
case typescript_1.default.SyntaxKind.FalseKeyword:
case typescript_1.default.SyntaxKind.FinallyKeyword:
case typescript_1.default.SyntaxKind.ForKeyword:
case typescript_1.default.SyntaxKind.FunctionKeyword:
case typescript_1.default.SyntaxKind.IfKeyword:
case typescript_1.default.SyntaxKind.ImportKeyword:
case typescript_1.default.SyntaxKind.InKeyword:
case typescript_1.default.SyntaxKind.InstanceOfKeyword:
case typescript_1.default.SyntaxKind.NewKeyword:
case typescript_1.default.SyntaxKind.NullKeyword:
case typescript_1.default.SyntaxKind.ReturnKeyword:
case typescript_1.default.SyntaxKind.SuperKeyword:
case typescript_1.default.SyntaxKind.SwitchKeyword:
break;
case typescript_1.default.SyntaxKind.ThisKeyword:
collectData(node, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.ThrowKeyword:
case typescript_1.default.SyntaxKind.TrueKeyword:
case typescript_1.default.SyntaxKind.TryKeyword:
case typescript_1.default.SyntaxKind.TypeOfKeyword:
case typescript_1.default.SyntaxKind.VarKeyword:
case typescript_1.default.SyntaxKind.VoidKeyword:
case typescript_1.default.SyntaxKind.WhileKeyword:
case typescript_1.default.SyntaxKind.WithKeyword:
case typescript_1.default.SyntaxKind.ImplementsKeyword:
case typescript_1.default.SyntaxKind.InterfaceKeyword:
case typescript_1.default.SyntaxKind.LetKeyword:
case typescript_1.default.SyntaxKind.PackageKeyword:
case typescript_1.default.SyntaxKind.PrivateKeyword:
case typescript_1.default.SyntaxKind.ProtectedKeyword:
case typescript_1.default.SyntaxKind.PublicKeyword:
case typescript_1.default.SyntaxKind.StaticKeyword:
case typescript_1.default.SyntaxKind.YieldKeyword:
case typescript_1.default.SyntaxKind.AbstractKeyword:
case typescript_1.default.SyntaxKind.AsKeyword:
case typescript_1.default.SyntaxKind.AnyKeyword:
case typescript_1.default.SyntaxKind.AsyncKeyword:
case typescript_1.default.SyntaxKind.AwaitKeyword:
case typescript_1.default.SyntaxKind.BooleanKeyword:
case typescript_1.default.SyntaxKind.ConstructorKeyword:
case typescript_1.default.SyntaxKind.DeclareKeyword:
case typescript_1.default.SyntaxKind.GetKeyword:
case typescript_1.default.SyntaxKind.IsKeyword:
case typescript_1.default.SyntaxKind.KeyOfKeyword:
case typescript_1.default.SyntaxKind.ModuleKeyword:
case typescript_1.default.SyntaxKind.NamespaceKeyword:
case typescript_1.default.SyntaxKind.NeverKeyword:
case typescript_1.default.SyntaxKind.ReadonlyKeyword:
case typescript_1.default.SyntaxKind.RequireKeyword:
case typescript_1.default.SyntaxKind.NumberKeyword:
case typescript_1.default.SyntaxKind.ObjectKeyword:
case typescript_1.default.SyntaxKind.SetKeyword:
case typescript_1.default.SyntaxKind.StringKeyword:
case typescript_1.default.SyntaxKind.SymbolKeyword:
case typescript_1.default.SyntaxKind.TypeKeyword:
case typescript_1.default.SyntaxKind.UndefinedKeyword:
case typescript_1.default.SyntaxKind.FromKeyword:
case typescript_1.default.SyntaxKind.GlobalKeyword:
case typescript_1.default.SyntaxKind.OfKeyword:
break;
case typescript_1.default.SyntaxKind.QualifiedName:
const qualifiedName = node;
handleNode(qualifiedName.left, file, sourceFile);
handleNode(qualifiedName.right, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.ComputedPropertyName:
const computedPropertyName = node;
handleNode(computedPropertyName.expression, file, sourceFile);
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);
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);
break;
case typescript_1.default.SyntaxKind.Decorator:
const decorator = node;
handleNode(decorator.expression, file, sourceFile);
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);
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);
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);
break;
case typescript_1.default.SyntaxKind.MethodDeclaration:
case typescript_1.default.SyntaxKind.Constructor:
case typescript_1.default.SyntaxKind.GetAccessor:
case typescript_1.default.SyntaxKind.SetAccessor:
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);
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);
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);
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);
break;
case typescript_1.default.SyntaxKind.TypePredicate:
const typePredicateNode = node;
handleNode(typePredicateNode.type, file, sourceFile);
handleNode(typePredicateNode.parameterName, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.TypeReference:
const typeReferenceNode = node;
handleNode(typeReferenceNode.typeName, file, sourceFile);
handleNodes(typeReferenceNode.typeArguments, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.FunctionType:
case typescript_1.default.SyntaxKind.ConstructorType:
const signatureDeclarationBase = node;
handleNode(signatureDeclarationBase.name, file, sourceFile);
handleNodes(signatureDeclarationBase.parameters, file, sourceFile);
handleNode(signatureDeclarationBase.type, file, sourceFile);
handleNodes(signatureDeclarationBase.typeParameters, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.TypeQuery:
const typeQueryNode = node;
handleNode(typeQueryNode.exprName, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.TypeLiteral:
const typeLiteralNode = node;
handleNodes(typeLiteralNode.members, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.ArrayType:
const arrayTypeNode = node;
handleNode(arrayTypeNode.elementType, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.TupleType:
const tupleTypeNode = node;
handleNodes(tupleTypeNode.elementTypes, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.UnionType:
const unionTypeNode = node;
handleNodes(unionTypeNode.types, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.IntersectionType:
const intersectionTypeNode = node;
handleNodes(intersectionTypeNode.types, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.ParenthesizedType:
const parenthesizedTypeNode = node;
handleNode(parenthesizedTypeNode.type, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.ThisType:
break;
case typescript_1.default.SyntaxKind.TypeOperator:
const typeOperatorNode = node;
handleNode(typeOperatorNode.type, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.IndexedAccessType:
const indexedAccessTypeNode = node;
handleNode(indexedAccessTypeNode.objectType, file, sourceFile);
handleNode(indexedAccessTypeNode.indexType, file, sourceFile);
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);
break;
case typescript_1.default.SyntaxKind.LiteralType:
const literalTypeNode = node;
handleNode(literalTypeNode.literal, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.ObjectBindingPattern:
const objectBindingPattern = node;
handleNodes(objectBindingPattern.elements, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.ArrayBindingPattern:
const arrayBindingPattern = node;
handleNodes(arrayBindingPattern.elements, file, sourceFile);
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);
break;
case typescript_1.default.SyntaxKind.ArrayLiteralExpression:
const arrayLiteralExpression = node;
handleNodes(arrayLiteralExpression.elements, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.ObjectLiteralExpression:
const objectLiteralExpression = node;
handleNodes(objectLiteralExpression.properties, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.PropertyAccessExpression:
const propertyAccessExpression = node;
handleNode(propertyAccessExpression.expression, file, sourceFile);
handleNode(propertyAccessExpression.name, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.ElementAccessExpression:
const elementAccessExpression = node;
handleNode(elementAccessExpression.expression, file, sourceFile);
handleNode(elementAccessExpression.argumentExpression, file, sourceFile);
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);
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);
break;
case typescript_1.default.SyntaxKind.TaggedTemplateExpression:
const taggedTemplateExpression = node;
handleNode(taggedTemplateExpression.template, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.TypeAssertionExpression:
const typeAssertion = node;
handleNode(typeAssertion.expression, file, sourceFile);
handleNode(typeAssertion.type, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.ParenthesizedExpression:
const parenthesizedExpression = node;
handleNode(parenthesizedExpression.expression, file, sourceFile);
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);
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);
break;
case typescript_1.default.SyntaxKind.DeleteExpression:
const deleteExpression = node;
handleNode(deleteExpression.expression, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.TypeOfExpression:
const typeOfExpression = node;
handleNode(typeOfExpression.expression, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.VoidExpression:
const voidExpression = node;
handleNode(voidExpression.expression, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.AwaitExpression:
const awaitExpression = node;
handleNode(awaitExpression.expression, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.PrefixUnaryExpression:
const prefixUnaryExpression = node;
handleNode(prefixUnaryExpression.operand, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.PostfixUnaryExpression:
const postfixUnaryExpression = node;
handleNode(postfixUnaryExpression.operand, file, sourceFile);
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);
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);
break;
case typescript_1.default.SyntaxKind.TemplateExpression:
const templateExpression = node;
handleNodes(templateExpression.templateSpans, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.YieldExpression:
const yieldExpression = node;
handleNode(yieldExpression.asteriskToken, file, sourceFile);
handleNode(yieldExpression.expression, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.SpreadElement:
const spreadElement = node;
handleNode(spreadElement.expression, file, sourceFile);
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);
break;
case typescript_1.default.SyntaxKind.OmittedExpression:
break;
case typescript_1.default.SyntaxKind.ExpressionWithTypeArguments:
const expressionWithTypeArguments = node;
handleNode(expressionWithTypeArguments.expression, file, sourceFile);
handleNodes(expressionWithTypeArguments.typeArguments, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.AsExpression:
const asExpression = node;
handleNode(asExpression.expression, file, sourceFile);
handleNode(asExpression.type, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.NonNullExpression:
const nonNullExpression = node;
handleNode(nonNullExpression.expression, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.MetaProperty:
const metaProperty = node;
handleNode(metaProperty.name, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.TemplateSpan:
const templateSpan = node;
handleNode(templateSpan.expression, file, sourceFile);
handleNode(templateSpan.literal, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.SemicolonClassElement:
const semicolonClassElement = node;
handleNode(semicolonClassElement.name, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.Block:
const block = node;
handleNodes(block.statements, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.VariableStatement:
const variableStatement = node;
handleNode(variableStatement.declarationList, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.EmptyStatement:
break;
case typescript_1.default.SyntaxKind.ExpressionStatement:
const expressionStatement = node;
handleNode(expressionStatement.expression, file, sourceFile);
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);
break;
case typescript_1.default.SyntaxKind.DoStatement:
const doStatement = node;
handleNode(doStatement.expression, file, sourceFile);
handleNode(doStatement.statement, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.WhileStatement:
const whileStatement = node;
handleNode(whileStatement.statement, file, sourceFile);
handleNode(whileStatement.expression, file, sourceFile);
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);
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);
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);
break;
case typescript_1.default.SyntaxKind.ContinueStatement:
case typescript_1.default.SyntaxKind.BreakStatement:
break;
case typescript_1.default.SyntaxKind.ReturnStatement:
const returnStatement = node;
handleNode(returnStatement.expression, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.WithStatement:
const withStatement = node;
handleNode(withStatement.expression, file, sourceFile);
handleNode(withStatement.statement, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.SwitchStatement:
const switchStatement = node;
handleNode(switchStatement.expression, file, sourceFile);
handleNode(switchStatement.caseBlock, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.LabeledStatement:
const labeledStatement = node;
handleNode(labeledStatement.label, file, sourceFile);
handleNode(labeledStatement.statement, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.ThrowStatement:
const throwStatement = node;
handleNode(throwStatement.expression, file, sourceFile);
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);
break;
case typescript_1.default.SyntaxKind.DebuggerStatement:
break;
case typescript_1.default.SyntaxKind.VariableDeclaration:
const variableDeclaration = node;
handleNode(variableDeclaration.name, file, sourceFile);
handleNode(variableDeclaration.type, file, sourceFile);
handleNode(variableDeclaration.initializer, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.VariableDeclarationList:
const declarationList = node;
handleNodes(declarationList.declarations, file, sourceFile);
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);
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);
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);
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);
break;
case typescript_1.default.SyntaxKind.EnumDeclaration:
const enumDeclaration = node;
handleNode(enumDeclaration.name, file, sourceFile);
handleNodes(enumDeclaration.members, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.ModuleDeclaration:
const moduleDeclaration = node;
handleNode(moduleDeclaration.name, file, sourceFile);
handleNode(moduleDeclaration.body, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.ModuleBlock:
const moduleBlock = node;
handleNodes(moduleBlock.statements, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.CaseBlock:
const caseBlock = node;
handleNodes(caseBlock.clauses, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.NamespaceExportDeclaration:
const namespaceExportDeclaration = node;
handleNode(namespaceExportDeclaration.name, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.ImportEqualsDeclaration:
const importEqualsDeclaration = node;
handleNode(importEqualsDeclaration.name, file, sourceFile);
handleNode(importEqualsDeclaration.moduleReference, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.ImportDeclaration:
const importDeclaration = node;
handleNode(importDeclaration.importClause, file, sourceFile);
handleNode(importDeclaration.moduleSpecifier, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.ImportClause:
const importClause = node;
handleNode(importClause.name, file, sourceFile);
handleNode(importClause.namedBindings, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.NamespaceImport:
const namespaceImport = node;
handleNode(namespaceImport.name, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.NamedImports:
const namedImports = node;
handleNodes(namedImports.elements, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.ImportSpecifier:
const importSpecifier = node;
handleNode(importSpecifier.name, file, sourceFile);
handleNode(importSpecifier.propertyName, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.ExportAssignment:
const exportAssignment = node;
handleNode(exportAssignment.name, file, sourceFile);
handleNode(exportAssignment.expression, file, sourceFile);
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);
break;
case typescript_1.default.SyntaxKind.NamedExports:
const namedExports = node;
handleNodes(namedExports.elements, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.ExportSpecifier:
const exportSpecifier = node;
handleNode(exportSpecifier.name, file, sourceFile);
handleNode(exportSpecifier.propertyName, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.MissingDeclaration:
const missingDeclaration = node;
handleNode(missingDeclaration.name, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.ExternalModuleReference:
const externalModuleReference = node;
handleNode(externalModuleReference.expression, file, sourceFile);
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);
break;
case typescript_1.default.SyntaxKind.JsxSelfClosingElement:
const jsxSelfClosingElement = node;
handleNode(jsxSelfClosingElement.attributes, file, sourceFile);
handleNode(jsxSelfClosingElement.tagName, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.JsxOpeningElement:
const jsxOpeningElement = node;
handleNode(jsxOpeningElement.attributes, file, sourceFile);
handleNode(jsxOpeningElement.tagName, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.JsxClosingElement:
const jsxClosingElement = node;
handleNode(jsxClosingElement.tagName, file, sourceFile);
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);
break;
case typescript_1.default.SyntaxKind.JsxOpeningFragment:
break;
case typescript_1.default.SyntaxKind.JsxClosingFragment:
break;
case typescript_1.default.SyntaxKind.JsxAttribute:
const jsxAttribute = node;
handleNode(jsxAttribute.name, file, sourceFile);
handleNode(jsxAttribute.initializer, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.JsxAttributes:
const jsxAttributes = node;
handleNodes(jsxAttributes.properties, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.JsxSpreadAttribute:
const jsxSpreadAttribute = node;
handleNode(jsxSpreadAttribute.name, file, sourceFile);
handleNode(jsxSpreadAttribute.expression, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.JsxExpression:
const jsxExpression = node;
handleNode(jsxExpression.dotDotDotToken, file, sourceFile);
handleNode(jsxExpression.expression, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.CaseClause:
const caseClause = node;
handleNodes(caseClause.statements, file, sourceFile);
handleNode(caseClause.expression, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.DefaultClause:
const defaultClause = node;
handleNodes(defaultClause.statements, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.HeritageClause:
const heritageClause = node;
handleNodes(heritageClause.types, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.CatchClause:
const catchClause = node;
handleNode(catchClause.variableDeclaration, file, sourceFile);
handleNode(catchClause.block, file, sourceFile);
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);
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);
break;
case typescript_1.default.SyntaxKind.SpreadAssignment:
const spreadAssignment = node;
handleNode(spreadAssignment.name, file, sourceFile);
handleNode(spreadAssignment.expression, file, sourceFile);
break;
case typescript_1.default.SyntaxKind.EnumMember:
case typescript_1.default.SyntaxKind.SourceFile:
case typescript_1.default.SyntaxKind.Bundle:
case typescript_1.default.SyntaxKind.JSDocTypeExpression:
case typescript_1.default.SyntaxKind.JSDocAllType:
case typescript_1.default.SyntaxKind.JSDocUnknownType:
case typescript_1.default.SyntaxKind.JSDocNullableType:
case typescript_1.default.SyntaxKind.JSDocNonNullableType:
case typescript_1.default.SyntaxKind.JSDocOptionalType:
case typescript_1.default.SyntaxKind.JSDocFunctionType:
case typescript_1.default.SyntaxKind.JSDocVariadicType:
case typescript_1.default.SyntaxKind.JSDocComment:
case typescript_1.default.SyntaxKind.JSDocTag:
case typescript_1.default.SyntaxKind.JSDocAugmentsTag:
case typescript_1.default.SyntaxKind.JSDocClassTag:
case typescript_1.default.SyntaxKind.JSDocParameterTag:
case typescript_1.default.SyntaxKind.JSDocReturnTag:
case typescript_1.default.SyntaxKind.JSDocTypeTag:
case typescript_1.default.SyntaxKind.JSDocTemplateTag:
case typescript_1.default.SyntaxKind.JSDocTypedefTag:
case typescript_1.default.SyntaxKind.JSDocPropertyTag:
case typescript_1.default.SyntaxKind.JSDocTypeLiteral:
case typescript_1.default.SyntaxKind.SyntaxList:
case typescript_1.default.SyntaxKind.NotEmittedStatement:
case typescript_1.default.SyntaxKind.PartiallyEmittedExpression:
case typescript_1.default.SyntaxKind.CommaListExpression:
case typescript_1.default.SyntaxKind.MergeDeclarationMarker:
case typescript_1.default.SyntaxKind.EndOfDeclarationMarker:
case typescript_1.default.SyntaxKind.Count:
break;
default:
console.log(`warning: unhandled node kind: ${node.kind}`);
}
}
for (const sourceFile of program.getSourceFiles()) {
let file = sourceFile.fileName;
if (!file.includes('node_modules')) {
file = path.relative(process.cwd(), file);
sourceFile.forEachChild(node => {
handleNode(node, file, sourceFile);
});
}
}
const { correctCount, totalCount } = await core_1.lint(argv.p || argv.project || '.', argv.detail, argv.debug);
const percent = Math.round(100 * correctCount / totalCount);

@@ -880,0 +24,0 @@ console.log(`${correctCount} / ${totalCount} ${percent}%`);

{
"name": "type-coverage",
"version": "1.2.1",
"version": "1.3.0-alpha.0",
"description": "A CLI tool to check type coverage for typescript code",
"main": "index.js",
"main": "dist/core.js",
"types": "dist/core.d.ts",
"repository": "https://github.com/plantain-00/type-coverage.git",

@@ -10,11 +11,11 @@ "author": "york yao <yaoao12306@outlook.com>",

"devDependencies": {
"@commitlint/cli": "7.1.2",
"@commitlint/cli": "7.2.1",
"@commitlint/config-conventional": "7.1.2",
"@types/glob": "7.1.1",
"@types/jasmine": "2.8.8",
"@types/jasmine": "2.8.9",
"@types/minimist": "1.2.0",
"@types/node": "10.11.3",
"@types/node": "10.12.0",
"clean-release": "2.7.0",
"clean-scripts": "1.9.2",
"jasmine": "3.2.0",
"jasmine": "3.3.0",
"markdownlint-cli": "0.13.0",

@@ -32,3 +33,3 @@ "no-unused-export": "1.6.0",

"tslib": "1.9.3",
"typescript": "3.1.1"
"typescript": "3.1.3"
},

@@ -35,0 +36,0 @@ "scripts": {

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc