Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

type-coverage-core

Package Overview
Dependencies
Maintainers
1
Versions
78
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

type-coverage-core - npm Package Compare versions

Comparing version 2.15.1 to 2.16.0

24

dist/checker.js

@@ -47,4 +47,4 @@ "use strict";

context.typeCheckResult.totalCount++;
if (types.every((t) => typeIsStrictAny(t, context.strict))) {
const kind = types.every((t) => typeIsStrictAny(t, false)) ? 1 /* any */ : 2 /* containsAny */;
if (types.every((t) => typeIsAnyOrInTypeArguments(t, context.strict && !context.ignoreNested))) {
const kind = types.every((t) => typeIsAnyOrInTypeArguments(t, false)) ? 1 /* any */ : 2 /* containsAny */;
const success = collectAny(node, context, kind);

@@ -60,10 +60,10 @@ if (!success) {

}
function typeIsStrictAny(type, strict) {
function typeIsAnyOrInTypeArguments(type, anyCanBeInTypeArguments) {
if (type.flags === ts.TypeFlags.Any) {
return type.intrinsicName === 'any';
}
if (strict && type.flags === ts.TypeFlags.Object) {
if (anyCanBeInTypeArguments && type.flags === ts.TypeFlags.Object) {
const typeArguments = type.typeArguments;
if (typeArguments) {
return typeArguments.some((typeArgument) => typeIsStrictAny(typeArgument, strict));
return typeArguments.some((typeArgument) => typeIsAnyOrInTypeArguments(typeArgument, anyCanBeInTypeArguments));
}

@@ -94,6 +94,16 @@ }

}
const isTypeAssertionExpression = ts.isTypeAssertionExpression || ts.isTypeAssertion;
function checkTypeAssertion(node, context, kind) {
if (context.strict) {
if (kind === 5 /* unsafeNonNull */ && context.ignoreNonNullAssertion) {
return;
}
if (kind === 3 /* unsafeAs */ && context.ignoreAsAssertion) {
return;
}
if (kind === 4 /* unsafeTypeAssertion */ && context.ignoreTypeAssertion) {
return;
}
// include `foo as any` and `<any>foo`
if ((ts.isAsExpression(node) || ts.isTypeAssertion(node)) && node.type.kind !== ts.SyntaxKind.AnyKeyword) {
if ((ts.isAsExpression(node) || isTypeAssertionExpression(node)) && node.type.kind !== ts.SyntaxKind.AnyKeyword) {
// exclude `foo as const` and `<const>foo`

@@ -327,3 +337,3 @@ if (ts.isTypeReferenceNode(node.type) && node.type.getText() === 'const') {

}
if (ts.isTypeAssertion(node)) {
if (isTypeAssertionExpression(node)) {
checkTypeAssertion(node, context, 4 /* unsafeTypeAssertion */);

@@ -330,0 +340,0 @@ checkNode(node.expression, context);

@@ -93,2 +93,6 @@ "use strict";

ingoreMap,
ignoreNested: lintOptions.ignoreNested,
ignoreAsAssertion: lintOptions.ignoreAsAssertion,
ignoreTypeAssertion: lintOptions.ignoreTypeAssertion,
ignoreNonNullAssertion: lintOptions.ignoreNonNullAssertion,
};

@@ -139,2 +143,6 @@ sourceFile.forEachChild(node => {

fileCounts: false,
ignoreNested: false,
ignoreAsAssertion: false,
ignoreTypeAssertion: false,
ignoreNonNullAssertion: false,
};

@@ -196,2 +204,6 @@ /**

ingoreMap,
ignoreNested: lintOptions.ignoreNested,
ignoreAsAssertion: lintOptions.ignoreAsAssertion,
ignoreTypeAssertion: lintOptions.ignoreTypeAssertion,
ignoreNonNullAssertion: lintOptions.ignoreNonNullAssertion,
};

@@ -198,0 +210,0 @@ sourceFile.forEachChild(node => {

@@ -33,24 +33,38 @@ import * as ts from 'typescript';

export declare type ProccessAny = (node: ts.Node, context: FileContext) => boolean;
export interface LintOptions {
debug: boolean;
export interface LintOptions extends CommonOptions {
files?: string[];
oldProgram?: ts.Program;
strict: boolean;
enableCache: boolean;
ignoreCatch: boolean;
ignoreFiles?: string | string[];
ignoreUnreadAnys: boolean;
fileCounts: boolean;
absolutePath?: boolean;
}
interface CommonOptions {
debug: boolean;
strict: boolean;
ignoreCatch: boolean;
ignoreUnreadAnys: boolean;
processAny?: ProccessAny;
/**
* Promise<any>
*/
ignoreNested: boolean;
/**
* foo as string
*/
ignoreAsAssertion: boolean;
/**
* <string>foo
*/
ignoreTypeAssertion: boolean;
/**
* foo!
*/
ignoreNonNullAssertion: boolean;
}
export interface FileContext {
export interface FileContext extends CommonOptions {
file: string;
sourceFile: ts.SourceFile;
typeCheckResult: FileTypeCheckResult;
debug: boolean;
strict: boolean;
checker: ts.TypeChecker;
ignoreCatch: boolean;
ignoreUnreadAnys: boolean;
catchVariables: {

@@ -62,3 +76,2 @@ [variable: string]: boolean;

};
processAny?: ProccessAny;
}

@@ -65,0 +78,0 @@ interface TypeCheckCache extends FileTypeCheckResult {

{
"name": "type-coverage-core",
"version": "2.15.1",
"version": "2.16.0",
"description": "A library to check type coverage for typescript code",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

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