@tryinget/crap4ts
v0.1.0
Published
CRAP metric calculator for TypeScript and JavaScript using the TypeScript compiler API.
Readme
summary: "Package README for crap4ts, the TypeScript/JavaScript CRAP metric tool." read_when:
- "You are using crap4ts from the monorepo"
- "You need package-level CLI behavior or output semantics" type: "reference"
crap4ts
Published as @tryinget/crap4ts.
A TypeScript/JavaScript CRAP metric calculator built on the TypeScript compiler API.
crap4ts can be used standalone for hotspot ranking, but it is also the intended companion package for @tryinget/ts-mutate.
The repo keeps them as separate packages so teams can adopt hotspot analysis without pulling in mutation testing, while the quality receipt still lets them operate hand in hand.
Features
- Parses
.ts,.tsx,.js,.jsx - Extracts named functions and methods with file and line span
- Computes cyclomatic complexity per function
- Parses LCOV (
lcov.info) - Maps line coverage back to function ranges
- Calculates CRAP scores
- Sorts output by highest CRAP first
- Supports path-fragment filtering
Usage
npm exec --yes --package @tryinget/crap4ts -- crap4ts
npm exec --yes --package @tryinget/crap4ts -- crap4ts --src src --lcov coverage/lcov.info
npm exec --yes --package @tryinget/crap4ts -- crap4ts --src src --filter auth/
npm exec --yes --package @tryinget/crap4ts -- crap4ts --jsonCoverage-aware workflow
Generate source-mapped LCOV from the package test suite:
npm run coverage --workspace packages/crap4tsThen run crap4ts against the package-local LCOV:
npm exec --workspace packages/crap4ts -- crap4ts --cwd packages/crap4ts
npm exec --workspace packages/crap4ts -- crap4ts --cwd packages/crap4ts --lcov coverage/lcov.info --jsonFor a repo-level hotspot receipt that also prints the next ts-mutate command, run:
just quality crap4ts
# npm equivalent
npm run quality -- --package crap4tsThat is the intended companion workflow: use crap4ts to rank hotspots, then hand the suggested file to ts-mutate.
CLI options
--src <path>: source root or file. Repeatable. Defaults tosrc--lcov <path>: explicit LCOV file. If omitted, the tool triescoverage/lcov.info,target/coverage/lcov.info, thenlcov.info--filter <fragment>: path fragment filter. Repeatable--json: machine-readable output--cwd <path>: override working directory--help: print usage
Output columns
Function: inferred function or method nameFile: path relative to the working directoryLines: start-end line spanCC: cyclomatic complexityCov%: line coverage percent from LCOVCRAP: calculated CRAP score
