TypeScript
Reference for which tree-sitter nodes pretender tracks for TypeScript files,
how each contributes to pretender check metrics, and known measurement gaps.
Consult this page when tuning thresholds or diagnosing unexpected scores.
Overview
Analyses .ts, .tsx, .mts, and .cts files using a tree-sitter grammar.
Identical branch and call tracking to the JavaScript adapter; type annotations
and generic type arguments are captured but carry no metric weight.
Tracked nodes
| Tree-sitter node | Capture | Metric impact |
|---|---|---|
function_declaration | @function.definition | Defines a metric scope |
variable_declarator with arrow_function | @function.definition | Defines a metric scope |
method_definition | @function.definition | Defines a metric scope |
if_statement | @branch.if | +1 cyclomatic, +1 cognitive |
switch_case | @branch.if | +1 cyclomatic, +1 cognitive |
for_statement | @branch.loop | +1 cyclomatic, +1 cognitive |
for_in_statement | @branch.loop | +1 cyclomatic, +1 cognitive |
while_statement | @branch.loop | +1 cyclomatic, +1 cognitive |
do_statement | @branch.loop | +1 cyclomatic, +1 cognitive |
catch_clause | @branch.catch | +1 cyclomatic, +1 cognitive |
ternary_expression | @branch.ternary | +1 cyclomatic, +1 cognitive |
binary_expression "&&" | @branch.logical.and | +1 cyclomatic, +1 cognitive |
binary_expression `“ | “` | |
call_expression | @call | +1 ABC C-count |
assignment_expression | @assign | +1 ABC A-count |
augmented_assignment_expression | @assign | +1 ABC A-count |
variable_declarator (with value) | @assign | +1 ABC A-count |
type_annotation | @type.annotation | None |
type_arguments | @type.generic | None |
Assertion patterns
Same as JavaScript:
| Pattern | Matches |
|---|---|
^assert$ | assert(...) |
^assert[A-Z] | assertEqual(...), etc. |
^expect$ | Jest / Vitest expect(...) |
^it$ | it('...', ...) test blocks |
^test$ | test('...', ...) blocks |
^describe$ | describe('...', ...) blocks |
Quirks and limitations
- Type-only constructs (
interface,typealiases,enumdeclarations) are not tracked as function scopes. - Type guards (
if (x instanceof Y)) are counted as regularif_statementbranches — no special handling. ??(nullish coalescing) and?.(optional chaining) are not tracked as branches.- Decorators on classes and methods do not contribute to complexity.
- TypeScript-specific syntax uses the same tree-sitter grammar revision as
JavaScript (
.tsxfiles are parsed as TSX).
Known unsupported metrics
min_assertions— Not implemented yet:metrics.scmhas no@assert.*capture, so unit assertion totals are always 0 (the[assertions]patterns serve rule scopes only). No ticket filed yet.- Nesting depth — Not implemented yet: the engine increments nesting
only inside
block-kind nodes, but tree-sitter-typescript wraps bodies instatement_block, sonesting_maxstays 0. No ticket filed yet.
Example output
src/api.ts cyclomatic=6 cognitive=8 function_lines=31 params=2
src/components/Form.tsx cyclomatic=4 cognitive=5 function_lines=22 params=1