Codemetrica is now rewritten for the Node.js + TypeScript ecosystem. It analyzes Python source code today, with Java adapter scaffolding in place, and computes metrics and smells for files, classes, and methods.
- Tree-sitter powered parsing for Python source code, with Java support planned through adapters
- File, class, and method metric calculation
- Code smell detection (file/class/method level)
- Strongly typed TypeScript API
- Test setup with Vitest
npm installimport { CodemetricaParser, PythonSource, FileMetric } from "codemetrica";
const parser = new CodemetricaParser("python");
const source = parser.parseFromFile("examples/complex_file.py") as PythonSource;
const fileMetric = new FileMetric(source);
console.log(fileMetric.getLoc());
for (const cls of source.getClasses()) {
console.log(cls.getName());
for (const method of cls.getMethods()) {
console.log(method.getName());
}
}npm run build: compile TypeScript todist/npm run dev: run the example scriptnpm run test: run test suite oncenpm run test:watch: run tests in watch modenpm run lint: run TypeScript type checks
src/parser.ts: parser entrypoint and language dispatchsrc/entities/*: base abstractions for source/class/function nodessrc/python/entities/*: Python-specific AST wrapperssrc/python/metric/*: Python metricssrc/python/smell/*: Python smell detectorstests/*: Vitest tests
The previous Python implementation remains in the repository for reference during migration. The active implementation is now the TypeScript code in src/.
MIT