🤖 Merge PR #59510 Added types for lcov-parse by @roccivic

This commit is contained in:
Rouslan Placella
2022-03-28 21:32:32 +01:00
committed by GitHub
parent fc45bdb9b2
commit 679074ac40
4 changed files with 147 additions and 0 deletions

85
types/lcov-parse/index.d.ts vendored Normal file
View File

@@ -0,0 +1,85 @@
// Type definitions for lcov-parse 1.0
// Project: https://github.com/davglass/lcov-parse
// Definitions by: Rouslan Placella <https://github.com/roccivic>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare namespace parse {
/**
* Line coverage detail
*/
interface LcovLine {
line: number;
hit: number;
}
/**
* Function coverage detail
*/
interface LcovFunc {
name: string;
line: number;
hit: number;
}
/**
* Branch coverage detail
*/
interface LcovBranch {
line: number;
block: number;
branch: number;
taken: number;
}
/**
* Code coverage for lines, functions or branches in a file
*/
interface LcovPart<T> {
hit: number;
found: number;
details: T[];
}
/**
* Code coverage for a file
*/
interface LcovFile {
title: string;
file: string;
lines: LcovPart<LcovLine>;
functions: LcovPart<LcovFunc>;
branches: LcovPart<LcovBranch>;
}
/**
* Parses an LCOV code coverage string:
* ```
* parse(lcovString, function(err, data) {
* //process the data here
* });
* ```
*
* @param str LCOV string to parse
* @param cb Callback: first arg is `null` or error string,
* second arg is parsed data or `undefined` if an error occurred
*/
function source(str: string, cb: (err: null | string, data: LcovFile[] | undefined) => void): void;
}
/**
* Parses an LCOV code coverage file:
* ```
* parse('./path/to/file.info', function(err, data) {
* //process the data here
* });
* ```
*
* The first argument can also be an LCOV string to parse:
* ```
* parse(lcovString, function(err, data) {
* //process the data here
* });
* ```
*
* @param file Path to the LCOV file or string to parse
* @param cb Callback: first arg is `null` or error string,
* second arg is parsed data or `undefined` if an error occurred
*/
declare function parse(file: string, cb: (err: null | string, data: parse.LcovFile[] | undefined) => void): void;
export = parse;

View File

@@ -0,0 +1,38 @@
import parse = require('lcov-parse');
const sample = `TN:
SF:src/most.js
FN:1,sum
FN:5,product
FNF:2
FNH:1
FNDA:1,sum
FNDA:0,product
DA:2,1
DA:6,0
DA:9,1
LF:3
LH:2
BRF:0
BRH:0
end_of_record`;
parse('', (err, data) => {
err; // $ExpectedType string
data; // $ExpectedType undefined
});
parse(sample, (err, data) => {
err; // $ExpectedType null
data; // $ExpectedType LcovFile[]
});
parse.source('', (err, data) => {
err; // $ExpectedType string
data; // $ExpectedType undefined
});
parse.source(sample, (err, data) => {
err; // $ExpectedType null
data; // $ExpectedType LcovFile[]
});

View File

@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"lcov-parse-tests.ts"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "@definitelytyped/dtslint/dt.json" }