Repository navigation
Adding a Language
Michael L. McKnight edited this page Dec 5, 2026
·
1 revision
Canonical source: docs/adding-a-language.md. Design constraints: docs/architecture.md and CONTRIBUTING.md.
A language needs a parser, an analyzer, and three registrations. tree-sitter support and taint tracking are optional extras on top.
-
Register the language in
code_cleaner/core/base.py: add aLanguageenum member and extensions toEXTENSION_MAP.--languagechoices come from the enum automatically. Also add it to.pre-commit-hooks.yamltypes_orif pre-commit knows the type. -
Parser (
code_cleaner/languages/<lang>_parser.py): subclassLanguageParserand implementparse,get_functions, andget_classes. It must never raise on bad input. -
Analyzer (
code_cleaner/languages/<lang>_analyzer.py): subclassLanguageAnalyzerand implement the five tiers (syntax, logic, performance, security, architecture). Give new rules an explicitrule_id. Opinion rules are INFO and only run whenself.config.style_enabled(...)is true. Pattern-only matches stay below CRITICAL unless anchored to a dangerous call. Keep analysis linear in file size. -
Register the analyzer in
code_cleaner/code_cleaner.py(_ANALYZERS). AI-mistake checks then run automatically. -
Optional: tree-sitter — add the grammar wheel, set
TS_LANG, describe aLangSpecincore/ts_specs.py. The engine then provides function spans, complexity, syntax errors and taint tracking. -
Optional: fallback taint — add an entry to
CONFIGincore/taint_fallback.py. -
Tests and docs — samples in
tests/test_code_cleaner.pyandtests/test_all_languages.py; tree-sitter and taint cases intests/test_v12.py. Runpython scripts/gen_rules_doc.pyand update the languages table in the README.
The core must stay free of third-party dependencies. New parsers go into an optional extra, with a fallback. See the canonical doc for code sketches and the Kotlin-shaped example.
Created by ML / ML Innovations Research Lab. Korg (AI assistant, Grok Bot), contributor. · Repository · Apache License 2.0
Start here
Using Code Cleaner
Contributing