Skip to content

Commit

Permalink
feat: support check specific files
Browse files Browse the repository at this point in the history
  • Loading branch information
plantain-00 committed Nov 11, 2022
1 parent f0afc7e commit 9bf6ac8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -55,6 +55,7 @@ name | type | description
`--history-file` | string? | file name where history is saved(Added in `v2.18`)
`--no-detail-when-failed` | boolean? | not show detail message when the CLI failed(Added in `v2.19`)(Use `--no-detail-when-failed=true` to enable it <https://github.com/plantain-00/type-coverage/issues/113>)
`--report-semantic-error` | boolean? | report typescript semantic error(Added in `v2.22`)
`-- file1.ts file2.ts ...` | string[]? | only checks these files, useful for usage with tools like `lint-staged`(Added in `v2.23`)

### strict mode

Expand Down
5 changes: 4 additions & 1 deletion packages/cli/src/index.ts
Expand Up @@ -16,7 +16,7 @@ function showToolVersion() {
}

function printHelp() {
console.log(`type-coverage [options]
console.log(`type-coverage [options] [-- file1.ts file2.ts ...]
-p, --project string? tell the CLI where is the tsconfig.json
--detail boolean? show detail
Expand All @@ -41,6 +41,7 @@ function printHelp() {
--history-file string? file name where history is saved
--no-detail-when-failed boolean? not show detail message when the CLI failed
--report-semantic-error boolean? report typescript semantic error
-- file1.ts file2.ts ... string[]? only checks these files, useful for usage with tools like lint-staged
`)
}

Expand All @@ -56,6 +57,7 @@ interface BaseArgs {
update: boolean
}
interface CliArgs extends BaseArgs {
'--': string[]
p: string
v: boolean
version: boolean
Expand Down Expand Up @@ -160,6 +162,7 @@ async function executeCommandLine() {
ignoreObject,
ignoreEmptyType,
reportSemanticError,
files: argv['--'].length > 0 ? argv['--'] : undefined,
});

const percent = Math.floor(10000 * correctCount / totalCount) / 100
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/core.ts
Expand Up @@ -37,13 +37,16 @@ export async function lint(project: string, options?: Partial<LintOptions>) {
: undefined
for (const sourceFile of program.getSourceFiles()) {
let file = sourceFile.fileName
if (!file.includes('node_modules') && (!lintOptions.files || lintOptions.files.includes(file))) {
if (!file.includes('node_modules')) {
if (!lintOptions.absolutePath) {
file = path.relative(process.cwd(), file)
if (file.startsWith('..')) {
continue
}
}
if (lintOptions.files && !lintOptions.files.includes(file)) {
continue
}
if (ignoreFileGlobs && ignoreFileGlobs.some((f) => minimatch(file, f))) {
continue
}
Expand Down

0 comments on commit 9bf6ac8

Please sign in to comment.