Rules¶
mcp_zen_of_languages.rules.base_models
¶
Canonical Pydantic models that define the shape of every zen principle.
This module is the single source of truth for the ZenPrinciple /
LanguageZenPrinciples hierarchy. Language rule files (e.g.
languages/python/rules.py) instantiate these models; analyzers,
detectors, and the DetectionPipeline consume them.
Key concepts:
- Each ZenPrinciple pairs a human-readable principle statement with
machine-readable
metrics,detectable_patterns, andviolationsthat drive the detection pipeline. - Severity (1-10) controls violation priority and is persisted into
every
ViolationReport. LanguageZenPrinciplesgroups all principles for a language together with provenance metadata (philosophy, source URL).
Classes¶
SeverityLevel
¶
Bases: int, Enum
Numeric severity scale (1-10) used to rank zen violations.
Levels are grouped into four bands:
- Informational (1-3): Style suggestions with no functional impact.
- Warning (4-6): Likely maintainability or readability concerns.
- Error (7-8): Strong anti-patterns that hinder correctness.
- Critical (9-10): Severe violations requiring immediate attention.
PrincipleCategory
¶
Bases: StrEnum
Taxonomy tag that groups related zen principles.
Analyzers and reporters use these categories to organise output (e.g.
"show all readability violations") and to build per-category coverage
reports. Each ZenPrinciple carries exactly one category.
ViolationSpec
¶
Bases: BaseModel
A single concrete way in which a zen principle can be violated.
Principles may list multiple ViolationSpec entries — each describes
one observable symptom. The id must be stable across releases so
that suppression rules and audit trails remain valid.
| ATTRIBUTE | DESCRIPTION |
|---|---|
id |
Stable, slug-style identifier (e.g.
TYPE:
|
description |
Human-readable explanation of the specific violation.
TYPE:
|
ZenPrinciple
¶
Bases: BaseModel
A single zen principle with its detection rules, metrics, and patterns.
This is the atomic unit of the zen rule system. Each principle carries
enough metadata for the DetectionPipeline to decide what to detect
(detectable_patterns, metrics) and how to report it
(severity, recommended_alternative).
| ATTRIBUTE | DESCRIPTION |
|---|---|
id |
Globally unique identifier following
TYPE:
|
principle |
The idiomatic best-practice statement, written as a short imperative sentence.
TYPE:
|
category |
Taxonomy tag for grouping related principles.
TYPE:
|
severity |
Impact score on a 1-10 scale (9-10 is critical).
TYPE:
|
description |
Paragraph-length explanation of why this principle matters.
TYPE:
|
violations |
Concrete symptoms that indicate a breach of the
principle. Accepts raw strings (auto-slugified) or
TYPE:
|
detectable_patterns |
Regex strings matched against source code by
TYPE:
|
metrics |
Threshold key/value pairs consumed by detectors (e.g.
TYPE:
|
recommended_alternative |
Suggested refactoring or idiom to replace the violating pattern.
TYPE:
|
required_config |
Tool or linter settings that must be active for the principle to be enforceable.
TYPE:
|
See Also
LanguageZenPrinciples — the per-language collection that holds
these principles.
Attributes¶
violation_specs
property
¶
Return the normalised ViolationSpec list for this principle.
| RETURNS | DESCRIPTION |
|---|---|
list[ViolationSpec]
|
list[ViolationSpec]: Deduplicated violation specs, identical to reading |
list[ViolationSpec]
|
after validator processing. |
Functions¶
compiled_patterns
¶
Compile detectable_patterns into re.Pattern objects for reuse.
Invalid regex strings are silently escaped so they behave as literal substring matchers. Returns an empty list when no patterns are defined.
| RETURNS | DESCRIPTION |
|---|---|
list[re.Pattern]
|
list['re.Pattern']: Compiled regex objects, one per entry in |
Source code in src/mcp_zen_of_languages/rules/base_models.py
LanguageZenPrinciples
¶
Bases: BaseModel
The complete set of zen principles for a single programming language.
Each instance records provenance (source document, URL) and holds the
ordered list of ZenPrinciple entries that analyzers iterate over.
| ATTRIBUTE | DESCRIPTION |
|---|---|
language |
Lowercase key used throughout the registry (e.g.
TYPE:
|
name |
Display-friendly language name (e.g.
TYPE:
|
philosophy |
Name of the guiding document or philosophy (e.g.
TYPE:
|
source_text |
Title of the authoritative style guide.
TYPE:
|
source_url |
URL to the upstream style guide or specification.
TYPE:
|
principles |
Ordered list of zen principles for this language.
TYPE:
|
Attributes¶
principle_count
property
¶
Total number of principles registered for this language.
| RETURNS | DESCRIPTION |
|---|---|
int
|
Length of the
TYPE:
|
Functions¶
get_by_id
¶
Look up a principle by its unique ID (e.g. "python-003").
| PARAMETER | DESCRIPTION |
|---|---|
principle_id
|
The
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ZenPrinciple | None
|
ZenPrinciple | None: The matching principle, or |
Source code in src/mcp_zen_of_languages/rules/base_models.py
get_by_category
¶
Filter principles belonging to category.
| PARAMETER | DESCRIPTION |
|---|---|
category
|
The
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[ZenPrinciple]
|
list[ZenPrinciple]: Principles whose |
Source code in src/mcp_zen_of_languages/rules/base_models.py
get_by_severity
¶
Return principles at or above min_severity.
| PARAMETER | DESCRIPTION |
|---|---|
min_severity
|
Inclusive lower bound on the 1-10 severity scale. Default to 7.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[ZenPrinciple]
|
list[ZenPrinciple]: Principles whose |
Source code in src/mcp_zen_of_languages/rules/base_models.py
ViolationReport
¶
Bases: BaseModel
Structured report emitted when a zen principle is violated.
Carries everything a reporter needs: the violated principle's identity, severity, location in source, a human-readable message, and an optional suggested fix.
| ATTRIBUTE | DESCRIPTION |
|---|---|
principle_id |
ID of the violated
TYPE:
|
principle_name |
Display name / statement of the principle.
TYPE:
|
severity |
1-10 severity copied from the principle.
TYPE:
|
category |
Taxonomy tag of the violated principle.
TYPE:
|
location |
Optional
TYPE:
|
message |
One-line human-readable violation description.
TYPE:
|
suggestion |
Recommended refactoring to resolve the violation.
TYPE:
|
code_snippet |
Extract of the offending source code.
TYPE:
|
AnalysisResult
¶
Bases: BaseModel
Aggregate outcome of analysing a source file against zen principles.
Contains the full violation list, a normalized 0-100 score, and any metrics (complexity, LOC, etc.) computed during analysis.
| ATTRIBUTE | DESCRIPTION |
|---|---|
language |
Lowercase language key that was analysed.
TYPE:
|
violations |
Ordered list of
TYPE:
|
overall_score |
Zen score where 100 means no violations.
TYPE:
|
metrics |
Free-form metric dictionary (keys vary by analyzer).
TYPE:
|
summary |
Human-readable prose summarising the analysis.
TYPE:
|
Attributes¶
critical_violations
property
¶
Subset of violations with severity ≥ 9 (critical band).
| RETURNS | DESCRIPTION |
|---|---|
list[ViolationReport]
|
list[ViolationReport]: |
violation_count
property
¶
Total number of violations recorded in this result.
| RETURNS | DESCRIPTION |
|---|---|
int
|
Length of the
TYPE:
|
LanguageSummary
¶
Bases: BaseModel
Lightweight snapshot of a language's presence in the registry.
Used by RegistryStats to avoid serialising the full principle list
when only high-level metadata is needed.
| ATTRIBUTE | DESCRIPTION |
|---|---|
name |
Human-readable language name.
TYPE:
|
principle_count |
How many principles are registered.
TYPE:
|
philosophy |
Core philosophy or guiding document title.
TYPE:
|
source_text |
Name of the upstream style guide (optional).
TYPE:
|
source_url |
URL of the upstream style guide (optional).
TYPE:
|
DetectorConfig
¶
Bases: BaseModel
Language-agnostic configuration bundle passed to individual detectors.
Built by RulesAdapter.get_detector_config or by the
DetectionPipeline from ZenPrinciple.metrics. Detectors
read thresholds and patterns from this model instead of inspecting
raw principle objects, keeping them decoupled from the rule schema.
| ATTRIBUTE | DESCRIPTION |
|---|---|
name |
Detector identifier (e.g.
TYPE:
|
thresholds |
Numeric limits keyed by metric name
(e.g.
TYPE:
|
patterns |
Regex strings the detector should match against source.
TYPE:
|
metadata |
Arbitrary non-numeric configuration values.
TYPE:
|
RegistryStats
¶
Bases: BaseModel
Aggregated statistics across the entire ZEN_REGISTRY.
Constructed via the from_registry classmethod. Useful for
dashboard rendering and health-check endpoints.
| ATTRIBUTE | DESCRIPTION |
|---|---|
total_languages |
Number of languages with registered principles.
TYPE:
|
total_principles |
Sum of principles across all languages.
TYPE:
|
languages |
Per-language
TYPE:
|
Functions¶
from_registry
classmethod
¶
Snapshot the live registry into a serialisable RegistryStats model.
| PARAMETER | DESCRIPTION |
|---|---|
registry
|
The
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RegistryStats
|
'RegistryStats': A fully populated |
Source code in src/mcp_zen_of_languages/rules/base_models.py
Functions¶
get_number_of_principles
¶
Count principles defined for a single language.
| PARAMETER | DESCRIPTION |
|---|---|
language
|
The
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int
|
Number of
TYPE:
|
Source code in src/mcp_zen_of_languages/rules/base_models.py
get_number_of_priniciple
¶
Backward-compatible alias for get_number_of_principles (typo preserved).
| PARAMETER | DESCRIPTION |
|---|---|
language
|
Delegated to
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int
|
Same as
TYPE:
|
Source code in src/mcp_zen_of_languages/rules/base_models.py
get_rule_ids
¶
Collect the unique ZenPrinciple.id values for a language.
| PARAMETER | DESCRIPTION |
|---|---|
language
|
The
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
set[str]
|
set[str]: Set of principle IDs (e.g. |
Source code in src/mcp_zen_of_languages/rules/base_models.py
get_total_principles
¶
Sum principle counts across every language in registry.
| PARAMETER | DESCRIPTION |
|---|---|
registry
|
The
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int
|
Aggregate principle count.
TYPE:
|
Source code in src/mcp_zen_of_languages/rules/base_models.py
get_missing_detector_rules
¶
Identify principle IDs that have no dedicated detector registered.
When explicit_only is True (the default), the generic
RulePatternDetector fallback is ignored — only purpose-built
detectors count as coverage.
| PARAMETER | DESCRIPTION |
|---|---|
language
|
The
TYPE:
|
explicit_only
|
If
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[str]
|
list[str]: Sorted list of principle IDs without detector coverage. |
See Also
get_rule_id_coverage — also reports unknown detector mappings.
Source code in src/mcp_zen_of_languages/rules/base_models.py
get_rule_id_coverage
¶
Compute bidirectional coverage between principles and detectors.
Returns two lists:
- missing — principle IDs with no mapped detector.
- unknown — detector rule-IDs that reference principles not defined in the canonical rule set (potential stale registrations).
| PARAMETER | DESCRIPTION |
|---|---|
language
|
The
TYPE:
|
explicit_only
|
When
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[list[str], list[str]]
|
tuple[list[str], list[str]]: |
Source code in src/mcp_zen_of_languages/rules/base_models.py
get_registry_rule_id_gaps
¶
Run get_rule_id_coverage across every language and collect gaps.
Languages with no gaps are omitted from the result.
| PARAMETER | DESCRIPTION |
|---|---|
registry
|
Full
TYPE:
|
explicit_only
|
Passed through to
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, dict[str, list[str]]]
|
dict[str, dict[str, list[str]]]: |
dict[str, dict[str, list[str]]]
|
language that has at least one gap. |
Source code in src/mcp_zen_of_languages/rules/base_models.py
get_registry_detector_gaps
¶
Return principle IDs lacking a dedicated detector for each language.
This is a convenience wrapper around get_missing_detector_rules
applied to every language in registry.
| PARAMETER | DESCRIPTION |
|---|---|
registry
|
Full
TYPE:
|
explicit_only
|
Passed through to
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, list[str]]
|
dict[str, list[str]]: |
Source code in src/mcp_zen_of_languages/rules/base_models.py
mcp_zen_of_languages.rules.coverage
¶
Rule-to-detector coverage analysis.
Provides functions and Pydantic models that answer the question: "Does every zen principle have at least one detector that can enforce it?"
Two granularity levels are supported:
- Rule coverage (
RuleCoverageMap) — maps principle IDs to detector IDs. - Config coverage (
RuleConfigCoverageMap) — maps principle IDs toDetectorConfigclasses, useful for verifying that the pipeline can build a valid config for every registered detector.
Each function comes in inclusive and explicit variants. Inclusive
variants count the generic RulePatternDetector fallback; explicit
variants require a purpose-built detector and raise ValueError when
one is missing.
Classes¶
RuleCoverageMap
¶
Bases: BaseModel
Maps each principle ID to the detector IDs registered for it.
| ATTRIBUTE | DESCRIPTION |
|---|---|
language |
Lowercase language key (e.g.
TYPE:
|
rules |
TYPE:
|
RuleConfigCoverageMap
¶
Bases: BaseModel
Maps each principle ID to the DetectorConfig subclasses that serve it.
| ATTRIBUTE | DESCRIPTION |
|---|---|
language |
Lowercase language key.
TYPE:
|
rules |
TYPE:
|
Functions¶
build_rule_coverage
¶
Build an inclusive rule-to-detector map for language.
Includes RulePatternDetector fallback registrations alongside
purpose-built detectors.
| PARAMETER | DESCRIPTION |
|---|---|
language
|
Lowercase language key (e.g.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RuleCoverageMap
|
A
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If language is not present in the registry. |
Source code in src/mcp_zen_of_languages/rules/coverage.py
build_explicit_rule_coverage
¶
Build a strict rule-to-detector map excluding RulePatternDetector fallbacks.
Raises ValueError if any principle lacks a purpose-built detector.
| PARAMETER | DESCRIPTION |
|---|---|
language
|
Lowercase language key.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RuleCoverageMap
|
A
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If language is unknown or any principle is uncovered. |
Source code in src/mcp_zen_of_languages/rules/coverage.py
build_rule_config_coverage
¶
Build an inclusive rule-to-config-class map for language.
| PARAMETER | DESCRIPTION |
|---|---|
language
|
Lowercase language key.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RuleConfigCoverageMap
|
A
TYPE:
|
RuleConfigCoverageMap
|
serving each principle. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If language is not present in the registry. |
Source code in src/mcp_zen_of_languages/rules/coverage.py
build_explicit_rule_config_coverage
¶
Build a strict rule-to-config-class map excluding RulePatternDetector fallbacks.
Raises ValueError if any principle lacks an explicit config class.
| PARAMETER | DESCRIPTION |
|---|---|
language
|
Lowercase language key.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RuleConfigCoverageMap
|
A
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If language is unknown or any principle is uncovered. |
Source code in src/mcp_zen_of_languages/rules/coverage.py
build_all_rule_coverage
¶
Build inclusive rule coverage maps for all (or selected) languages.
| PARAMETER | DESCRIPTION |
|---|---|
languages
|
Restrict to these language keys.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[RuleCoverageMap]
|
list[RuleCoverageMap]: One |
Source code in src/mcp_zen_of_languages/rules/coverage.py
build_all_explicit_rule_coverage
¶
Build strict rule coverage maps (no fallback) for all (or selected) languages.
| PARAMETER | DESCRIPTION |
|---|---|
languages
|
Restrict to these language keys.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[RuleCoverageMap]
|
list[RuleCoverageMap]: One |
Source code in src/mcp_zen_of_languages/rules/coverage.py
build_all_rule_config_coverage
¶
Build inclusive config coverage maps for all (or selected) languages.
| PARAMETER | DESCRIPTION |
|---|---|
languages
|
Restrict to these language keys.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[RuleConfigCoverageMap]
|
list[RuleConfigCoverageMap]: One |
Source code in src/mcp_zen_of_languages/rules/coverage.py
build_all_explicit_rule_config_coverage
¶
Build strict config coverage maps (no fallback) for all (or selected) languages.
| PARAMETER | DESCRIPTION |
|---|---|
languages
|
Restrict to these language keys.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[RuleConfigCoverageMap]
|
list[RuleConfigCoverageMap]: One |
Source code in src/mcp_zen_of_languages/rules/coverage.py
mcp_zen_of_languages.rules.detections
¶
Compatibility shim: re-export detection helpers from rules.tools.detections.
Legacy import path: mcp_zen_of_languages.rules.detections
New canonical path: mcp_zen_of_languages.rules.tools.detections
Classes¶
DuplicateFinding
¶
Bases: BaseModel
A function name that appears in more than one file.
| ATTRIBUTE | DESCRIPTION |
|---|---|
name |
Function name found in multiple files.
TYPE:
|
files |
Paths of the files containing the duplicate definition.
TYPE:
|
GodClassFinding
¶
Bases: BaseModel
A class that exceeds method-count or line-count thresholds.
| ATTRIBUTE | DESCRIPTION |
|---|---|
name |
Class name.
TYPE:
|
method_count |
Number of
TYPE:
|
lines |
Total line span of the class body.
TYPE:
|
InheritanceFinding
¶
Bases: BaseModel
An inheritance chain that exceeds the allowed depth.
| ATTRIBUTE | DESCRIPTION |
|---|---|
chain |
Ordered list of class names from child to deepest ancestor.
TYPE:
|
depth |
Number of inheritance hops (
TYPE:
|
DependencyCycleFinding
¶
Bases: BaseModel
A circular dependency path discovered in the import graph.
| ATTRIBUTE | DESCRIPTION |
|---|---|
cycle |
Module names forming the cycle, ending with a repeat of the first element.
TYPE:
|
FeatureEnvyFinding
¶
Bases: BaseModel
A method that accesses another object's attributes more than its own.
| ATTRIBUTE | DESCRIPTION |
|---|---|
method |
Name of the envious method (
TYPE:
|
target_class |
Most-referenced external object name.
TYPE:
|
occurrences |
Number of attribute accesses on target_class.
TYPE:
|
SparseCodeFinding
¶
Bases: BaseModel
A source line containing too many semicolon-separated statements.
| ATTRIBUTE | DESCRIPTION |
|---|---|
line |
1-based line number.
TYPE:
|
statements |
Number of statements found on the line.
TYPE:
|
ConsistencyFinding
¶
Bases: BaseModel
Mixed naming conventions detected among function definitions.
| ATTRIBUTE | DESCRIPTION |
|---|---|
naming_styles |
Sorted list of observed styles (e.g.
TYPE:
|
ExplicitnessFinding
¶
Bases: BaseModel
A function with one or more parameters lacking type annotations.
| ATTRIBUTE | DESCRIPTION |
|---|---|
function |
Name of the under-annotated function.
TYPE:
|
missing_params |
Parameter names without type hints.
TYPE:
|
NamespaceFinding
¶
Bases: BaseModel
Namespace pollution metrics for a single source file.
| ATTRIBUTE | DESCRIPTION |
|---|---|
top_level_symbols |
Count of top-level definitions, imports, and assignments.
TYPE:
|
export_count |
Number of entries in
TYPE:
|
TsAnyFinding
¶
Bases: BaseModel
Occurrences of the any keyword in TypeScript source.
| ATTRIBUTE | DESCRIPTION |
|---|---|
count |
Total number of
TYPE:
|
TsTypeAliasFinding
¶
Bases: BaseModel
Object-style type aliases (type X = { … }) found in TypeScript source.
| ATTRIBUTE | DESCRIPTION |
|---|---|
count |
Number of object-literal type aliases.
TYPE:
|
TsReturnTypeFinding
¶
Bases: BaseModel
Exported functions missing explicit return-type annotations.
| ATTRIBUTE | DESCRIPTION |
|---|---|
count |
Number of exported functions without a return type.
TYPE:
|
TsReadonlyFinding
¶
Bases: BaseModel
Occurrences of the readonly modifier in TypeScript source.
| ATTRIBUTE | DESCRIPTION |
|---|---|
count |
Number of
TYPE:
|
TsAssertionFinding
¶
Bases: BaseModel
Type-assertion expressions (as T) found in TypeScript source.
| ATTRIBUTE | DESCRIPTION |
|---|---|
count |
Number of
TYPE:
|
TsUtilityTypeFinding
¶
Bases: BaseModel
Built-in utility-type references (Partial, Pick, etc.) in TypeScript source.
| ATTRIBUTE | DESCRIPTION |
|---|---|
count |
Combined occurrences of
TYPE:
|
TsNonNullFinding
¶
Bases: BaseModel
Non-null assertion operators (!) found in TypeScript source.
| ATTRIBUTE | DESCRIPTION |
|---|---|
count |
Number of non-null assertion matches.
TYPE:
|
TsEnumObjectFinding
¶
Bases: BaseModel
const object literals that may serve as ad-hoc enums.
| ATTRIBUTE | DESCRIPTION |
|---|---|
count |
Number of
TYPE:
|
TsUnknownAnyFinding
¶
Bases: BaseModel
Comparative counts of any vs unknown keywords in TypeScript source.
| ATTRIBUTE | DESCRIPTION |
|---|---|
any_count |
Occurrences of the
TYPE:
|
unknown_count |
Occurrences of the
TYPE:
|
TsOptionalChainingFinding
¶
Bases: BaseModel
Manual null-check chains in TypeScript source.
| ATTRIBUTE | DESCRIPTION |
|---|---|
count |
Number of manual null-check chain patterns found.
TYPE:
|
TsIndexLoopFinding
¶
Bases: BaseModel
C-style index-based for loops in TypeScript source.
| ATTRIBUTE | DESCRIPTION |
|---|---|
count |
Number of index-based loop patterns found.
TYPE:
|
TsPromiseChainFinding
¶
Bases: BaseModel
Raw .then() promise chains in TypeScript source.
| ATTRIBUTE | DESCRIPTION |
|---|---|
count |
Number of
TYPE:
|
TsDefaultExportFinding
¶
Bases: BaseModel
export default statements in TypeScript source.
| ATTRIBUTE | DESCRIPTION |
|---|---|
count |
Number of
TYPE:
|
TsCatchAllTypeFinding
¶
Bases: BaseModel
Catch-all type annotations (Object, object, {}) in TypeScript source.
| ATTRIBUTE | DESCRIPTION |
|---|---|
count |
Number of catch-all type annotation patterns found.
TYPE:
|
TsConsoleUsageFinding
¶
Bases: BaseModel
console.* calls in TypeScript source.
| ATTRIBUTE | DESCRIPTION |
|---|---|
count |
Number of
TYPE:
|
TsRequireImportFinding
¶
Bases: BaseModel
require() calls in TypeScript source.
| ATTRIBUTE | DESCRIPTION |
|---|---|
count |
Number of
TYPE:
|
TsStringConcatFinding
¶
Bases: BaseModel
String concatenation patterns in TypeScript source.
| ATTRIBUTE | DESCRIPTION |
|---|---|
count |
Number of string concatenation patterns found.
TYPE:
|
Functions¶
detect_ts_optional_chaining
¶
Detect manual null-check chains replaceable by optional chaining.
| PARAMETER | DESCRIPTION |
|---|---|
code
|
TypeScript source text.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
TsOptionalChainingFinding
|
Detection result. |
Source code in src/mcp_zen_of_languages/rules/tools/detections.py
detect_ts_index_loops
¶
Detect C-style index-based for loops.
| PARAMETER | DESCRIPTION |
|---|---|
code
|
TypeScript source text.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
TsIndexLoopFinding
|
Detection result.
TYPE:
|
Source code in src/mcp_zen_of_languages/rules/tools/detections.py
detect_ts_promise_chains
¶
Detect raw .then() promise chains.
| PARAMETER | DESCRIPTION |
|---|---|
code
|
TypeScript source text.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
TsPromiseChainFinding
|
Detection result.
TYPE:
|
Source code in src/mcp_zen_of_languages/rules/tools/detections.py
detect_ts_default_exports
¶
Detect export default statements.
| PARAMETER | DESCRIPTION |
|---|---|
code
|
TypeScript source text.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
TsDefaultExportFinding
|
Detection result.
TYPE:
|
Source code in src/mcp_zen_of_languages/rules/tools/detections.py
detect_ts_catch_all_types
¶
Detect catch-all type annotations.
| PARAMETER | DESCRIPTION |
|---|---|
code
|
TypeScript source text.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
TsCatchAllTypeFinding
|
Detection result.
TYPE:
|
Source code in src/mcp_zen_of_languages/rules/tools/detections.py
detect_ts_console_usage
¶
Detect console.* calls.
| PARAMETER | DESCRIPTION |
|---|---|
code
|
TypeScript source text.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
TsConsoleUsageFinding
|
Detection result.
TYPE:
|
Source code in src/mcp_zen_of_languages/rules/tools/detections.py
detect_ts_require_imports
¶
Detect require() calls.
| PARAMETER | DESCRIPTION |
|---|---|
code
|
TypeScript source text.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
TsRequireImportFinding
|
Detection result.
TYPE:
|
Source code in src/mcp_zen_of_languages/rules/tools/detections.py
detect_ts_string_concats
¶
Detect string concatenation patterns.
| PARAMETER | DESCRIPTION |
|---|---|
code
|
TypeScript source text.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
TsStringConcatFinding
|
Detection result.
TYPE:
|
Source code in src/mcp_zen_of_languages/rules/tools/detections.py
detect_deep_nesting
¶
Measure the deepest indentation level using 4-space tab stops.
| PARAMETER | DESCRIPTION |
|---|---|
code
|
Python source text to scan.
TYPE:
|
max_depth
|
Nesting-depth ceiling used for the boolean flag. Default to 3.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
tuple[bool, int]: |
int
|
when deepest_level is strictly greater than max_depth. |
Source code in src/mcp_zen_of_languages/rules/tools/detections.py
detect_long_functions
¶
Find top-level def blocks that exceed max_lines.
Uses naive line counting: a new def at column 0 starts a new block
and terminates the previous one.
| PARAMETER | DESCRIPTION |
|---|---|
code
|
Python source text.
TYPE:
|
max_lines
|
Line-count ceiling. Blocks at or below this are ignored. Default to 50.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[tuple[str, int]]
|
list[tuple[str, int]]: |
Source code in src/mcp_zen_of_languages/rules/tools/detections.py
detect_magic_methods_overuse
¶
Collect all dunder-method definitions (def __xxx__) in code.
| PARAMETER | DESCRIPTION |
|---|---|
code
|
Python source text to scan.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[str]
|
list[str]: Raw matched lines (including leading whitespace) for each dunder |
Source code in src/mcp_zen_of_languages/rules/tools/detections.py
detect_multiple_implementations
¶
Identify function names defined in more than one file.
Scans each file for top-level def statements and groups them by
function name. Any name appearing in two or more files produces a
DuplicateFinding.
| PARAMETER | DESCRIPTION |
|---|---|
files
|
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[DuplicateFinding]
|
list[DuplicateFinding]: One |
Source code in src/mcp_zen_of_languages/rules/tools/detections.py
detect_god_classes
¶
Flag classes that exceed method-count or line-span thresholds.
Parses class boundaries by looking for class Foo at column 0 and
counting indented def lines inside each block.
| PARAMETER | DESCRIPTION |
|---|---|
code
|
Python source text.
TYPE:
|
max_methods
|
Method-count ceiling. Default to 10.
TYPE:
|
max_lines
|
Line-span ceiling. Default to 500.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[GodClassFinding]
|
list[GodClassFinding]: One |
Source code in src/mcp_zen_of_languages/rules/tools/detections.py
detect_deep_inheritance
¶
Discover inheritance chains deeper than max_depth across multiple files.
Builds a parent map by regex-parsing class Foo(Bar, Baz) declarations,
then walks chains recursively. Cycles are detected and short-circuited.
| PARAMETER | DESCRIPTION |
|---|---|
code_map
|
TYPE:
|
max_depth
|
Maximum allowed inheritance hops. Default to 3.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[InheritanceFinding]
|
list[InheritanceFinding]: One |
list[InheritanceFinding]
|
exceeding max_depth. |
Source code in src/mcp_zen_of_languages/rules/tools/detections.py
detect_dependency_cycles
¶
Find circular dependencies in a directed edge list via depth-first search.
| PARAMETER | DESCRIPTION |
|---|---|
edges
|
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[DependencyCycleFinding]
|
list[DependencyCycleFinding]: One |
Source code in src/mcp_zen_of_languages/rules/tools/detections.py
detect_feature_envy
¶
Heuristic: flag files where an external object's attributes are accessed more often than self.
Counts self.attr vs other.attr patterns globally across the file.
When any single external name outweighs self references, a finding
is emitted.
Note
This is a deliberately naive global heuristic — it counts all
self.attr occurrences against all other.attr occurrences
without scope isolation. Method-level granularity may be added
in a future iteration.
| PARAMETER | DESCRIPTION |
|---|---|
code
|
Python source text.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[FeatureEnvyFinding]
|
list[FeatureEnvyFinding]: At most one |
list[FeatureEnvyFinding]
|
file. |
Source code in src/mcp_zen_of_languages/rules/tools/detections.py
detect_sparse_code
¶
Flag lines containing multiple semicolon-separated statements.
Comment-only lines are skipped.
| PARAMETER | DESCRIPTION |
|---|---|
code
|
Python source text.
TYPE:
|
max_statements_per_line
|
Maximum allowed statements per line. Default to 1.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[SparseCodeFinding]
|
list[SparseCodeFinding]: One |
Source code in src/mcp_zen_of_languages/rules/tools/detections.py
detect_inconsistent_naming_styles
¶
Check whether function names mix snake_case, camelCase, or PascalCase.
| PARAMETER | DESCRIPTION |
|---|---|
code
|
Python source text.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[ConsistencyFinding]
|
list[ConsistencyFinding]: A single-element list when more than one style is detected, |
list[ConsistencyFinding]
|
otherwise an empty list. |
Source code in src/mcp_zen_of_languages/rules/tools/detections.py
detect_missing_type_hints
¶
Walk the AST to find functions with unannotated parameters (excluding self).
| PARAMETER | DESCRIPTION |
|---|---|
code
|
Python source text.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[ExplicitnessFinding]
|
list[ExplicitnessFinding]: One |
Source code in src/mcp_zen_of_languages/rules/tools/detections.py
detect_namespace_usage
¶
Count top-level symbols and __all__ entries to gauge namespace pollution.
| PARAMETER | DESCRIPTION |
|---|---|
code
|
Python source text.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NamespaceFinding
|
A
TYPE:
|
Source code in src/mcp_zen_of_languages/rules/tools/detections.py
detect_ts_any_usage
¶
Count occurrences of the any type keyword in TypeScript source.
| PARAMETER | DESCRIPTION |
|---|---|
code
|
TypeScript source text.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
TsAnyFinding
|
A
TYPE:
|
Source code in src/mcp_zen_of_languages/rules/tools/detections.py
detect_ts_object_type_aliases
¶
Count type X = { … } object-literal type aliases in TypeScript.
| PARAMETER | DESCRIPTION |
|---|---|
code
|
TypeScript source text.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
TsTypeAliasFinding
|
A
TYPE:
|
Source code in src/mcp_zen_of_languages/rules/tools/detections.py
detect_ts_missing_return_types
¶
Count exported functions lacking an explicit return-type annotation.
| PARAMETER | DESCRIPTION |
|---|---|
code
|
TypeScript source text.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
TsReturnTypeFinding
|
A
TYPE:
|
Source code in src/mcp_zen_of_languages/rules/tools/detections.py
detect_ts_readonly_usage
¶
Count readonly modifier occurrences in TypeScript source.
| PARAMETER | DESCRIPTION |
|---|---|
code
|
TypeScript source text.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
TsReadonlyFinding
|
A
TYPE:
|
Source code in src/mcp_zen_of_languages/rules/tools/detections.py
detect_ts_type_assertions
¶
Count as T type-assertion expressions in TypeScript source.
| PARAMETER | DESCRIPTION |
|---|---|
code
|
TypeScript source text.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
TsAssertionFinding
|
A
TYPE:
|
Source code in src/mcp_zen_of_languages/rules/tools/detections.py
detect_ts_utility_types
¶
Count built-in utility-type references (Partial, Pick, Omit, Record, Readonly).
| PARAMETER | DESCRIPTION |
|---|---|
code
|
TypeScript source text.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
TsUtilityTypeFinding
|
A
TYPE:
|
Source code in src/mcp_zen_of_languages/rules/tools/detections.py
detect_ts_non_null_assertions
¶
Count non-null assertion operators (expr!) in TypeScript source.
| PARAMETER | DESCRIPTION |
|---|---|
code
|
TypeScript source text.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
TsNonNullFinding
|
A
TYPE:
|
Source code in src/mcp_zen_of_languages/rules/tools/detections.py
detect_ts_plain_enum_objects
¶
Count const X = { patterns that may function as ad-hoc enums.
| PARAMETER | DESCRIPTION |
|---|---|
code
|
TypeScript source text.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
TsEnumObjectFinding
|
A
TYPE:
|
Source code in src/mcp_zen_of_languages/rules/tools/detections.py
detect_ts_unknown_over_any
¶
Compare any vs unknown keyword usage in TypeScript source.
A high any_count relative to unknown_count suggests the codebase
should migrate toward unknown for safer type narrowing.
| PARAMETER | DESCRIPTION |
|---|---|
code
|
TypeScript source text.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
TsUnknownAnyFinding
|
A
TYPE:
|
Source code in src/mcp_zen_of_languages/rules/tools/detections.py
mcp_zen_of_languages.rules.mapping_export
¶
Export the live rule-to-detector registry as a JSON mapping.
Intended consumers are CI dashboards, coverage reports, and developer tooling that need a static snapshot of which detectors enforce which zen principles. The export format includes per-language rule counts, detector IDs, and a reverse mapping (detector → rules) for cross-referencing.
Functions¶
build_rule_detector_mapping
¶
Assemble a JSON-serialisable mapping from principles to their detectors.
For each language the output contains:
rules_count/detectors_count— aggregate totals.mapping—{rule_id: {principle, detectors, …}}.reverse_mapping—{detector_id: [rule_id, …]}.
| PARAMETER | DESCRIPTION |
|---|---|
languages
|
Restrict output to these language keys.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Any]
|
dict[str, Any]: Nested dict ready for |
Source code in src/mcp_zen_of_languages/rules/mapping_export.py
export_mapping_json
¶
Write the rule-to-detector mapping to output_path as pretty-printed JSON.
| PARAMETER | DESCRIPTION |
|---|---|
output_path
|
Destination file (created or overwritten).
TYPE:
|
languages
|
Restrict to these language keys.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Any]
|
dict[str, Any]: The same dict that was written to disk, for programmatic reuse. |