type-coverage
Advanced tools
Comparing version 1.8.0 to 1.9.0
@@ -6,4 +6,5 @@ "use strict"; | ||
const path = tslib_1.__importStar(require("path")); | ||
const utils = tslib_1.__importStar(require("tsutils/util")); | ||
const tsconfig_1 = require("./tsconfig"); | ||
// tslint:disable-next-line:no-big-function | ||
// tslint:disable-next-line:no-big-function cognitive-complexity | ||
async function lint(project, detail, debug, files, oldProgram, strict = false) { | ||
@@ -22,4 +23,8 @@ const { configFilePath, dirname } = tsconfig_1.getTsConfigFilePath(project); | ||
let anys = []; | ||
function collectAny(node, file, sourceFile) { | ||
const ingoreMap = {}; | ||
function collectAny(node, file, sourceFile, type) { | ||
const { line, character } = typescript_1.default.getLineAndCharacterOfPosition(sourceFile, node.getStart(sourceFile)); | ||
if (ingoreMap[file] && ingoreMap[file].has(line)) { | ||
return false; | ||
} | ||
if (debug) { | ||
@@ -31,2 +36,3 @@ console.log(`type === any: ${file}:${line + 1}:${character + 1}: ${node.getText(sourceFile)}`); | ||
} | ||
return true; | ||
} | ||
@@ -45,3 +51,6 @@ function collectNotAny(node, file, sourceFile, type) { | ||
if (typeIsStrictAny(type, strict)) { | ||
collectAny(node, file, sourceFile); | ||
const success = collectAny(node, file, sourceFile, type); | ||
if (!success) { | ||
collectNotAny(node, file, sourceFile, type); | ||
} | ||
} | ||
@@ -894,4 +903,25 @@ else { | ||
let file = sourceFile.fileName; | ||
if (!file.includes('node_modules') && (!files || files.includes(file))) { | ||
if (!program.isSourceFileDefaultLibrary(sourceFile) | ||
&& !program.isSourceFileFromExternalLibrary(sourceFile) | ||
&& (!files || files.includes(file))) { | ||
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); | ||
} | ||
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 => { | ||
@@ -898,0 +928,0 @@ handleNode(node, file, sourceFile); |
{ | ||
"name": "type-coverage", | ||
"version": "1.8.0", | ||
"version": "1.9.0", | ||
"description": "A CLI tool to check type coverage for typescript code", | ||
@@ -32,2 +32,3 @@ "main": "dist/core.js", | ||
"tslib": "1", | ||
"tsutils": "3", | ||
"typescript": "2 || 3" | ||
@@ -34,0 +35,0 @@ }, |
@@ -41,2 +41,13 @@ # type-coverage | ||
## ingore line | ||
Use `type-coverage:ignore-next-line` or `type-coverage:ignore-line` in comment(`//` or `/* */`) to ignore `any` in a line. | ||
```ts | ||
try { | ||
// type-coverage:ignore-next-line | ||
} catch (error) { // type-coverage:ignore-line | ||
} | ||
``` | ||
## vscode plugin | ||
@@ -43,0 +54,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
66673
1135
69
5
+ Addedtsutils@3
+ Addedtsutils@3.21.0(transitive)