Skip to content

Adding a Language

Michael L. McKnight edited this page Dec 5, 2026 · 1 revision

Adding a Language

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.

  1. Register the language in code_cleaner/core/base.py: add a Language enum member and extensions to EXTENSION_MAP. --language choices come from the enum automatically. Also add it to .pre-commit-hooks.yaml types_or if pre-commit knows the type.
  2. Parser (code_cleaner/languages/<lang>_parser.py): subclass LanguageParser and implement parse, get_functions, and get_classes. It must never raise on bad input.
  3. Analyzer (code_cleaner/languages/<lang>_analyzer.py): subclass LanguageAnalyzer and implement the five tiers (syntax, logic, performance, security, architecture). Give new rules an explicit rule_id. Opinion rules are INFO and only run when self.config.style_enabled(...) is true. Pattern-only matches stay below CRITICAL unless anchored to a dangerous call. Keep analysis linear in file size.
  4. Register the analyzer in code_cleaner/code_cleaner.py (_ANALYZERS). AI-mistake checks then run automatically.
  5. Optional: tree-sitter — add the grammar wheel, set TS_LANG, describe a LangSpec in core/ts_specs.py. The engine then provides function spans, complexity, syntax errors and taint tracking.
  6. Optional: fallback taint — add an entry to CONFIG in core/taint_fallback.py.
  7. Tests and docs — samples in tests/test_code_cleaner.py and tests/test_all_languages.py; tree-sitter and taint cases in tests/test_v12.py. Run python scripts/gen_rules_doc.py and 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.

Clone this wiki locally