Architecture
Four modules around the sloc line counter.
Modules
config.ts: definesLineLimitsConfigandDEFAULTS; loads the JSON config withreadFileSyncand merges partial configs over the defaults; missing or malformed files yield the defaults.walker.ts: walks each scan directory recursively withreaddirSync; prunes directories named inskipDirs(defaultnode_modules,.git,dist,coverage); keeps only.ts,.tsx,.js,.jsx, and.mjsfiles not matched by an exclude pattern.check-line-limits.ts: reads each walked file and counts SLOC through the CJSslocpackage (default import, typed by@types/sloc); classifies each file asok,warn, orerror.cli.ts: parses--config,--warn,--error, and--json; writes warnings and errors to stderr, success messages to stdout; exits1when 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 usenode:fsandnode:pathonly. - 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.*); seeisExcluded.