type-coverage-core
Advanced tools
Comparing version 2.10.0 to 2.12.0
@@ -13,1 +13,13 @@ import ts from 'typescript'; | ||
}>; | ||
/** | ||
* @public | ||
*/ | ||
export declare function lintSync(compilerOptions: ts.CompilerOptions, rootNames: string[], options?: Partial<LintOptions>): { | ||
correctCount: number; | ||
totalCount: number; | ||
anys: (AnyInfo & { | ||
sourceFile: ts.SourceFile; | ||
})[]; | ||
program: ts.Program; | ||
fileCounts: Map<string, Pick<FileTypeCheckResult, "correctCount" | "totalCount">>; | ||
}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.lint = void 0; | ||
exports.lintSync = exports.lint = void 0; | ||
const tslib_1 = require("tslib"); | ||
@@ -138,1 +138,72 @@ const typescript_1 = tslib_1.__importDefault(require("typescript")); | ||
}; | ||
/** | ||
* @public | ||
*/ | ||
function lintSync(compilerOptions, rootNames, options) { | ||
const lintOptions = { ...defaultLintOptions, ...options }; | ||
const program = typescript_1.default.createProgram(rootNames, compilerOptions, undefined, lintOptions.oldProgram); | ||
const checker = program.getTypeChecker(); | ||
const allFiles = new Set(); | ||
const sourceFileInfos = []; | ||
const ignoreFileGlobs = lintOptions.ignoreFiles | ||
? (typeof lintOptions.ignoreFiles === 'string' | ||
? [lintOptions.ignoreFiles] | ||
: lintOptions.ignoreFiles) | ||
: undefined; | ||
for (const sourceFile of program.getSourceFiles()) { | ||
let file = sourceFile.fileName; | ||
if (!file.includes('node_modules') && (!lintOptions.files || lintOptions.files.includes(file))) { | ||
if (!lintOptions.absolutePath) { | ||
file = path.relative(process.cwd(), file); | ||
if (file.startsWith('..')) { | ||
continue; | ||
} | ||
} | ||
if (ignoreFileGlobs && ignoreFileGlobs.some((f) => minimatch_1.default(file, f))) { | ||
continue; | ||
} | ||
allFiles.add(file); | ||
sourceFileInfos.push({ | ||
file, | ||
sourceFile, | ||
}); | ||
} | ||
} | ||
let correctCount = 0; | ||
let totalCount = 0; | ||
const anys = []; | ||
const fileCounts = new Map(); | ||
for (const { sourceFile, file } of sourceFileInfos) { | ||
const ingoreMap = ignore_1.collectIgnoreMap(sourceFile, file); | ||
const context = { | ||
file, | ||
sourceFile, | ||
typeCheckResult: { | ||
correctCount: 0, | ||
totalCount: 0, | ||
anys: [] | ||
}, | ||
ignoreCatch: lintOptions.ignoreCatch, | ||
catchVariables: {}, | ||
debug: lintOptions.debug, | ||
strict: lintOptions.strict, | ||
processAny: lintOptions.processAny, | ||
checker, | ||
ingoreMap, | ||
}; | ||
sourceFile.forEachChild(node => { | ||
checker_1.checkNode(node, context); | ||
}); | ||
correctCount += context.typeCheckResult.correctCount; | ||
totalCount += context.typeCheckResult.totalCount; | ||
anys.push(...context.typeCheckResult.anys.map((a) => ({ file, ...a, sourceFile }))); | ||
if (lintOptions.fileCounts) { | ||
fileCounts.set(file, { | ||
correctCount: context.typeCheckResult.correctCount, | ||
totalCount: context.typeCheckResult.totalCount | ||
}); | ||
} | ||
} | ||
return { correctCount, totalCount, anys, program, fileCounts }; | ||
} | ||
exports.lintSync = lintSync; |
@@ -58,8 +58,10 @@ import ts from 'typescript'; | ||
} | ||
export interface SourceFileInfo { | ||
file: string; | ||
sourceFile: ts.SourceFile; | ||
export interface SourceFileInfo extends SourceFileInfoWithoutCache { | ||
hash: string; | ||
cache?: TypeCheckCache; | ||
} | ||
export interface SourceFileInfoWithoutCache { | ||
file: string; | ||
sourceFile: ts.SourceFile; | ||
} | ||
export {}; |
{ | ||
"name": "type-coverage-core", | ||
"version": "2.10.0", | ||
"version": "2.12.0", | ||
"description": "A library to check type coverage for typescript code", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
49468
1246