Skip to content

Commit

Permalink
feat: the target can be in package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
yorkyao committed Nov 1, 2018
1 parent 0f94b02 commit 6c7e4d7
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 7 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This tool will check type of all identifiers, `the code coverage` = `the count o
[![Build Status: Windows](https://ci.appveyor.com/api/projects/status/github/plantain-00/type-coverage?branch=master&svg=true)](https://ci.appveyor.com/project/plantain-00/type-coverage/branch/master)
[![npm version](https://badge.fury.io/js/type-coverage.svg)](https://badge.fury.io/js/type-coverage)
[![Downloads](https://img.shields.io/npm/dm/type-coverage.svg)](https://www.npmjs.com/package/type-coverage)
![](https://img.shields.io/badge/dynamic/json.svg?label=type-coverage&prefix=%E2%89%A5&suffix=%&query=$.typeCoverage.atLeast&uri=https%3A%2F%2Fraw.githubusercontent.com%2Fplantain-00%2Ftype-coverage%2Fmaster%2Fpackage.json)

## install

Expand All @@ -27,3 +28,11 @@ name | type | description
--detail | boolean? | show detail
--at-least | number? | fail if coverage rate < this value
--debug | boolean? | show debug info

## config in package.json

```json
"typeCoverage": {
"atLeast": 99 // same as --at-least
},
```
2 changes: 1 addition & 1 deletion clean-scripts.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {
build: [
'rimraf dist/',
'tsc -p src/',
'node dist/index.js -p src --detail --at-least 99 --supressError > spec/result.txt'
'node dist/index.js -p src --detail --supressError > spec/result.txt'
],
lint: {
ts: `tslint ${tsFiles}`,
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
"test": "clean-scripts test",
"fix": "clean-scripts fix"
},
"typeCoverage": {
"atLeast": 99
},
"bin": {
"type-coverage": "bin/type-coverage"
}
Expand Down
8 changes: 4 additions & 4 deletions spec/result.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ src/index.ts:23:62: p
src/index.ts:23:72: project
src/index.ts:23:93: detail
src/index.ts:23:106: debug
src/index.ts:38:4: error
src/index.ts:39:7: error
src/index.ts:42:17: error
3148 / 3161 99.59%
src/index.ts:44:4: error
src/index.ts:45:7: error
src/index.ts:48:17: error
3160 / 3173 99.59%
type-coverage success.
8 changes: 7 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ async function executeCommandLine() {
const percent = Math.round(10000 * correctCount / totalCount) / 100
console.log(`${correctCount} / ${totalCount} ${percent.toFixed(2)}%`)

const atLeast: number | undefined = argv['at-least']
let atLeast: number | undefined
if (packageJson.typeCoverage && packageJson.typeCoverage.atLeast) {
atLeast = packageJson.typeCoverage.atLeast
}
if (argv['at-least']) {
atLeast = argv['at-least']
}
if (atLeast && percent < atLeast) {
throw new Error(`The type coverage rate(${percent.toFixed(2)}%) is lower than the target(${atLeast}%). \nYou can add '--detail' or use VSCode plugin to show detailed informations.`)
}
Expand Down
5 changes: 4 additions & 1 deletion src/lib.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
declare module '*.json' {
export const version: string
export const version: string
export const typeCoverage: {
atLeast?: number
}?
}

0 comments on commit 6c7e4d7

Please sign in to comment.