Skip to content

Architecture

Four modules around the sloc line counter.

Modules

  • config.ts: defines LineLimitsConfig and DEFAULTS; loads the JSON config with readFileSync and merges partial configs over the defaults; missing or malformed files yield the defaults.
  • walker.ts: walks each scan directory recursively with readdirSync; prunes directories named in skipDirs (default node_modules, .git, dist, coverage); keeps only .ts, .tsx, .js, .jsx, and .mjs files not matched by an exclude pattern.
  • check-line-limits.ts: reads each walked file and counts SLOC through the CJS sloc package (default import, typed by @types/sloc); classifies each file as ok, warn, or error.
  • cli.ts: parses --config, --warn, --error, and --json; writes warnings and errors to stderr, success messages to stdout; exits 1 when any file reaches the error threshold.

index.ts re-exports the public API: checkLineLimits, loadConfig, and the three result and config types. The CLI is a separate entry point.

Data Flow

CLI args -> loadConfig -> walkDir (per scanDir) -> readFileSync -> sloc -> classify -> output -> exit code

Design Decisions

  • One runtime dependency (sloc); walking, exclusion matching, and IO use node:fs and node:path only.
  • Filesystem operations are synchronous.
  • Unreadable files and nonexistent scan directories are skipped silently.
  • Exclusion patterns match suffixes (**/*.d.ts), directory prefixes (dist/**), and infixes (**/*.generated.*); see isExcluded.