Detectors¶
Detectors encapsulate individual rule checks by language.
Bash¶
mcp_zen_of_languages.languages.bash.detectors ¶
Rule detectors for Bash/shell code quality and robustness checks.
Each detector in this module targets a specific shell scripting anti-pattern — from missing set -euo pipefail and unquoted variable expansions to legacy backtick syntax and absent signal handlers. Detectors scan source lines with regex patterns because no Python-native Bash AST is currently integrated.
See Also
BashAnalyzer: The analyzer that wires these detectors into its pipeline.
Classes¶
BashStrictModeDetector ¶
Bases: ViolationDetector[BashStrictModeConfig], LocationHelperMixin
Detect scripts missing the unofficial Bash strict mode header.
Without set -euo pipefail, a script silently continues after command failures (-e), uses undefined variables without error (-u), and masks failures in pipelines (pipefail). This is the number-one cause of "it worked on my machine" CI failures. The detector searches the entire file content for the exact pragma string.
Note
Place set -euo pipefail immediately after the shebang line so that every subsequent command runs under strict error handling.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/bash/detectors.py
BashQuoteVariablesDetector ¶
Bases: ViolationDetector[BashQuoteVariablesConfig], LocationHelperMixin
Detect unquoted variable expansions that cause word-splitting bugs.
When $var appears outside double quotes, the shell performs word splitting and pathname expansion on its value. A filename containing spaces or glob characters can silently break rm, mv, or loop logic. This detector flags lines containing $ variable references that lack surrounding double quotes.
Note
Always write "$var" instead of bare $var to prevent word splitting and globbing surprises.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/bash/detectors.py
BashEvalUsageDetector ¶
Bases: ViolationDetector[BashEvalUsageConfig], LocationHelperMixin
Detect usage of eval which enables code injection attacks.
eval re-parses its arguments as shell commands, making scripts vulnerable to injection when any part of the evaluated string comes from user input, environment variables, or external files. This detector scans every line for the eval keyword and reports its exact position.
Note
Replace eval with arrays for dynamic command construction or case statements for dispatching, both of which are injection-safe.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/bash/detectors.py
BashDoubleBracketsDetector ¶
Bases: ViolationDetector[BashDoubleBracketsConfig], LocationHelperMixin
Detect single-bracket [ ] test expressions that should use [[ ]].
The POSIX [ command is an external binary with surprising parsing rules — unquoted variables inside [ ] can cause syntax errors when empty, and pattern matching is unavailable. Bash's built-in [[ ]] handles empty strings safely, supports =~ regex matching, and does not perform word splitting on variables.
Note
[[ ]] is a Bash extension. If POSIX portability is required, quote all variables inside [ ] instead.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/bash/detectors.py
BashCommandSubstitutionDetector ¶
Bases: ViolationDetector[BashCommandSubstitutionConfig], LocationHelperMixin
Detect legacy backtick command substitution syntax.
Backtick-delimited command substitution (cmd) cannot be nested without cumbersome escaping, is visually ambiguous with single quotes in some fonts, and is considered deprecated in modern shell style guides. This detector flags every backtick occurrence and recommends the $(cmd) form, which nests cleanly and is universally supported.
Note
$(...) is supported by all POSIX-compliant shells and should be the default choice for command substitution.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/bash/detectors.py
BashReadonlyConstantsDetector ¶
Bases: ViolationDetector[BashReadonlyConstantsConfig], LocationHelperMixin
Detect ALL_CAPS assignments that are not declared readonly.
Shell constants (paths, configuration values, magic strings) are conventionally named in ALL_CAPS but remain mutable unless explicitly declared with readonly. Accidental reassignment of a constant deep in a script can produce silent, hard-to-debug failures. This detector flags top-level ALL_CAPS assignments lacking readonly.
Note
Use readonly MY_CONST="value" or declare -r to make constants truly immutable.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/bash/detectors.py
BashExitCodeChecksDetector ¶
Bases: ViolationDetector[BashExitCodeConfig], LocationHelperMixin
Detect external commands whose exit codes are silently ignored.
Even with set -e, some command failures can slip through (e.g., commands on the left side of && or inside if conditions). This detector identifies standalone command invocations that are not guarded by ||, &&, or explicit $? checks, flagging the first unguarded command it finds.
Note
Guard critical commands with cmd || handle_error or check $? immediately after execution.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/bash/detectors.py
BashFunctionUsageDetector ¶
Bases: ViolationDetector[Bash006Config], LocationHelperMixin
Detect long scripts that lack function decomposition.
A linear Bash script without functions becomes unreadable and un-testable as it grows. This detector counts non-comment, non-blank lines and flags scripts exceeding max_script_length_without_functions when no function or name() declaration is present.
Note
Extract repeated or logically distinct blocks into named functions so each unit can be tested, logged, and reused independently.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/bash/detectors.py
BashLocalVariablesDetector ¶
Bases: ViolationDetector[BashLocalVariablesConfig], LocationHelperMixin
Detect function-scoped variables missing the local keyword.
Bash variables are global by default — assigning name=value inside a function pollutes the caller's namespace and can overwrite unrelated variables. This detector tracks whether the script is inside a function body and flags variable assignments that omit local.
Note
Always prefix function-internal assignments with local to prevent accidental namespace collisions.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/bash/detectors.py
BashArgumentValidationDetector ¶
Bases: ViolationDetector[BashArgumentValidationConfig], LocationHelperMixin
Detect scripts that use positional arguments without validation.
Scripts referencing $1, $@, or $* without checking $# or using getopts will produce cryptic errors — or worse, silently operate on empty values — when invoked with missing arguments. This detector flags the absence of argument-count guards.
Note
Validate arguments early with if [[ $# -lt N ]] or use getopts for option parsing to fail fast with a clear message.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/bash/detectors.py
BashMeaningfulNamesDetector ¶
Bases: ViolationDetector[Bash011Config], LocationHelperMixin
Detect overly short or cryptic variable names in shell scripts.
Single-character names like x or t outside of loop counters (i, j, k) and ALL_CAPS constants make scripts harder to maintain. This detector extracts variable assignments, skips uppercase constants and conventional loop vars, and flags names shorter than min_variable_name_length.
Note
Descriptive names like log_dir instead of d turn the script into self-documenting code.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/bash/detectors.py
BashSignalHandlingDetector ¶
Bases: ViolationDetector[BashSignalHandlingConfig], LocationHelperMixin
Detect scripts that lack trap handlers for cleanup on exit or signals.
Scripts that create temporary files, acquire locks, or start background processes must clean up on EXIT, INT, and TERM signals. Without a trap handler, an interrupted script leaves stale temp files, dangling lock files, or orphaned child processes.
Note
Add trap cleanup EXIT near the top of the script to guarantee that cleanup runs regardless of how the script terminates.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/bash/detectors.py
BashArrayUsageDetector ¶
Bases: ViolationDetector[BashArrayUsageConfig], LocationHelperMixin
Detect IFS-based string splitting used instead of proper Bash arrays.
Setting IFS to split a string into tokens and iterating over unquoted $var is fragile — it breaks when values contain the delimiter character and does not preserve empty fields. This detector flags IFS= assignments and for x in $var patterns, recommending Bash arrays with "${array[@]}" iteration instead.
Note
Bash arrays handle whitespace-containing elements correctly and should be preferred over IFS-splitting for list-like data.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/bash/detectors.py
BashUsageInfoDetector ¶
Bases: ViolationDetector[BashUsageInfoConfig], LocationHelperMixin
Detect scripts lacking a usage function or --help/-h flag.
A script without built-in help forces users to read the source code to understand its arguments and options. This detector checks for the presence of a usage keyword or --help/-h string and flags scripts that provide neither.
Note
Even minimal scripts benefit from a usage() function that prints expected arguments and exits with a non-zero code on misuse.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/bash/detectors.py
C++¶
mcp_zen_of_languages.languages.cpp.detectors ¶
Zen-rule detectors for C++ code quality, safety, and modern idiom checks.
Each detector implements the Strategy pattern as a ViolationDetector subclass, targeting a specific C++ anti-pattern. Modern C++ (C++11 through C++23) provides RAII, smart pointers, constexpr, range-based loops, and std::optional to replace error-prone C-era patterns; these detectors enforce that transition.
See Also
CppAnalyzer: Template Method analyzer that orchestrates these detectors.
Classes¶
CppSmartPointerDetector ¶
Bases: ViolationDetector[CppSmartPointerConfig], LocationHelperMixin
Flags raw new/delete usage where smart pointers should be used.
Manual new/delete is the leading cause of memory leaks, dangling pointers, and double-free vulnerabilities in C++ code. std::unique_ptr and std::shared_ptr provide deterministic, exception-safe ownership semantics that eliminate entire categories of runtime errors with zero overhead (for unique_ptr) or minimal overhead (for shared_ptr).
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'cpp_smart_pointers' for registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Detector identifier for the smart-pointer rule. TYPE: |
Methods:¶
detect ¶
Flag lines containing raw new or delete expressions.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with C++ source text. TYPE: |
config | Smart-pointer detection configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/cpp/detectors.py
CppNullptrDetector ¶
Bases: ViolationDetector[CppNullptrConfig], LocationHelperMixin
Flags legacy NULL macro usage instead of the type-safe nullptr literal.
The NULL macro is a C holdover typically defined as 0 or (void*)0, which participates in integer overload resolution and can silently select the wrong function overload. nullptr introduced in C++11 has its own type (std::nullptr_t) that only converts to pointer types, preventing subtle overload-resolution bugs.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'cpp_nullptr' for registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Detector identifier for the nullptr rule. TYPE: |
Methods:¶
detect ¶
Flag lines that reference the NULL macro.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with C++ source text. TYPE: |
config | Nullptr detection configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/cpp/detectors.py
CppRaiiDetector ¶
Bases: ViolationDetector[CppRaiiConfig], LocationHelperMixin
Detects manual resource management that should use RAII wrappers.
RAII (Resource Acquisition Is Initialization) is the cornerstone of safe C++ resource management. Raw new/delete, malloc/free calls bypass destructor-based cleanup, leaving resources leaked when exceptions unwind the stack or early returns skip cleanup code. Using RAII wrappers like std::unique_ptr, std::lock_guard, or custom scoped handles ensures deterministic release regardless of control flow.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'cpp-001' for registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Detector identifier for the RAII rule. TYPE: |
Methods:¶
detect ¶
Flag lines with new/delete/malloc/free that bypass RAII.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with C++ source text. TYPE: |
config | RAII detection configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/cpp/detectors.py
CppAutoDetector ¶
Bases: ViolationDetector[CppAutoConfig], LocationHelperMixin
Suggests auto type deduction where explicit std:: types add verbosity.
When the right-hand side of an assignment makes the type obvious (e.g., auto it = container.begin()), spelling out the full type clutters code without adding information. auto reduces visual noise, prevents narrowing-conversion surprises, and makes refactoring safer because the variable type tracks the expression automatically.
Note
Lines already containing auto are skipped; only verbose std:: assignments are flagged.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'cpp-003' for registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Detector identifier for the auto-deduction rule. TYPE: |
Methods:¶
detect ¶
Flag assignments with explicit std:: types that could use auto.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with C++ source text. TYPE: |
config | Auto-deduction detection configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/cpp/detectors.py
CppRangeForDetector ¶
Bases: ViolationDetector[CppRangeForConfig], LocationHelperMixin
Flags iterator-based for loops that should use range-based for.
C++11 range-based for loops (for (auto& x : container)) eliminate off-by-one errors, remove boilerplate .begin()/.end() calls, and express intent more clearly than manual iterator management. They also compose better with structured bindings (C++17) for map iteration.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'cpp-005' for registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Detector identifier for the range-for rule. TYPE: |
Methods:¶
detect ¶
Flag for loops using explicit .begin()/.end() iterators.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with C++ source text. TYPE: |
config | Range-for detection configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/cpp/detectors.py
CppManualAllocationDetector ¶
Bases: ViolationDetector[CppManualAllocationConfig], LocationHelperMixin
Detects C-style heap allocation (malloc/free, new[]/delete[]).
Manual heap allocation requires exact pairing of allocate/deallocate calls and is inherently exception-unsafe. Standard containers (std::vector, std::array) and smart pointers manage memory automatically, provide bounds checking in debug builds, and integrate with move semantics for efficient transfers. C-style allocation should be reserved for FFI boundaries or custom allocator implementations.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'cpp-006' for registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Detector identifier for the manual-allocation rule. TYPE: |
Methods:¶
detect ¶
Flag malloc/free and array new[]/delete[] usage.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with C++ source text. TYPE: |
config | Manual-allocation detection configuration. |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/cpp/detectors.py
CppConstCorrectnessDetector ¶
Bases: ViolationDetector[CppConstCorrectnessConfig], LocationHelperMixin
Flags non-const references where const qualification is appropriate.
Const correctness is a compile-time contract that prevents accidental mutation. Passing objects by non-const reference when the function does not modify them misleads readers, prevents the compiler from optimising, and can mask bugs where mutation was unintended. Marking parameters and locals const wherever possible is a core C++ Core Guideline.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'cpp-007' for registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Detector identifier for the const-correctness rule. TYPE: |
Methods:¶
detect ¶
Flag reference parameters and variables missing const qualification.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with C++ source text. TYPE: |
config | Const-correctness detection configuration. |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/cpp/detectors.py
CppCStyleCastDetector ¶
Bases: ViolationDetector[CppCStyleCastConfig], LocationHelperMixin
Detects C-style casts that should use static_cast/dynamic_cast.
C-style casts ((int)x) silently combine const_cast, static_cast, reinterpret_cast, and even removing access protection in a single opaque syntax. C++-style named casts make the programmer's intent explicit, are searchable in code, and trigger compiler diagnostics when the conversion is unsafe.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'cpp-008' for registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Detector identifier for the C-style-cast rule. TYPE: |
Methods:¶
detect ¶
Flag C-style cast syntax on lines not already using named casts.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with C++ source text. TYPE: |
config | C-style-cast detection configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/cpp/detectors.py
CppRuleOfFiveDetector ¶
Bases: ViolationDetector[CppRuleOfFiveConfig], LocationHelperMixin
Flags classes with destructors but missing copy/move special members.
The Rule of Five states that if a class defines any of the destructor, copy constructor, copy assignment, move constructor, or move assignment, it should explicitly define or default all five. Failing to do so risks shallow copies of owned resources, double-free on destruction, and silently deleted move operations that degrade performance.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'cpp-009' for registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Detector identifier for the Rule-of-Five rule. TYPE: |
Methods:¶
detect ¶
Flag classes with a destructor but no operator= definition.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with C++ source text. TYPE: |
config | Rule-of-Five detection configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/cpp/detectors.py
CppMoveDetector ¶
Bases: ViolationDetector[CppMoveConfig], LocationHelperMixin
Flags rvalue references (&&) without corresponding std::move.
Move semantics (C++11) enable zero-copy ownership transfer, but the benefit is only realised when std::move is used to cast lvalues to rvalue references. Code that accepts && parameters but copies instead of moving wastes the performance advantage and misleads readers about ownership intent.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'cpp-010' for registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Detector identifier for the move-semantics rule. TYPE: |
Methods:¶
detect ¶
Flag code with && references but no std::move usage.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with C++ source text. TYPE: |
config | Move-semantics detection configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/cpp/detectors.py
CppAvoidGlobalsDetector ¶
Bases: ViolationDetector[CppAvoidGlobalsConfig], LocationHelperMixin
Detects mutable global and file-scope static/extern variables.
Mutable globals introduce hidden coupling between translation units, create data races in multi-threaded programs, and make unit testing nearly impossible because state persists across test cases. The C++ Core Guidelines recommend scoped state managed through function parameters or dependency injection instead.
Note
static_assert lines are excluded because they are compile-time checks, not mutable state.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'cpp-011' for registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Detector identifier for the avoid-globals rule. TYPE: |
Methods:¶
detect ¶
Flag file-scope static or extern declarations (excluding static_assert).
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with C++ source text. TYPE: |
config | Global-avoidance detection configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/cpp/detectors.py
CppOverrideFinalDetector ¶
Bases: ViolationDetector[CppOverrideFinalConfig], LocationHelperMixin
Flags virtual overrides missing the override or final specifier.
Without override, a typo in a virtual method signature silently creates a new function instead of overriding the base class version, a bug that is invisible until runtime. override (C++11) turns this into a compile-time error. final additionally prevents further overriding, enabling devirtualisation optimisations.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'cpp-012' for registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Detector identifier for the override/final rule. TYPE: |
Methods:¶
detect ¶
Flag virtual methods lacking override or final specifiers.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with C++ source text. TYPE: |
config | Override/final detection configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/cpp/detectors.py
CppOptionalDetector ¶
Bases: ViolationDetector[CppOptionalConfig], LocationHelperMixin
Suggests std::optional over nullable raw pointers for optional values.
Using raw pointers to represent "maybe a value" conflates ownership, nullability, and optionality into a single ambiguous type. std::optional (C++17) is a value-semantic wrapper that makes the "no value" state explicit in the type system, prevents null-pointer dereferences at compile time (with value()), and avoids heap allocation entirely.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'cpp-013' for registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Detector identifier for the std::optional rule. TYPE: |
Methods:¶
detect ¶
Flag pointer declarations where std::optional would express intent better.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with C++ source text. TYPE: |
config | Optional detection configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/cpp/detectors.py
C¶
mcp_zen_of_languages.languages.csharp.detectors ¶
Zen-rule detectors for C# code quality, .NET idiom, and type-safety checks.
Each detector implements the Strategy pattern as a ViolationDetector subclass, targeting a specific C# anti-pattern. Modern C# (8-12) provides nullable reference types, pattern matching, records, and async/await to replace legacy patterns; these detectors enforce that adoption.
See Also
CSharpAnalyzer: Template Method analyzer that orchestrates these detectors.
Classes¶
CSharpAsyncAwaitDetector ¶
Bases: ViolationDetector[CSharpAsyncAwaitConfig], LocationHelperMixin
Flags synchronous blocking on tasks via .Result or .Wait().
Calling .Result or .Wait() on a Task blocks the calling thread and can deadlock in UI or ASP.NET synchronization contexts where the continuation needs the same thread that is now blocked. Using await instead yields the thread back to the pool, preventing deadlocks and keeping the application responsive under load.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'csharp_async_await' for registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Detector identifier for the async/await rule. TYPE: |
Methods:¶
detect ¶
Flag lines that block on tasks with .Result or .Wait().
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with C# source text. TYPE: |
config | Async/await detection configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/csharp/detectors.py
CSharpStringInterpolationDetector ¶
Bases: ViolationDetector[CSharpStringInterpolationConfig], LocationHelperMixin
Flags String.Format usage where string interpolation is cleaner.
String.Format requires positional index placeholders ({0}, {1}) that are error-prone and hard to read. C# 6+ string interpolation ($"Hello {name}") embeds expressions inline, is checked at compile time, and allocates fewer intermediate strings on the managed heap.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'csharp_string_interpolation' for registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Detector identifier for the string-interpolation rule. TYPE: |
Methods:¶
detect ¶
Flag calls to String.Format that should use interpolation.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with C# source text. TYPE: |
config | String-interpolation detection configuration. |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/csharp/detectors.py
CSharpNullableDetector ¶
Bases: ViolationDetector[CSharpNullableConfig], LocationHelperMixin
Detects files missing #nullable enable for nullable reference types.
C# 8 nullable reference types turn NullReferenceException from a runtime surprise into a compile-time warning. Without #nullable enable, the compiler cannot distinguish nullable from non-nullable references, leaving the most common .NET exception class unguarded and forcing defensive null checks throughout the codebase.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'cs-001' for registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Detector identifier for the nullable-reference-types rule. TYPE: |
Methods:¶
detect ¶
Flag files that do not contain a #nullable enable directive.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with C# source text. TYPE: |
config | Nullable detection configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/csharp/detectors.py
CSharpExpressionBodiedDetector ¶
Bases: ViolationDetector[CSharpExpressionBodiedConfig], LocationHelperMixin
Flags verbose property getters that should use expression-bodied members.
Expression-bodied members (=> expression;) introduced in C# 6 eliminate brace-and-return boilerplate for single-expression getters and methods, reducing visual noise and making the class surface area immediately scannable.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'cs-002' for registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Detector identifier for the expression-bodied-member rule. TYPE: |
Methods:¶
detect ¶
Flag get { return ... } patterns that could be expression-bodied.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with C# source text. TYPE: |
config | Expression-bodied detection configuration. |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/csharp/detectors.py
CSharpVarDetector ¶
Bases: ViolationDetector[CSharpVarConfig], LocationHelperMixin
Flags explicit primitive type declarations where var improves readability.
When the right-hand side of an assignment makes the type obvious (e.g., new List<string>()), repeating List<string> on the left adds redundancy without clarity. var reduces line length and keeps the focus on the variable name and its initial value, following the .NET coding convention for obvious-type assignments.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'cs-003' for registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Detector identifier for the var-usage rule. TYPE: |
Methods:¶
detect ¶
Flag assignments with explicit primitive types that could use var.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with C# source text. TYPE: |
config | Var-usage detection configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/csharp/detectors.py
CSharpPatternMatchingDetector ¶
Bases: ViolationDetector[CSharpPatternMatchingConfig], LocationHelperMixin
Suggests pattern matching (is/switch expressions) over explicit casts.
C# 7+ pattern matching combines type testing and variable declaration in a single expression, eliminating the need for separate is checks followed by casts. This reduces boxing for value types and prevents InvalidCastException by making the type check and extraction atomic.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'cs-005' for registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Detector identifier for the pattern-matching rule. TYPE: |
Methods:¶
detect ¶
Flag is type checks that could leverage pattern matching.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with C# source text. TYPE: |
config | Pattern-matching detection configuration. |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/csharp/detectors.py
CSharpCollectionExpressionDetector ¶
Bases: ViolationDetector[CSharpCollectionExpressionConfig], LocationHelperMixin
Flags verbose new List or new T[] where collection expressions work.
C# 12 collection expressions ([a, b, c]) provide a concise, target-typed syntax for initialising lists, arrays, and spans. They reduce boilerplate, improve readability, and allow the compiler to choose the optimal backing storage based on the target type.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'cs-007' for registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Detector identifier for the collection-expression rule. TYPE: |
Methods:¶
detect ¶
Flag new List or new T[] initialisations that could use [].
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with C# source text. TYPE: |
config | Collection-expression detection configuration. |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/csharp/detectors.py
CSharpNamingConventionDetector ¶
Bases: ViolationDetector[Cs008Config], LocationHelperMixin
Enforces .NET naming conventions for public and private members.
The .NET Framework Design Guidelines prescribe PascalCase for public members and camelCase (optionally _-prefixed) for private fields. Consistent naming enables developers to infer visibility from the identifier alone, which is critical in large codebases where navigating by convention replaces navigating by access modifiers.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'cs-008' for registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Detector identifier for the naming-convention rule. TYPE: |
Methods:¶
detect ¶
Flag public/private members that violate configured naming styles.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with C# source text. TYPE: |
config | Contains TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/csharp/detectors.py
CSharpDisposableDetector ¶
Bases: ViolationDetector[CSharpDisposableConfig], LocationHelperMixin
Detects IDisposable resources not wrapped in using statements.
.NET's deterministic disposal pattern requires IDisposable objects (database connections, file handles, HTTP clients) to be wrapped in using blocks or declarations. Without using, the Dispose() call depends on the garbage collector's finaliser queue, leading to resource exhaustion under load—connection pool starvation is the most common symptom.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'cs-009' for registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Detector identifier for the disposable-resource rule. TYPE: |
Methods:¶
detect ¶
Flag code referencing IDisposable/Dispose() without using.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with C# source text. TYPE: |
config | Disposable detection configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/csharp/detectors.py
CSharpMagicNumberDetector ¶
Bases: ViolationDetector[CSharpMagicNumberConfig], LocationHelperMixin
Flags hard-coded numeric literals (magic numbers) in business logic.
Magic numbers embedded in code hide domain intent and make maintenance hazardous—changing a threshold means finding every occurrence of the same literal across the codebase. Named constants (const or static readonly) provide self-documenting, single-source-of-truth values that the JIT compiler can inline just as efficiently.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'cs-010' for registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Detector identifier for the magic-number rule. TYPE: |
Methods:¶
detect ¶
Flag multi-digit numeric literals that should be named constants.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with C# source text. TYPE: |
config | Magic-number detection configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/csharp/detectors.py
CSharpLinqDetector ¶
Bases: ViolationDetector[CSharpLinqConfig], LocationHelperMixin
Suggests LINQ methods (Select/Where) over manual foreach loops.
LINQ provides a declarative, composable query syntax that expresses what to compute rather than how to iterate. Replacing imperative foreach accumulation with Select, Where, and Aggregate reduces mutable state, enables deferred execution, and aligns with the functional programming features built into the .NET runtime.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'cs-011' for registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Detector identifier for the LINQ-preference rule. TYPE: |
Methods:¶
detect ¶
Flag foreach loops that lack corresponding LINQ method calls.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with C# source text. TYPE: |
config | LINQ detection configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/csharp/detectors.py
CSharpExceptionHandlingDetector ¶
Bases: ViolationDetector[CSharpExceptionHandlingConfig], LocationHelperMixin
Flags overly broad catch (Exception) or empty catch blocks.
Catching the base Exception type swallows OutOfMemoryException, StackOverflowException, and other critical failures that should crash the process. Empty catch blocks silently discard errors, making production debugging impossible. Best practice is to catch the most specific exception type and log or re-throw with context.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'cs-012' for registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Detector identifier for the exception-handling rule. TYPE: |
Methods:¶
detect ¶
Flag catch (Exception) and bare catch blocks.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with C# source text. TYPE: |
config | Exception-handling detection configuration. |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/csharp/detectors.py
CSharpRecordDetector ¶
Bases: ViolationDetector[CSharpRecordConfig], LocationHelperMixin
Suggests record types for immutable data-transfer objects (DTOs).
C# 9 record types provide value-based equality, immutability via init-only setters, built-in ToString(), and with-expression cloning—all of which must be hand-written for plain class DTOs. Using class with get; set; properties for data carriers wastes boilerplate and invites accidental mutation of shared state.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'cs-013' for registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Detector identifier for the record-type rule. TYPE: |
Methods:¶
detect ¶
Flag class definitions with get; set; that could be records.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with C# source text. TYPE: |
config | Record-type detection configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/csharp/detectors.py
Go¶
mcp_zen_of_languages.languages.go.detectors ¶
Rule detectors for go code quality and architecture checks.
Classes¶
GoErrorHandlingDetector ¶
Bases: ViolationDetector[GoErrorHandlingConfig]
Flags ignored errors, unchecked err variables, and panic() calls in Go code.
Go's explicit if err != nil pattern is the language's primary safety mechanism — there are no exceptions. Assigning errors to _, calling panic() in library code, or leaving err unchecked silently discards failure information. This detector uses regex to count all three anti-patterns and flags files whose combined total exceeds the configured threshold.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/go/detectors.py
GoInterfaceSizeDetector ¶
Bases: ViolationDetector[GoInterfaceSizeConfig]
Detects oversized interfaces that violate Go's preference for small, composable contracts.
Go proverb: "The bigger the interface, the weaker the abstraction." Interfaces with many methods are hard to implement, hard to mock in tests, and tightly couple consumers to a single implementation. This detector parses interface bodies via regex, counts non-comment method lines, and flags interfaces that exceed the configured maximum.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/go/detectors.py
GoContextUsageDetector ¶
Bases: ViolationDetector[GoContextUsageConfig]
Flags code that lacks context.Context for cancellation and deadline propagation.
In Go, context.Context is the standard mechanism for cancellation, timeouts, and request-scoped values across goroutine boundaries. Long-running or network-bound operations without a context parameter cannot be cancelled gracefully. This detector checks whether the source mentions context.Context at all and flags its absence when required by configuration.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/go/detectors.py
GoDeferUsageDetector ¶
Bases: ViolationDetector[GoDeferUsageConfig]
Detects defer misuse inside loops and missing defer for resource cleanup.
defer in Go schedules a call to run when the enclosing function returns, making it ideal for releasing resources like file handles and locks. However, defer inside a loop defers until function exit — not loop iteration — causing resource leaks. This detector also scans for .Close() and .Unlock() calls that are not deferred, flagging forgotten cleanup.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/go/detectors.py
GoNamingConventionDetector ¶
Bases: ViolationDetector[GoNamingConventionConfig]
Flags overly long variable names that violate Go's brevity conventions.
Go favors short, context-driven names — r for a reader, ctx for a context — because the language's small function scopes make long names redundant. This detector uses a regex to find var declarations with identifiers exceeding 24 characters and suggests shorter, more idiomatic alternatives.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/go/detectors.py
GoInterfaceReturnDetector ¶
Bases: ViolationDetector[GoInterfaceReturnConfig]
Flags functions that return interface types instead of concrete structs.
Go idiom: "Accept interfaces, return structs." Returning an interface hides the concrete type from callers, preventing them from accessing type-specific methods or embedding the struct. It also makes it harder to discover what a function actually produces. This detector uses a regex to find function signatures that return interface{ and suggests returning concrete types instead.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/go/detectors.py
GoZeroValueDetector ¶
Bases: ViolationDetector[GoZeroValueConfig]
Flags New* constructor functions where making the zero value usable would be simpler.
Go's zero-value philosophy means a var x MyStruct should be ready to use without initialization. When a package exports NewFoo() constructors, callers must remember to call them, and forgetting leads to nil-pointer panics. This detector scans for func New* patterns and suggests designing structs so their zero values are valid.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/go/detectors.py
GoInterfacePointerDetector ¶
Bases: ViolationDetector[GoInterfacePointerConfig]
Detects pointers to interfaces, which are almost always a mistake in Go.
Interfaces in Go are already reference-like values (a type-pointer plus a data-pointer), so *MyInterface adds an unnecessary level of indirection that confuses the type system and prevents interface satisfaction. This detector scans for *<name>Interface and *interface{ patterns via regex.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/go/detectors.py
GoGoroutineLeakDetector ¶
Bases: ViolationDetector[GoGoroutineLeakConfig]
Flags goroutines launched without cancellation support and unclosed channels.
Goroutine leaks are among the most insidious Go bugs: a goroutine blocked on a channel or network call with no way to cancel accumulates silently until the process runs out of memory. This detector checks for go func invocations that lack a context.Context cancellation path and make(chan ...) allocations without a corresponding close() call.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/go/detectors.py
GoPackageNamingDetector ¶
Bases: ViolationDetector[GoPackageNamingConfig]
Flags package names that violate Go's singular, lowercase naming convention.
The Go specification and community style guides require package names to be short, lowercase, singular nouns — no underscores, no mixedCaps, no plurals. A package named utils or string_helpers signals poor cohesion. This detector extracts the package declaration and checks for trailing s or embedded underscores.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/go/detectors.py
GoPackageStateDetector ¶
Bases: ViolationDetector[GoPackageStateConfig]
Flags mutable package-level variables that introduce hidden global state.
Package-level var declarations are effectively globals: they create implicit coupling between functions, make testing difficult, and introduce data races in concurrent programs. Go encourages passing dependencies explicitly via function arguments or struct fields. This detector scans for top-level var declarations and flags their presence.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/go/detectors.py
GoInitUsageDetector ¶
Bases: ViolationDetector[GoInitUsageConfig]
Flags func init() usage that hides initialization logic from callers.
Go's init() functions run automatically at package load time, creating invisible side effects that make testing and dependency ordering unpredictable. Explicit initialization via exported functions gives callers control over when and how setup happens. This detector simply checks for the presence of func init( in the source.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/go/detectors.py
GoOrganizeResponsibilityDetector ¶
Bases: ViolationDetector[GoSinglePurposePackageConfig]
Detects catch-all package names like util, common, or helper.
"Each package fulfils a single purpose" — generic package names indicate a grab-bag of unrelated functionality.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return detector identifier.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string. TYPE: |
Methods:¶
detect ¶
Detect catch-all Go package names.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with source code. TYPE: |
config | Detector configuration. |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Detected violations. |
Source code in src/mcp_zen_of_languages/languages/go/detectors.py
GoEarlyReturnDetector ¶
Bases: ViolationDetector[GoEarlyReturnConfig]
Flags err == nil guards that nest the happy path instead of returning early.
Go convention favours returning errors immediately to keep the main logic at the top indentation level.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return detector identifier.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string. TYPE: |
Methods:¶
detect ¶
Detect err == nil nesting anti-pattern.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with source code. TYPE: |
config | Detector configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Detected violations. |
Source code in src/mcp_zen_of_languages/languages/go/detectors.py
GoEmbeddingDepthDetector ¶
Bases: ViolationDetector[GoEmbeddingDepthConfig]
Flags structs with too many anonymously embedded types.
Go allows embedding struct types without a field name. Deep embedding chains make the type hierarchy hard to reason about and introduce implicit method promotion conflicts. This detector counts anonymous (embedded) fields inside each struct definition and flags files where any struct exceeds max_embedding_depth.
An anonymous embedded field is a struct field with no explicit name — only a type (e.g. io.Reader or *Base). Named fields such as Name Type are excluded because they follow the \w+ \w+ pattern.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return detector identifier.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string. TYPE: |
Methods:¶
detect ¶
Detect excessive struct embedding depth.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with source code. TYPE: |
config | Detector configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Detected violations. |
Source code in src/mcp_zen_of_languages/languages/go/detectors.py
GoConcurrencyCallerDetector ¶
Bases: ViolationDetector[GoConcurrencyCallerConfig]
Flags functions that spawn goroutines internally.
Go proverb: leave concurrency decisions to the caller so that library code remains composable and testable.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return detector identifier.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string. TYPE: |
Methods:¶
detect ¶
Detect internal goroutine spawning.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with source code. TYPE: |
config | Detector configuration. |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Detected violations. |
Source code in src/mcp_zen_of_languages/languages/go/detectors.py
GoSimplicityDetector ¶
Bases: ViolationDetector[GoSimplicityConfig]
Flags empty interface usage that weakens type safety.
interface{} (or any) discards compile-time type information. Prefer specific types or small interfaces.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return detector identifier.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string. TYPE: |
Methods:¶
detect ¶
Detect empty interface usage.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with source code. TYPE: |
config | Detector configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Detected violations. |
Source code in src/mcp_zen_of_languages/languages/go/detectors.py
GoTestPresenceDetector ¶
Bases: ViolationDetector[GoTestPresenceConfig]
Flags exported functions without accompanying test functions.
Every exported API surface should have tests to lock in expected behaviour and prevent regressions.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return detector identifier.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string. TYPE: |
Methods:¶
detect ¶
Detect exported functions without tests.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with source code. TYPE: |
config | Detector configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Detected violations. |
Source code in src/mcp_zen_of_languages/languages/go/detectors.py
GoBenchmarkDetector ¶
Bases: ViolationDetector[GoBenchmarkConfig]
Flags optimisation primitives used without benchmark proof.
sync.Pool and unsafe.Pointer are advanced optimisations that should be justified by benchmark results.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return detector identifier.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string. TYPE: |
Methods:¶
detect ¶
Detect optimisation without benchmarks.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with source code. TYPE: |
config | Detector configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Detected violations. |
Source code in src/mcp_zen_of_languages/languages/go/detectors.py
GoModerationDetector ¶
Bases: ViolationDetector[GoModerationConfig]
Flags excessive goroutine spawning within a single file.
Moderation is a virtue — too many go statements in one file suggest uncontrolled concurrency that is hard to reason about.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return detector identifier.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string. TYPE: |
Methods:¶
detect ¶
Detect goroutine proliferation.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with source code. TYPE: |
config | Detector configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Detected violations. |
Source code in src/mcp_zen_of_languages/languages/go/detectors.py
GoMaintainabilityDetector ¶
Bases: ViolationDetector[GoMaintainabilityConfig]
Flags exported functions missing godoc comments.
Go convention requires every exported symbol to have a comment starting with the symbol name for go doc to render correctly.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return detector identifier.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string. TYPE: |
Methods:¶
detect ¶
Detect exported functions without godoc comments.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with source code. TYPE: |
config | Detector configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Detected violations. |
Source code in src/mcp_zen_of_languages/languages/go/detectors.py
JavaScript¶
mcp_zen_of_languages.languages.javascript.detectors ¶
Rule detectors for JavaScript code quality and idiomatic best-practice checks.
Each detector in this module targets a specific JavaScript anti-pattern — from legacy var declarations and loose equality to callback hell and unhandled promise rejections. Detectors scan source lines with regex patterns because no Python-native JavaScript AST is currently integrated.
See Also
JavaScriptAnalyzer: The analyzer that wires these detectors into its pipeline.
Classes¶
JsCallbackNestingDetector ¶
Bases: ViolationDetector[JsCallbackNestingConfig], LocationHelperMixin
Detect deeply nested callbacks that create "callback hell".
JavaScript's event-driven model often leads to pyramids of nested function or => callbacks, making control flow hard to follow and errors easy to swallow. This detector tracks nesting depth by counting callback openings vs. closing braces and flags files that exceed the configured threshold.
Note
Modern code should prefer async/await or chained Promises to keep nesting shallow and readable.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/javascript/detectors.py
JsNoVarDetector ¶
Bases: ViolationDetector[JsNoVarConfig], LocationHelperMixin
Detect usage of the legacy var keyword for variable declarations.
var has function scope rather than block scope, which leads to subtle hoisting bugs and accidental variable leaks in loops and conditionals. This detector scans every line for the \\bvar\\b pattern and reports each occurrence with its exact line and column position.
Note
const (for immutable bindings) and let (for mutable bindings) are block-scoped and should always be preferred over var.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/javascript/detectors.py
JsStrictEqualityDetector ¶
Bases: ViolationDetector[JsStrictEqualityConfig], LocationHelperMixin
Detect loose equality operators (== / !=) in JavaScript.
JavaScript's abstract equality algorithm performs type coercion before comparison, producing counter-intuitive results such as 0 == "" evaluating to true. This detector scans for == and != while skipping their strict counterparts (=== / !==), reporting the exact column of each offending operator.
Note
Strict equality (=== / !==) avoids implicit coercion and is the standard recommendation in ESLint's eqeqeq rule.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/javascript/detectors.py
JsAsyncErrorHandlingDetector ¶
Bases: ViolationDetector[JsAsyncErrorHandlingConfig], LocationHelperMixin
Detect async functions and promise chains with missing error handling.
Unhandled promise rejections crash Node.js processes (since v15+) and silently swallow errors in browsers. This detector raises a violation when an async function body contains no try/catch or .catch() call, and when .then() chains lack a trailing .catch() within a four-line look-ahead window.
Note
Every async call path should terminate in a catch clause to prevent unhandled-rejection crashes in production.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/javascript/detectors.py
JsFunctionLengthDetector ¶
Bases: ViolationDetector[JsFunctionLengthConfig], LocationHelperMixin
Detect JavaScript functions that exceed a configurable line-count limit.
Long functions violate the single-responsibility principle and are harder to test, review, and maintain. This detector finds function keyword declarations, counts lines until the closing brace, and flags any that exceed max_function_length.
Note
Arrow functions and method shorthand are not currently matched; the detector focuses on classic function declarations.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/javascript/detectors.py
JsGlobalStateDetector ¶
Bases: ViolationDetector[JsGlobalStateConfig], LocationHelperMixin
Detect direct access to global mutable state via window, globalThis, or global.
Relying on global state creates hidden coupling between modules, makes code non-deterministic, and breaks in environments where the expected global object differs (e.g., window is undefined in Node.js workers). This detector flags lines that reference any of the three common global accessors.
Note
Prefer dependency injection or module-scoped state to keep functions pure and testable.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/javascript/detectors.py
JsModernFeaturesDetector ¶
Bases: ViolationDetector[JsModernFeaturesConfig], LocationHelperMixin
Detect opportunities to adopt modern ES6+ language features.
Legacy patterns like anonymous function() expressions, string concatenation with +, and repeated property access without destructuring are harder to read and more error-prone. This detector checks for each pattern independently and suggests arrow functions, template literals, or destructuring as replacements.
Note
All modern browsers and Node.js 14+ support these features natively — there is no reason to avoid them in new code.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/javascript/detectors.py
JsMagicNumbersDetector ¶
Bases: ViolationDetector[JsMagicNumbersConfig], LocationHelperMixin
Detect unexplained numeric literals (magic numbers) in JavaScript code.
Magic numbers obscure intent — a reader cannot tell whether 86400 means "seconds in a day" or an unrelated constant. This detector uses a regex to find integer literals ≥ 2 that are not assigned to a named constant, and recommends extracting them into descriptive const declarations.
Note
Common trivial values like 0 and 1 are intentionally excluded from detection to reduce false positives.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/javascript/detectors.py
JsInheritanceDepthDetector ¶
Bases: ViolationDetector[Js009Config], LocationHelperMixin
Detect class hierarchies that exceed a maximum inheritance depth.
Deep extends chains tightly couple subclasses to ancestor implementations, making refactoring fragile and debugging painful. This detector builds a parent-child map from class X extends Y declarations, walks each chain, and flags any that exceed the configured max_inheritance_depth.
Note
Composition (injecting behaviour via constructor parameters or mixins) is generally preferred over deep inheritance in JavaScript.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/javascript/detectors.py
JsPureFunctionDetector ¶
Bases: ViolationDetector[JsPureFunctionConfig], LocationHelperMixin
Detect in-place array mutations that break functional programming principles.
Methods like push, pop, splice, shift, and unshift mutate arrays in place, producing side effects that make functions impure and harder to reason about. This detector scans for these method calls and recommends immutable alternatives such as spread syntax, concat, filter, or slice.
Note
Pure functions with immutable data structures are easier to test, cache, and parallelize in both browser and server environments.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/javascript/detectors.py
JsMeaningfulNamesDetector ¶
Bases: ViolationDetector[Js011Config], LocationHelperMixin
Detect overly short or cryptic identifiers in JavaScript declarations.
Single-character names like x or d outside of loop counters (i, j, k) harm readability and make code searches unreliable. This detector extracts names from const, let, var, function, and class declarations and flags any shorter than min_identifier_length.
Note
Descriptive names serve as inline documentation and reduce the need for explanatory comments.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/javascript/detectors.py
JsDestructuringDetector ¶
Bases: ViolationDetector[JsDestructuringConfig]
Detect repeated property access on the same object without destructuring.
When three or more property accesses reference the same object name, code becomes verbose and harder to maintain. Destructuring extracts multiple properties in a single statement and makes data dependencies explicit.
Note
const { a, b, c } = obj; is more concise and communicates intent better than three separate obj.x assignments.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/javascript/detectors.py
JsObjectSpreadDetector ¶
Bases: ViolationDetector[JsObjectSpreadConfig]
Detect usage of Object.assign where object spread is preferred.
Object.assign mutates its first argument and is harder to read than the equivalent spread syntax { ...a, ...b }. The spread form is also safer because it always creates a new object.
Note
Object spread is supported in all modern browsers and Node.js 8.3+.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/javascript/detectors.py
JsNoWithDetector ¶
Bases: ViolationDetector[JsNoWithConfig]
Detect usage of the with statement in JavaScript.
The with statement creates ambiguous scope chains, making it impossible to tell at a glance whether an identifier refers to a property of the with target or an outer variable. It is forbidden in strict mode and should never appear in modern code.
Note
with was deprecated by ES5 strict mode and is a syntax error in ES modules.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/javascript/detectors.py
JsParamCountDetector ¶
Bases: ViolationDetector[JsParamCountConfig]
Detect functions with too many parameters.
Functions accepting four or more positional parameters are hard to call correctly — callers must remember argument order, and long signatures impede readability. An options-object parameter collapses the list into a single, self-documenting argument.
Note
function create({ name, age, role }) is clearer than function create(name, age, role, active).
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/javascript/detectors.py
JsNoEvalDetector ¶
Bases: ViolationDetector[JsNoEvalConfig]
Detect usage of eval() or new Function() in JavaScript.
Both eval and the Function constructor execute arbitrary strings as code, opening the door to injection attacks, defeating static analysis, and disabling engine optimisations. There is almost always a safer, more performant alternative.
Note
Content-Security-Policy headers block eval by default in modern browsers — relying on it also limits deployment options.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/javascript/detectors.py
JsNoArgumentsDetector ¶
Bases: ViolationDetector[JsNoArgumentsConfig]
Detect usage of the legacy arguments object in JavaScript.
The arguments object is not a real Array, lacks arrow-function support, and prevents engine optimisations. Rest parameters (...args) provide a true array with full method support and work consistently in both regular and arrow functions.
Note
arguments is unavailable inside arrow functions, so migrating early avoids runtime errors during future refactoring.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/javascript/detectors.py
JsNoPrototypeMutationDetector ¶
Bases: ViolationDetector[JsNoPrototypeMutationConfig]
Detect mutations of built-in object prototypes.
Assigning to Array.prototype, String.prototype, or other built-in prototypes pollutes every instance in the runtime, causing unpredictable interactions between unrelated modules and libraries.
Note
If custom behaviour is needed, use a wrapper function or subclass instead of modifying the shared prototype chain.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector configuration that controls thresholds. |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/javascript/detectors.py
JSON¶
mcp_zen_of_languages.languages.json.detectors ¶
Detectors for JSON/JSON5 structural and semantic quality checks.
Classes¶
JsonStrictnessDetector ¶
Bases: ViolationDetector[JsonStrictnessConfig], LocationHelperMixin
Flag trailing commas when strict JSON output is expected.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
Methods:¶
detect ¶
Detect strict-mode trailing comma violations.
Source code in src/mcp_zen_of_languages/languages/json/detectors.py
JsonSchemaConsistencyDetector ¶
Bases: ViolationDetector[JsonSchemaConsistencyConfig], LocationHelperMixin
Detect excessive JSON nesting depth.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
Methods:¶
detect ¶
Detect deep nesting beyond the configured threshold.
Source code in src/mcp_zen_of_languages/languages/json/detectors.py
JsonDuplicateKeyDetector ¶
Bases: ViolationDetector[JsonDuplicateKeyConfig], LocationHelperMixin
Detect duplicate keys in JSON objects.
Duplicate object keys silently override earlier values in most parsers, leading to hard-to-diagnose bugs. This detector uses a parse-time object_pairs_hook to catch duplicates before they are lost.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
Methods:¶
detect ¶
Detect duplicate keys while preserving parse-time key order.
Source code in src/mcp_zen_of_languages/languages/json/detectors.py
JsonMagicStringDetector ¶
Bases: ViolationDetector[JsonMagicStringConfig], LocationHelperMixin
Detect repeated magic-string values.
Repeated literal strings scattered across a JSON file make maintenance hazardous — updating one instance while missing others leads to inconsistency. This detector flags string values that appear at least min_repetition times and are at least min_length characters long (ignoring semver-like strings such as ^1.2.3).
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
Methods:¶
detect ¶
Detect repeated literal strings that behave like magic constants.
Source code in src/mcp_zen_of_languages/languages/json/detectors.py
JsonDateFormatDetector ¶
Bases: ViolationDetector[JsonDateFormatConfig], LocationHelperMixin
Identify date strings that deviate from ISO 8601 formatting.
JSON has no native date type, so dates are encoded as strings. Using locale-dependent formats like MM/DD/YYYY creates ambiguity (is 02/03/2024 the 2nd of March or the 3rd of February?). Prefer YYYY-MM-DD or the full YYYY-MM-DDTHH:MM:SSZ for unambiguous, sortable date representation.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
Methods:¶
detect ¶
Detect string values that look like dates but are not ISO 8601.
Source code in src/mcp_zen_of_languages/languages/json/detectors.py
JsonNullHandlingDetector ¶
Bases: ViolationDetector[JsonNullHandlingConfig], LocationHelperMixin
Report top-level object keys whose values are explicitly null.
Explicit null values in JSON can signal intentional absence or simply forgotten clean-up. At the top level of a configuration document they almost always mean the key should be omitted rather than set to null. This detector flags documents where more than max_top_level_nulls top-level keys carry a null value.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
Methods:¶
detect ¶
Detect top-level object keys explicitly set to null.
Source code in src/mcp_zen_of_languages/languages/json/detectors.py
JsonKeyCasingDetector ¶
Bases: ViolationDetector[JsonKeyCasingConfig], LocationHelperMixin
Detect mixed key casing at the same object level.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
Methods:¶
detect ¶
Detect mixed key casing at the same object level.
Source code in src/mcp_zen_of_languages/languages/json/detectors.py
JsonArrayOrderDetector ¶
Bases: ViolationDetector[JsonArrayOrderConfig], LocationHelperMixin
Detect oversized inline arrays.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
Methods:¶
detect ¶
Detect arrays that exceed the allowed inline size.
Source code in src/mcp_zen_of_languages/languages/json/detectors.py
JsonNullSprawlDetector ¶
Bases: ViolationDetector[JsonNullSprawlConfig], LocationHelperMixin
Detect excessive null values across JSON objects/arrays.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
Methods:¶
detect ¶
Detect excessive use of null across a document.
Source code in src/mcp_zen_of_languages/languages/json/detectors.py
PowerShell¶
mcp_zen_of_languages.languages.powershell.detectors ¶
Rule detectors for PowerShell code quality and automation best-practice checks.
Each detector in this module targets a specific PowerShell anti-pattern — from alias usage in scripts and Write-Host misuse to global scope pollution and missing CmdletBinding. Detectors scan source lines with regex patterns because no Python-native PowerShell AST is currently integrated.
See Also
PowerShellAnalyzer: The analyzer that wires these detectors into its pipeline.
Classes¶
PowerShellApprovedVerbDetector ¶
Bases: ViolationDetector[PowerShellApprovedVerbConfig], LocationHelperMixin
Detect function names that use unapproved PowerShell verbs.
PowerShell mandates a standard set of verbs (Get, Set, New, Remove, etc.) for the Verb-Noun naming convention. Using non-standard verbs like Fetch-Data or Grab-Item triggers import warnings, breaks discoverability in Get-Command, and violates the PowerShell module publishing guidelines.
Note
Run Get-Verb in a PowerShell session to see the full list of approved verbs and their expected usage groups.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/powershell/detectors.py
PowerShellErrorHandlingDetector ¶
Bases: ViolationDetector[PowerShellErrorHandlingConfig], LocationHelperMixin
Detect scripts that lack any form of error handling.
PowerShell's default Continue error action silently moves past non-terminating errors, allowing scripts to report success despite partial failures. This detector flags scripts that contain no try/catch blocks and no -ErrorAction parameters.
Note
Use $ErrorActionPreference = 'Stop' at the script level or -ErrorAction Stop per cmdlet to promote errors to terminating exceptions that try/catch can handle.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/powershell/detectors.py
PowerShellPascalCaseDetector ¶
Bases: ViolationDetector[PowerShellPascalCaseConfig], LocationHelperMixin
Detect function names that violate PascalCase naming conventions.
PowerShell's ecosystem expects Verb-Noun function names in PascalCase (e.g., Get-ChildItem). Functions named get_data or fetchItems break tab-completion expectations, look foreign alongside built-in cmdlets, and confuse users accustomed to the standard naming pattern.
Note
The regex validates both standalone PascalCase names and hyphenated Verb-Noun pairs to accommodate advanced functions and modules.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/powershell/detectors.py
PowerShellCmdletBindingDetector ¶
Bases: ViolationDetector[PowerShellCmdletBindingConfig], LocationHelperMixin
Detect advanced functions missing [CmdletBinding()] and param().
Without [CmdletBinding()], a function cannot participate in the common-parameter ecosystem (-Verbose, -Debug, -ErrorAction, -WhatIf). Scripts that define functions but omit the attribute lose access to PowerShell's built-in safety and diagnostics features.
Note
[CmdletBinding()] paired with a param() block is the minimum requirement for production-quality advanced functions.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/powershell/detectors.py
PowerShellVerboseDebugDetector ¶
Bases: ViolationDetector[PowerShellVerboseDebugConfig], LocationHelperMixin
Detect Write-Host calls that should use Write-Verbose or Write-Debug.
Write-Host writes directly to the console host, bypassing PowerShell's output streams. Its output cannot be captured, redirected, or suppressed — making scripts unusable in automated pipelines, remoting sessions, and CI/CD environments. This detector flags every Write-Host occurrence.
Note
Use Write-Verbose for operational messages, Write-Debug for developer diagnostics, and Write-Output for pipeline data.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/powershell/detectors.py
PowerShellPositionalParamsDetector ¶
Bases: ViolationDetector[PowerShellPositionalParamsConfig], LocationHelperMixin
Detect reliance on $args for positional parameter access.
Using the automatic $args variable instead of a typed param() block sacrifices type validation, tab completion, mandatory-parameter enforcement, and pipeline binding. This detector scans for $args references and recommends named parameters.
Note
Define explicit [Parameter()] attributes with types and validation to make functions self-documenting and IDE-friendly.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/powershell/detectors.py
PowerShellPipelineUsageDetector ¶
Bases: ViolationDetector[PowerShellPipelineUsageConfig], LocationHelperMixin
Detect ForEach-Object or foreach loops that should use pipelines.
PowerShell's pipeline streams objects one at a time, enabling memory- efficient processing of large datasets. Explicit foreach loops without a pipeline accumulate entire collections in memory and miss the composability benefits of chaining cmdlets with |.
Note
Pipeline-aware code like Get-Process | Where-Object CPU -gt 50 is both more idiomatic and more memory-efficient than loop-based equivalents.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/powershell/detectors.py
PowerShellShouldProcessDetector ¶
Bases: ViolationDetector[PowerShellShouldProcessConfig], LocationHelperMixin
Detect destructive cmdlet verbs missing SupportsShouldProcess.
Functions that Remove, Set, Stop, Clear, Restart, Disable, or Enable resources should declare [CmdletBinding(SupportsShouldProcess)] so that callers can pass -WhatIf for dry-run confirmation and -Confirm for interactive safety. This detector flags destructive verbs without the attribute.
Note
Always call $PSCmdlet.ShouldProcess() before performing the destructive action to honour -WhatIf and -Confirm flags.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/powershell/detectors.py
PowerShellSplattingDetector ¶
Bases: ViolationDetector[PowerShellSplattingConfig], LocationHelperMixin
Detect cmdlet calls with many inline parameters that should use splatting.
Lines passing four or more -Parameter Value pairs become hard to read, impossible to diff cleanly, and error-prone to maintain. Splatting (@params) moves parameters into a hashtable variable, improving readability and enabling parameter reuse. This detector counts - prefixed tokens per line, skipping lines already using @.
Note
Splatting also simplifies conditional parameter inclusion by letting you build the hashtable dynamically before the call.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/powershell/detectors.py
PowerShellParameterValidationDetector ¶
Bases: ViolationDetector[PowerShellParameterValidationConfig], LocationHelperMixin
Detect param() blocks that lack [Validate*] attributes.
PowerShell's validation attributes ([ValidateNotNullOrEmpty()], [ValidateRange()], [ValidateSet()], etc.) enforce input constraints before the function body runs, producing clear error messages without manual guard clauses. This detector flags param() blocks that omit all validation attributes.
Note
Declarative validation is preferred over manual if checks because it integrates with Get-Help and IDE tooling.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/powershell/detectors.py
PowerShellCommentHelpDetector ¶
Bases: ViolationDetector[PowerShellCommentHelpConfig], LocationHelperMixin
Detect functions missing comment-based help with .SYNOPSIS.
PowerShell's Get-Help system relies on structured comment blocks containing .SYNOPSIS, .DESCRIPTION, .PARAMETER, and .EXAMPLE sections. Without them, users cannot discover how to use a function without reading its source code. This detector flags the absence of .SYNOPSIS in the file.
Note
Comment-based help also enables -? and tab-completion of parameter descriptions in the console.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/powershell/detectors.py
PowerShellAliasUsageDetector ¶
Bases: ViolationDetector[PowerShellAliasUsageConfig], LocationHelperMixin
Detect built-in aliases (gci, ls, %, ?) used in scripts.
Aliases like gci, ls, dir, cat, %, and ? vary across platforms (ls maps to Get-ChildItem on Windows but to /bin/ls on Linux) and are not guaranteed to exist in constrained environments like JEA endpoints. This detector scans for common alias tokens and recommends full cmdlet names for portability.
Note
Aliases are fine for interactive sessions but should never appear in shared scripts, modules, or CI/CD automation.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/powershell/detectors.py
PowerShellReturnObjectsDetector ¶
Bases: ViolationDetector[PowerShellReturnObjectsConfig], LocationHelperMixin
Detect functions that return formatted text instead of objects.
Using Format-Table or Out-String inside a function bakes a specific display format into the output, preventing downstream cmdlets from filtering, sorting, or exporting the data. PowerShell functions should return rich objects and let the caller choose the presentation format.
Note
Reserve Format-* cmdlets for the final display step in the console, never inside reusable functions or modules.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/powershell/detectors.py
PowerShellScopeUsageDetector ¶
Bases: ViolationDetector[PowerShellScopeUsageConfig], LocationHelperMixin
Detect explicit $global: and $script: scope modifiers.
Accessing $global: or $script: variables creates hidden coupling between functions, makes testing difficult (state leaks between test runs), and can introduce race conditions in parallel execution. This detector flags any use of these scope prefixes.
Note
Prefer passing state through parameters and return values to keep functions self-contained and testable in isolation.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/powershell/detectors.py
PowerShellNullHandlingDetector ¶
Bases: ViolationDetector[PowerShellNullHandlingConfig], LocationHelperMixin
Detect functions and param blocks that never check for $null.
PowerShell treats $null differently from empty strings and empty collections, and cmdlets can return $null unexpectedly when no objects match a filter. Functions that process pipeline input or optional parameters without $null guards risk NullReference errors at runtime. This detector flags scripts containing function or param() declarations with no $null check.
Note
Use if ($null -ne $value) (with $null on the left) to avoid PowerShell's counter-intuitive collection comparison behaviour.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/powershell/detectors.py
Python¶
mcp_zen_of_languages.languages.python.detectors ¶
Python-specific violation detectors implementing the Strategy pattern.
Each detector class encapsulates a single zen-principle check against Python source code. Detectors are instantiated by the registry, wired into a DetectionPipeline, and executed during PythonAnalyzer.analyze().
Detectors fall into two categories:
- Syntactic detectors — operate directly on source lines or the stdlib
asttree (e.g.StarImportDetector,BareExceptDetector). - Metric-gated detectors — rely on pre-computed metrics stored in
AnalysisContext(e.g.CyclomaticComplexityDetectorreadscontext.cyclomatic_summary).
Classes¶
StarImportDetector ¶
Bases: ViolationDetector[StarImportConfig], LocationHelperMixin
Detect wildcard from X import * statements that pollute the module namespace.
Star imports pull every public name from the target module into the current namespace, making it impossible to tell where a name originated from by reading the source alone. They also defeat static analysis tools and IDE auto-complete, and create subtle bugs when two star-imported modules export the same name.
Implements the "Namespaces are one honking great idea" zen principle: explicit imports keep namespaces clean and traceable.
The detector scans raw source lines with a regex rather than walking the AST, because import * is a lexical pattern that is faster to match textually and does not require a successful parse.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return "star_imports" for detector registry lookup.
| RETURNS | DESCRIPTION |
|---|---|
str | Registry key used to wire this detector to its rule config. TYPE: |
Methods:¶
detect ¶
Scan source lines for from X import * patterns.
Each matching line produces a violation pinpointed to the import keyword column so that editors can jump straight to the offending statement.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context carrying the source text to scan. TYPE: |
config | Star-import detector thresholds and rule metadata. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: One violation per wildcard import found. |
Source code in src/mcp_zen_of_languages/languages/python/detectors.py
BareExceptDetector ¶
Bases: ViolationDetector[BareExceptConfig], LocationHelperMixin
Detect bare except: clauses and silently swallowed exceptions.
A bare except: catches everything — including KeyboardInterrupt and SystemExit — making it nearly impossible to interrupt or terminate the process cleanly. Empty handlers (except SomeError: pass) are equally dangerous because they hide real failures and turn bugs into silent data corruption.
Implements the "Errors should never pass silently" zen principle: exceptions must be caught specifically and handled meaningfully.
Detection works on raw source lines using regex matching, covering three patterns: bare except:, inline except X: pass, and multi-line except X: followed by a pass/... body.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return "bare_except" for detector registry lookup.
| RETURNS | DESCRIPTION |
|---|---|
str | Registry key used to wire this detector to its rule config. TYPE: |
Methods:¶
detect ¶
Scan source lines for bare excepts and empty exception handlers.
Three patterns are checked in order for each line:
except:with no exception type.- Inline
except SomeError: passorexcept SomeError: .... except SomeError:on one line followed bypass/...on the next.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with the source code to inspect. TYPE: |
config | Bare-except detector thresholds and rule metadata. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: One violation per offending |
Source code in src/mcp_zen_of_languages/languages/python/detectors.py
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | |
MagicNumberDetector ¶
Bases: ViolationDetector[MagicNumberConfig], LocationHelperMixin
Detect excessive use of unexplained numeric literals (magic numbers).
Numeric literals scattered through code obscure intent — a reader seeing if retries > 3 cannot tell whether 3 is an arbitrary guess, a business rule, or a protocol limit. Named constants (MAX_RETRIES = 3) make the code self-documenting and centralise change points.
Implements the "Readability counts" zen principle: every value should communicate its purpose through a descriptive name.
The detector regex-scans each line for integers ≥ 2 and non-integer floats, skipping comments, blank lines, and ALL_CAPS = … constant assignments. A violation fires only when the total count exceeds the configured max_magic_numbers threshold.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return "magic_number" for detector registry lookup.
| RETURNS | DESCRIPTION |
|---|---|
str | Registry key used to wire this detector to its rule config. TYPE: |
Methods:¶
detect ¶
Count numeric literals across non-trivial lines and flag when too many.
Lines that are blank, comments, or ALL_CAPS constant assignments are excluded. The location of the first match is reported to guide the developer to the most likely starting point for refactoring.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context carrying the source text. TYPE: |
config | Magic-number detector thresholds ( TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: At most one violation when the count exceeds the configured threshold. |
Source code in src/mcp_zen_of_languages/languages/python/detectors.py
ComplexOneLinersDetector ¶
Bases: ViolationDetector[ComplexOneLinersConfig], LocationHelperMixin
Detect overly dense one-liner expressions that sacrifice readability.
Deeply nested comprehensions and long ternary chains pack too much logic into a single line, making code hard to debug and impossible to set breakpoints inside. Splitting them into named intermediate steps improves clarity without sacrificing performance.
Implements the "Simple is better than complex" zen principle: favour straightforward multi-line code over clever one-liners.
Two heuristics are applied per line:
- Count of
forkeywords exceedingmax_for_clausesflags nested comprehensions. - Lines longer than
max_line_lengthcontaining bothifandelseflag complex ternary expressions.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return "complex_one_liners" for detector registry lookup.
| RETURNS | DESCRIPTION |
|---|---|
str | Registry key used to wire this detector to its rule config. TYPE: |
Methods:¶
detect ¶
Scan each line for nested comprehensions or complex ternary chains.
Blank lines and comments are skipped. Each offending line produces exactly one violation, choosing the most specific message variant (comprehension vs. generic one-liner).
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context carrying the source text. TYPE: |
config | One-liner detector thresholds ( TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: One violation per line that exceeds the complexity heuristics. |
Source code in src/mcp_zen_of_languages/languages/python/detectors.py
ContextManagerDetector ¶
Bases: ViolationDetector[ContextManagerConfig], LocationHelperMixin
Detect open() calls not wrapped in a with context manager.
File handles opened without a context manager risk resource leaks if an exception occurs before .close() is called. The with statement guarantees cleanup even under error conditions.
Implements the "Explicit is better than implicit" zen principle: resource lifetime should be governed by a visible scope, not by garbage collection timing.
Detection walks the stdlib ast tree looking for Call nodes whose function name is open. For each match, a surrounding snippet is checked for with open to avoid false positives on properly managed handles.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return "context_manager" for detector registry lookup.
| RETURNS | DESCRIPTION |
|---|---|
str | Registry key used to wire this detector to its rule config. TYPE: |
Methods:¶
detect ¶
Walk the AST for open() calls and verify with wrapping.
For each open() call node, a small surrounding snippet (±2 lines) is checked for with open. This avoids false positives on handles that are already managed by a context manager.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with source text and (optionally) a pre-parsed AST. TYPE: |
config | Context-manager detector thresholds and rule metadata. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: One violation per |
Source code in src/mcp_zen_of_languages/languages/python/detectors.py
DocstringDetector ¶
Bases: ViolationDetector[DocstringConfig], LocationHelperMixin
Detect top-level functions and classes missing a docstring.
Public APIs without docstrings force consumers to read source code to understand behaviour, parameter expectations, and return semantics. Even a one-line docstring dramatically improves discoverability and IDE tooltip support.
Implements the "Readability counts" zen principle: every public interface should document its contract.
Detection uses ast.iter_child_nodes on the module root so that only module-level (top-level) definitions are checked — private helpers nested inside other functions are intentionally excluded.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return "docstrings" for detector registry lookup.
| RETURNS | DESCRIPTION |
|---|---|
str | Registry key used to wire this detector to its rule config. TYPE: |
Methods:¶
detect ¶
Parse the module AST and flag top-level defs lacking a docstring.
Iterates only immediate children of the module node via ast.iter_child_nodes. FunctionDef and ClassDef nodes are checked with ast.get_docstring; classes receive a higher severity because they typically represent broader public contracts.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with source text to inspect. TYPE: |
config | Docstring detector thresholds and rule metadata. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: One violation per undocumented top-level function or class. |
Source code in src/mcp_zen_of_languages/languages/python/detectors.py
LineLengthDetector ¶
Bases: ViolationDetector[LineLengthConfig], LocationHelperMixin
Detect source lines that exceed a configured character limit.
Overly long lines force horizontal scrolling in editors, break side-by- side diffs in code review, and often signal that a statement is doing too much at once. PEP 8 recommends 79 characters; most modern projects settle on 88-120.
Implements the "Beautiful is better than ugly" zen principle: consistent line length produces a visually uniform codebase.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return "line_length" for detector registry lookup.
| RETURNS | DESCRIPTION |
|---|---|
str | Registry key used to wire this detector to its rule config. TYPE: |
Methods:¶
detect ¶
Iterate source lines and emit a violation for each exceeding max_line_length.
The violation location column is set to max_len + 1 so that editors highlight exactly where the overflow begins.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context carrying the source text. TYPE: |
config | Line-length detector thresholds ( TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: One violation per over-long line. |
Source code in src/mcp_zen_of_languages/languages/python/detectors.py
ClassSizeDetector ¶
Bases: ViolationDetector[ClassSizeConfig], LocationHelperMixin
Detect classes whose line count exceeds the configured maximum.
Classes that grow beyond a few hundred lines tend to accumulate unrelated responsibilities, making them hard to understand, test, and extend. Splitting oversized classes into smaller, cohesive units improves modularity and keeps each unit within a developer's working memory.
Implements the "Simple is better than complex" zen principle: small classes with clear responsibility boundaries are easier to reason about.
Detection walks the AST for ClassDef nodes and measures each class by the span from its lineno to the lineno of its last body statement.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return "class_size" for detector registry lookup.
| RETURNS | DESCRIPTION |
|---|---|
str | Registry key used to wire this detector to its rule config. TYPE: |
Methods:¶
detect ¶
Walk the AST and flag classes whose line span exceeds max_class_length.
Falls back to ast.parse when the pre-built context.ast_tree is unavailable or not a stdlib ast.AST.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with source text and parsed tree. TYPE: |
config | Class-size detector thresholds ( TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: One violation per oversized class. |
Source code in src/mcp_zen_of_languages/languages/python/detectors.py
NameStyleDetector ¶
Bases: ViolationDetector[NameStyleConfig], LocationHelperMixin
Detect function and variable names that violate Python's snake_case convention.
PEP 8 mandates snake_case for functions and variables. Mixing camelCase or other styles within a Python module confuses readers and clashes with the standard library's consistent naming.
Implements the "There should be one obvious way to do it" zen principle: a single naming convention removes cognitive overhead and keeps style debates out of code review.
The primary path walks the stdlib ast tree to find FunctionDef and Assign nodes. When parsing fails (e.g. partial code snippets), a regex-based heuristic fallback extracts def and assignment names directly from source text.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return "name_style" for detector registry lookup.
| RETURNS | DESCRIPTION |
|---|---|
str | Registry key used to wire this detector to its rule config. TYPE: |
Methods:¶
detect ¶
Walk the AST for non-snake_case function and variable names.
FunctionDef nodes and Assign targets are checked against a snake_case regex. ALL_CAPS constant assignments are intentionally skipped. Tuple/list unpacking targets are flattened before checking.
Falls back to _heuristic_detect when the AST cannot be built.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with source text and parsed tree. TYPE: |
config | Name-style detector thresholds and rule metadata. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: One violation per non-conforming name. |
Source code in src/mcp_zen_of_languages/languages/python/detectors.py
869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 | |
ShortVariableNamesDetector ¶
Bases: ViolationDetector[ShortVariableNamesConfig], LocationHelperMixin
Detect variables and loop targets with names shorter than the configured minimum.
Single-letter variables like x, d, or n obscure intent and make grep-based navigation unreliable. Descriptive names (index, data, count) are self-documenting and reduce the need for inline comments.
Implements the "Readability counts" zen principle: code is read far more often than it is written, so names should communicate purpose.
Detection walks the AST for Assign, AnnAssign, AugAssign, For, and AsyncFor nodes. ALL_CAPS constants and a configurable allow-list of conventional loop names (i, j, k, _) are excluded. Falls back to regex heuristics on parse failure.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return "short_variable_names" for detector registry lookup.
| RETURNS | DESCRIPTION |
|---|---|
str | Registry key used to wire this detector to its rule config. TYPE: |
Methods:¶
detect ¶
Walk the AST and flag identifiers shorter than min_identifier_length.
Assignment targets (including tuple/list unpacking), annotated assignments, augmented assignments, and for/async for loop variables are all inspected. ALL_CAPS constants and names in allowed_loop_names are skipped.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with source text and parsed tree. TYPE: |
config | Short-name detector thresholds ( TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: One violation per overly short identifier. |
Source code in src/mcp_zen_of_languages/languages/python/detectors.py
1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 | |
CyclomaticComplexityDetector ¶
Bases: ViolationDetector[CyclomaticComplexityConfig], LocationHelperMixin
Detect functions whose cyclomatic complexity exceeds the configured threshold.
Cyclomatic complexity counts the number of independent execution paths through a function. High values correlate strongly with bug density and make unit testing exponentially harder because each path requires at least one test case.
Implements the "Simple is better than complex" zen principle: functions with low branching are easier to read, test, and maintain.
Detection reads the pre-computed context.cyclomatic_summary (populated by radon via MetricsCollector). Both the module-wide average and individual function blocks are checked. Per-block severity is scaled by how far the complexity exceeds the threshold.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return "cyclomatic_complexity" for detector registry lookup.
| RETURNS | DESCRIPTION |
|---|---|
str | Registry key used to wire this detector to its rule config. TYPE: |
Methods:¶
detect ¶
Check module-wide average and per-function cyclomatic complexity.
When the module average exceeds max_cyclomatic_complexity, a violation is emitted at the first def location. Individual function blocks that exceed the threshold also produce violations with severity scaled proportionally to the overshoot.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with a pre-computed TYPE: |
config | Cyclomatic-complexity detector thresholds. |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: One violation per over-complex function, plus optionally one for the module-wide average. |
Source code in src/mcp_zen_of_languages/languages/python/detectors.py
1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 | |
NestingDepthDetector ¶
Bases: ViolationDetector[NestingDepthConfig], LocationHelperMixin
Detect code blocks with excessive indentation depth and nested loops.
Deeply nested code forces readers to maintain a large mental stack of conditions and scopes. Beyond three levels, bugs hide in corner cases that are nearly impossible to reason about during review.
Implements the "Flat is better than nested" zen principle: early returns, guard clauses, and helper functions keep nesting shallow.
Two checks are performed:
- Indentation-based nesting depth via
detect_deep_nesting. - AST-based loop nesting depth — nested
for/whileloops beyond depth 1 are flagged separately.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return "nesting_depth" for detector registry lookup.
| RETURNS | DESCRIPTION |
|---|---|
str | Registry key used to wire this detector to its rule config. TYPE: |
Methods:¶
detect ¶
Check indentation depth and loop nesting against thresholds.
First delegates to detect_deep_nesting for an indentation-based measurement. Then separately computes the maximum loop nesting depth via AST traversal and flags anything beyond depth 1.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with source text and parsed tree. TYPE: |
config | Nesting-depth detector thresholds ( TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Up to two violations — one for general nesting, one for loop nesting. |
Source code in src/mcp_zen_of_languages/languages/python/detectors.py
1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 | |
LongFunctionDetector ¶
Bases: ViolationDetector[LongFunctionConfig], LocationHelperMixin
Detect functions whose line count exceeds the configured maximum.
Long functions tend to do too much — mixing input validation, business logic, side effects, and formatting in a single scope. Shorter functions with descriptive names serve as self-documenting building blocks that are individually testable.
Implements the "Simple is better than complex" zen principle: small, focused functions are the foundation of maintainable code.
Detection delegates to detect_long_functions which measures each def block by line span.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return "long_functions" for detector registry lookup.
| RETURNS | DESCRIPTION |
|---|---|
str | Registry key used to wire this detector to its rule config. TYPE: |
Methods:¶
detect ¶
Delegate to detect_long_functions and emit violations for oversized defs.
Each function exceeding max_function_length lines produces one violation pinpointed to its def statement.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with source text and parsed tree. TYPE: |
config | Long-function detector thresholds ( TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: One violation per oversized function. |
Source code in src/mcp_zen_of_languages/languages/python/detectors.py
GodClassDetector ¶
Bases: ViolationDetector[GodClassConfig]
Detect God classes — classes with too many methods or lines of code.
A God class absorbs responsibilities that should be distributed across several smaller collaborating classes. They become magnets for change, difficult to test in isolation, and resistant to parallel development.
Implements the "Simple is better than complex" zen principle: each class should have a single, well-defined responsibility.
Detection delegates to detect_god_classes which counts methods and measures line span per class, comparing against max_methods and max_class_length.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return "god_classes" for detector registry lookup.
| RETURNS | DESCRIPTION |
|---|---|
str | Registry key used to wire this detector to its rule config. TYPE: |
Methods:¶
detect ¶
Delegate to detect_god_classes and flag classes that breach thresholds.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with source text. TYPE: |
config | God-class detector thresholds ( TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: One violation per God class found. |
Source code in src/mcp_zen_of_languages/languages/python/detectors.py
MagicMethodDetector ¶
Bases: ViolationDetector[MagicMethodConfig], LocationHelperMixin
Detect classes that overload too many dunder (magic) methods.
While dunder methods are powerful, overusing them creates an opaque API where the behaviour of operators like +, [], and == becomes hard to predict. A class implementing more than a handful of magic methods is often trying to act like a built-in type and should instead expose explicit method names.
Implements the "Explicit is better than implicit" zen principle: prefer named methods over operator overloading for non-obvious semantics.
Detection delegates to detect_magic_methods_overuse which collects all __dunder__ method definitions per class, then flags classes exceeding max_magic_methods.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return "magic_methods" for detector registry lookup.
| RETURNS | DESCRIPTION |
|---|---|
str | Registry key used to wire this detector to its rule config. TYPE: |
Methods:¶
detect ¶
Count dunder method definitions and flag when exceeding the threshold.
The violation is anchored at the first def __ occurrence in the source to guide the developer to the most relevant class.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with source text. TYPE: |
config | Magic-method detector thresholds ( TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: At most one violation when the count exceeds the configured maximum. |
Source code in src/mcp_zen_of_languages/languages/python/detectors.py
CircularDependencyDetector ¶
Bases: ViolationDetector[CircularDependencyConfig]
Detect circular import dependencies across modules.
Circular imports are a common source of ImportError at runtime and indicate tangled module responsibilities. They also prevent clean layering and make it impossible to understand a module in isolation.
Implements the "Flat is better than nested" zen principle applied to the dependency graph: modules should form a directed acyclic graph.
Detection uses the pre-built context.dependency_analysis graph edges and delegates cycle-finding to detect_dependency_cycles, which performs a topological sort and reports back-edges.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return "circular_dependencies" for detector registry lookup.
| RETURNS | DESCRIPTION |
|---|---|
str | Registry key used to wire this detector to its rule config. TYPE: |
Methods:¶
detect ¶
Extract dependency graph edges and flag any import cycles.
Skips detection entirely when no dependency_analysis is available (single-file mode without repository context).
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with a pre-built dependency graph. TYPE: |
config | Circular-dependency detector thresholds and rule metadata. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: One violation per import cycle detected. |
Source code in src/mcp_zen_of_languages/languages/python/detectors.py
DeepInheritanceDetector ¶
Bases: ViolationDetector[DeepInheritanceConfig]
Detect class hierarchies that exceed a safe inheritance depth.
Deep inheritance chains (more than two or three levels) create fragile base-class coupling, make method resolution order hard to predict, and encourage overriding rather than composing. Composition via delegation or mixins keeps each class understandable in isolation.
Implements the "Flat is better than nested" zen principle applied to type hierarchies: shallow, wide hierarchies beat deep, narrow ones.
Detection requires multi-file context (context.other_files). It delegates to detect_deep_inheritance which traces class parents across all provided source files.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return "deep_inheritance" for detector registry lookup.
| RETURNS | DESCRIPTION |
|---|---|
str | Registry key used to wire this detector to its rule config. TYPE: |
Methods:¶
detect ¶
Trace class parent chains across files and flag excessive depth.
Requires context.other_files for cross-file class resolution; returns an empty list in single-file mode.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with source text and sibling file map. TYPE: |
config | Deep-inheritance detector thresholds and rule metadata. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: One violation per inheritance chain exceeding the configured depth. |
Source code in src/mcp_zen_of_languages/languages/python/detectors.py
FeatureEnvyDetector ¶
Bases: ViolationDetector[FeatureEnvyConfig]
Detect methods that access another object's data more than their own.
Feature envy is a classic code smell where a method in class A repeatedly reaches into class B's attributes. This suggests the method belongs on B (or on a shared helper) rather than A, and its presence on A couples the two classes unnecessarily.
Implements the "There should be one obvious way to do it" zen principle: behaviour should live next to the data it operates on.
Detection delegates to detect_feature_envy and filters results by min_occurrences to avoid flagging incidental cross-object access.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return "feature_envy" for detector registry lookup.
| RETURNS | DESCRIPTION |
|---|---|
str | Registry key used to wire this detector to its rule config. TYPE: |
Methods:¶
detect ¶
Identify methods excessively accessing another object's attributes.
Results from detect_feature_envy are filtered by min_occurrences to suppress noise from incidental attribute reads.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with source text. TYPE: |
config | Feature-envy detector thresholds ( TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: One violation per envious method exceeding the occurrence threshold. |
Source code in src/mcp_zen_of_languages/languages/python/detectors.py
DuplicateImplementationDetector ¶
Bases: ViolationDetector[DuplicateImplementationConfig]
Detect identical or near-identical function implementations across files.
Copy-pasted logic creates a maintenance multiplier — every bug fix or feature change must be applied in multiple places, and divergence over time turns copies into subtle variants with different edge-case handling.
Implements the "There should be one obvious way to do it" zen principle: shared logic should live in a single canonical location.
Detection requires multi-file context (context.other_files). It delegates to detect_multiple_implementations which compares function bodies across the provided source map.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return "duplicate_implementations" for detector registry lookup.
| RETURNS | DESCRIPTION |
|---|---|
str | Registry key used to wire this detector to its rule config. TYPE: |
Methods:¶
detect ¶
Compare function bodies across files and flag duplicates.
Merges context.other_files with the current file, then delegates to detect_multiple_implementations. Skips detection in single-file mode.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with source text and sibling file map. TYPE: |
config | Duplicate-implementation detector thresholds and rule metadata. |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: One violation per group of duplicated functions, with the |
Source code in src/mcp_zen_of_languages/languages/python/detectors.py
SparseCodeDetector ¶
Bases: ViolationDetector[SparseCodeConfig], LocationHelperMixin
Detect lines packing multiple statements separated by semicolons.
Cramming several statements onto one line (x = 1; y = 2; z = 3) makes code harder to read, harder to step through in a debugger, and breaks the one-statement-per-line convention that most Python style guides assume.
Implements the "Sparse is better than dense" zen principle: each line should do one thing clearly.
Detection delegates to detect_sparse_code which counts semicolon- separated statements per line and reports those exceeding max_statements_per_line.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return "sparse_code" for detector registry lookup.
| RETURNS | DESCRIPTION |
|---|---|
str | Registry key used to wire this detector to its rule config. TYPE: |
Methods:¶
detect ¶
Flag lines containing more than max_statements_per_line statements.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with source text. TYPE: |
config | Sparse-code detector thresholds ( TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: One violation per overly dense line. |
Source code in src/mcp_zen_of_languages/languages/python/detectors.py
ConsistencyDetector ¶
Bases: ViolationDetector[ConsistencyConfig], LocationHelperMixin
Detect mixed naming conventions within a single module.
A module that uses both camelCase and snake_case (or other styles) signals either multiple authors with different habits or unfinished refactoring. Inconsistency forces readers to context-switch between conventions and erodes trust in the codebase.
Implements the "There should be one obvious way to do it" zen principle: pick one naming style and apply it everywhere.
Detection delegates to detect_inconsistent_naming_styles and flags when the number of distinct styles exceeds max_naming_styles.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return "consistency" for detector registry lookup.
| RETURNS | DESCRIPTION |
|---|---|
str | Registry key used to wire this detector to its rule config. TYPE: |
Methods:¶
detect ¶
Count distinct naming styles and flag when too many coexist.
The violation is anchored at the first def statement since naming inconsistency is inherently module-wide rather than localised.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with source text. TYPE: |
config | Consistency detector thresholds ( TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: At most one violation when the style count exceeds the threshold. |
Source code in src/mcp_zen_of_languages/languages/python/detectors.py
ExplicitnessDetector ¶
Bases: ViolationDetector[ExplicitnessConfig], LocationHelperMixin
Detect function parameters missing type annotations.
Type hints are the primary documentation channel for Python function contracts. Without them, callers must read the implementation to discover expected types, and static analysis tools like mypy and pyright cannot verify call-site correctness.
Implements the "Explicit is better than implicit" zen principle: annotated signatures make interfaces self-describing and machine- checkable.
Detection is gated on config.require_type_hints and delegates to detect_missing_type_hints which parses function signatures for un-annotated parameters.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return "explicitness" for detector registry lookup.
| RETURNS | DESCRIPTION |
|---|---|
str | Registry key used to wire this detector to its rule config. TYPE: |
Methods:¶
detect ¶
Scan function signatures for un-annotated parameters.
No-ops when config.require_type_hints is False, allowing projects to opt out of this check.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with source text. TYPE: |
config | Explicitness detector thresholds ( TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: One violation per function with missing type annotations. |
Source code in src/mcp_zen_of_languages/languages/python/detectors.py
NamespaceUsageDetector ¶
Bases: ViolationDetector[NamespaceConfig], LocationHelperMixin
Detect modules with too many top-level symbols or __all__ exports.
A module that defines dozens of public names is likely doing too much and should be split into sub-modules. Overly large __all__ lists signal the same problem from the export side. Keeping modules focused makes imports predictable and navigation fast.
Implements the "Namespaces are one honking great idea" zen principle: each module should own a narrow, well-defined slice of the namespace.
Detection delegates to detect_namespace_usage which counts top-level symbols and __all__ entries, comparing against max_top_level_symbols and max_exports.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return "namespace_usage" for detector registry lookup.
| RETURNS | DESCRIPTION |
|---|---|
str | Registry key used to wire this detector to its rule config. TYPE: |
Methods:¶
detect ¶
Count top-level symbols and __all__ entries against thresholds.
Two independent checks are performed: one for total top-level symbol count and one for __all__ export count. Either or both may fire.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with source text. TYPE: |
config | Namespace detector thresholds ( TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Up to two violations — one for symbols, one for exports. |
Source code in src/mcp_zen_of_languages/languages/python/detectors.py
PythonPracticalityDetector ¶
Bases: ViolationDetector[PythonPracticalityConfig]
Flags over-engineered abstractions like ABCs with likely few implementations.
Python's "practicality beats purity" principle discourages premature abstraction.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return detector identifier.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string. TYPE: |
Methods:¶
detect ¶
Detect over-engineered abstractions.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with source code. TYPE: |
config | Detector configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Detected violations. |
Source code in src/mcp_zen_of_languages/languages/python/detectors.py
PythonExplicitSilenceDetector ¶
Bases: ViolationDetector[PythonExplicitSilenceConfig]
Detects bare except clauses and silently caught exceptions.
Errors should never pass silently unless explicitly silenced.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return detector identifier.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string. TYPE: |
Methods:¶
detect ¶
Detect bare except and silent catch patterns.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with source code. TYPE: |
config | Detector configuration. |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Detected violations. |
Source code in src/mcp_zen_of_languages/languages/python/detectors.py
PythonTodoStubDetector ¶
Bases: ViolationDetector[PythonTodoStubConfig]
Detects TODO, FIXME, HACK, and XXX comments left in source code.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return detector identifier.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string. TYPE: |
Methods:¶
detect ¶
Detect TODO/FIXME/HACK/XXX comment markers.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with source code. TYPE: |
config | Detector configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Detected violations. |
Source code in src/mcp_zen_of_languages/languages/python/detectors.py
PythonPrematureImplDetector ¶
Bases: ViolationDetector[PythonPrematureImplConfig]
Detects raise NotImplementedError stubs without documentation.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return detector identifier.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string. TYPE: |
Methods:¶
detect ¶
Detect NotImplementedError raises.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with source code. TYPE: |
config | Detector configuration. |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Detected violations. |
Source code in src/mcp_zen_of_languages/languages/python/detectors.py
PythonComplexUndocumentedDetector ¶
Bases: ViolationDetector[PythonComplexUndocumentedConfig]
Detects functions missing docstrings.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return detector identifier.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string. TYPE: |
Methods:¶
detect ¶
Detect functions without docstrings.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with source code. TYPE: |
config | Detector configuration. |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Detected violations. |
Source code in src/mcp_zen_of_languages/languages/python/detectors.py
PythonSimpleDocumentedDetector ¶
Bases: ViolationDetector[PythonSimpleDocumentedConfig]
Detects public functions (not starting with _) missing docstrings.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return detector identifier.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string. TYPE: |
Methods:¶
detect ¶
Detect public functions without docstrings.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with source code. TYPE: |
config | Detector configuration. |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Detected violations. |
Source code in src/mcp_zen_of_languages/languages/python/detectors.py
PythonIdiomDetector ¶
Bases: ViolationDetector[PythonIdiomConfig]
Detects non-idiomatic Python patterns like range(len(...)) and == True.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return detector identifier.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string. TYPE: |
Methods:¶
detect ¶
Detect non-idiomatic Python patterns.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with source code. TYPE: |
config | Detector configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Detected violations. |
Source code in src/mcp_zen_of_languages/languages/python/detectors.py
GreyCommitCommentDetector ¶
Bases: ViolationDetector[GreyCommitConfig], LocationHelperMixin
Detect method-level inline comment narratives that belong in docstrings.
Flags comment blocks inside function and method bodies that read like rationale prose rather than short annotations: knowledge-marker comments (NOTE:, REASON:, IMPORTANT:, BECAUSE:, TODO:), multi-line comment blocks, long single-line comments, and comments sitting next to control-flow statements. That kind of documentation renders and stays discoverable when it lives in a function's docstring instead of scattered inline comments.
Note
# noqa, # type: ignore and single-word annotation comments are excluded to minimize false positives.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector registry identifier.
| RETURNS | DESCRIPTION |
|---|---|
str | The literal string TYPE: |
Methods:¶
detect ¶
Parse comment tokens and flag docstring-grade inline rationale.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with source code. TYPE: |
config | Detector configuration with the inline comment length threshold and the enable/disable switch. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations for comment blocks that should be moved into function or method docstrings. |
Note
tokenize.generate_tokens is lazy, so a malformed token stream raises tokenize.TokenError part-way through iteration. The scan degrades best-effort -- keeping the comments collected before the failure -- rather than propagating the error up through the analysis pipeline, matching how _mask_comments handles the same failure elsewhere in the codebase.
Source code in src/mcp_zen_of_languages/languages/python/detectors.py
2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 | |
UnusedArgumentUtilizationDetector ¶
Bases: ViolationDetector[UnusedArgumentUtilizationConfig], LocationHelperMixin
Detect function parameters that are requested but never used.
Every parameter in a signature is a promise of context the function body is expected to use. Flags parameters that are declared but never read, and suggests how to put the missing context to work: logging it, filtering/correlating on it, or removing it from the signature entirely. self/cls receivers, *args/**kwargs catch-alls, and stub bodies (..., pass, or a docstring-only body, e.g. Protocol methods and @overload signatures) are exempt. Underscore-prefixed names are intentionally not exempt — silencing an unused parameter with a leading _ still hides a design question about why the argument exists at all.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector registry identifier.
| RETURNS | DESCRIPTION |
|---|---|
str | The literal string TYPE: |
Methods:¶
detect ¶
Flag ignored function arguments and suggest purposeful integration.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with source code. TYPE: |
config | Detector configuration controlling logging-oriented suggestions and abstract-method exclusion. |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations for parameters that are declared but never read inside the function body. |
Source code in src/mcp_zen_of_languages/languages/python/detectors.py
2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 | |
Ruby¶
mcp_zen_of_languages.languages.ruby.detectors ¶
Zen-rule detectors for Ruby code quality, naming, and architecture checks.
Each detector implements the Strategy pattern as a ViolationDetector subclass, targeting a specific Ruby anti-pattern. Ruby's dynamic runtime and convention-driven culture make disciplined naming, restrained metaprogramming, and idiomatic block usage essential for maintainable code.
See Also
RubyAnalyzer: Template Method analyzer that orchestrates these detectors.
Classes¶
RubyNamingConventionDetector ¶
Bases: ViolationDetector[RubyNamingConventionConfig], LocationHelperMixin
Flags Ruby methods defined with non-snake_case names.
Ruby's community universally expects snake_case for method and variable names. A method starting with an uppercase letter looks like a constant or class reference, breaking the readability contract that Rubyists rely on when scanning code without explicit type annotations.
Note
Only catches def UpperCase patterns; does not inspect local variables.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'ruby_naming_convention' for registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Detector identifier for the naming-convention rule. TYPE: |
Methods:¶
detect ¶
Scan method definitions for non-snake_case names.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with Ruby source text. TYPE: |
config | Threshold configuration for naming conventions. |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: One violation per method using non-snake_case naming. |
Source code in src/mcp_zen_of_languages/languages/ruby/detectors.py
RubyMethodChainDetector ¶
Bases: ViolationDetector[RubyMethodChainConfig], LocationHelperMixin
Detects excessively long method chains that reduce readability.
Ruby's fluent API style encourages chaining, but overly long chains become hard to debug and produce cryptic NoMethodError traces. Breaking chains into named intermediate variables clarifies intent and makes each transformation step independently testable.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'ruby_method_chain' for registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Detector identifier for the method-chain-length rule. TYPE: |
Methods:¶
detect ¶
Flag lines where the number of chained method calls exceeds the threshold.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with Ruby source text. TYPE: |
config | Contains TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/ruby/detectors.py
RubyDryDetector ¶
Bases: ViolationDetector[RubyDryConfig], LocationHelperMixin
Identifies duplicated code lines that violate Don't Repeat Yourself (DRY).
Repeated non-trivial lines signal copy-paste programming, a common anti-pattern in Ruby projects that grow without refactoring. Extracting shared logic into methods, modules, or concerns keeps Ruby codebases concise and aligned with the principle that every piece of knowledge should have a single authoritative representation.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'ruby_dry' for registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Detector identifier for the DRY rule. TYPE: |
Methods:¶
detect ¶
Flag source files containing three or more identical non-blank lines.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with Ruby source text. TYPE: |
config | DRY threshold configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/ruby/detectors.py
RubyBlockPreferenceDetector ¶
Bases: ViolationDetector[RubyBlockPreferenceConfig], LocationHelperMixin
Flags use of lambda/Proc.new where idiomatic blocks would suffice.
Ruby blocks (do...end / {...}) are the idiomatic way to pass closures for iteration and callbacks. Reaching for lambda or Proc.new when a simple block works adds unnecessary ceremony and confuses readers who expect the conventional block form in everyday enumerable pipelines.
Note
lambda is appropriate for stored callables; this detector targets cases where a block would be more natural.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'ruby_block_preference' for registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Detector identifier for the block-preference rule. TYPE: |
Methods:¶
detect ¶
Flag files that use lambda or Proc.new instead of blocks.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with Ruby source text. TYPE: |
config | Block-preference threshold configuration. |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/ruby/detectors.py
RubyMonkeyPatchDetector ¶
Bases: ViolationDetector[RubyMonkeyPatchConfig], LocationHelperMixin
Detects reopening of core Ruby classes (monkey patching).
Monkey patching String, Array, Hash, or numeric classes silently mutates shared global state, creating action-at-a-distance bugs that are notoriously difficult to diagnose. In Ruby's open-class system any gem or initializer can redefine core behaviour, leading to conflicts between libraries and unpredictable runtime failures.
Note
Refinements (Module#refine) are the safe alternative for scoped extensions to core classes.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'ruby_monkey_patch' for registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Detector identifier for the monkey-patching rule. TYPE: |
Methods:¶
detect ¶
Flag class reopenings of built-in Ruby types like String or Array.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with Ruby source text. TYPE: |
config | Monkey-patch detection configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/ruby/detectors.py
RubyMethodNamingDetector ¶
Bases: ViolationDetector[RubyMethodNamingConfig], LocationHelperMixin
Flags boolean-style methods that lack the conventional trailing ?.
Ruby convention dictates that predicate methods end with ? (e.g., empty?, valid?). A method named is_active or has_items without the ? suffix breaks the expectation of every Ruby developer, making boolean intent invisible at call sites and undermining Ruby's expressive readability.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'ruby_method_naming' for registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Detector identifier for the boolean-method naming rule. TYPE: |
Methods:¶
detect ¶
Flag methods starting with is/has that are missing a ? suffix.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with Ruby source text. TYPE: |
config | Method-naming threshold configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/ruby/detectors.py
RubySymbolKeysDetector ¶
Bases: ViolationDetector[RubySymbolKeysConfig], LocationHelperMixin
Flags hash literals using string keys instead of idiomatic symbol keys.
Symbols are immutable, interned identifiers that are cheaper to compare and allocate than strings. Using 'key' => value instead of key: value wastes memory in long-lived hashes and signals unfamiliarity with Ruby's modern hash syntax introduced in Ruby 1.9.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'ruby_symbol_keys' for registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Detector identifier for the symbol-keys rule. TYPE: |
Methods:¶
detect ¶
Flag hash literals that use quoted string keys with => syntax.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with Ruby source text. TYPE: |
config | Symbol-keys detection configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/ruby/detectors.py
RubyGuardClauseDetector ¶
Bases: ViolationDetector[RubyGuardClauseConfig], LocationHelperMixin
Detects methods that could benefit from guard clauses to reduce nesting.
Deeply nested if blocks obscure the happy path. Ruby's return if / return unless guard clauses let methods exit early, keeping the main logic at the top indentation level and making methods dramatically easier to read and maintain.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'ruby_guard_clause' for registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Detector identifier for the guard-clause rule. TYPE: |
Methods:¶
detect ¶
Flag code with if blocks that lack return if/unless guard clauses.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with Ruby source text. TYPE: |
config | Guard-clause detection configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/ruby/detectors.py
RubyMetaprogrammingDetector ¶
Bases: ViolationDetector[RubyMetaprogrammingConfig], LocationHelperMixin
Flags dangerous metaprogramming constructs like method_missing and eval.
Ruby's metaprogramming power—define_method, method_missing, class_eval, instance_eval, and dynamic send—can make code impossible to trace statically, defeats IDE navigation, and hides method signatures from documentation tools. Unrestricted use turns a codebase into a maze where any object may respond to any message at runtime, making debugging and security auditing extremely difficult.
Note
Metaprogramming is acceptable in DSL frameworks; this detector highlights it so teams can make conscious, documented decisions.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'ruby_metaprogramming' for registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Detector identifier for the metaprogramming-restraint rule. TYPE: |
Methods:¶
detect ¶
Flag code containing dynamic dispatch or runtime method generation.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with Ruby source text. TYPE: |
config | Metaprogramming detection configuration. |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/ruby/detectors.py
RubyExpressiveSyntaxDetector ¶
Bases: ViolationDetector[RubyExpressiveSyntaxConfig], LocationHelperMixin
Flags non-idiomatic control flow like C-style for loops and unless !.
Ruby provides each, map, select, and other Enumerable methods that are more expressive and less error-prone than for...in loops. Similarly, unless !condition is a double-negative that should be written as if condition. Using these non-idiomatic constructs signals unfamiliarity with Ruby's expressive design philosophy.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'ruby_expressive_syntax' for registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Detector identifier for the expressive-syntax rule. TYPE: |
Methods:¶
detect ¶
Flag for...in loops and unless ! double-negatives.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with Ruby source text. TYPE: |
config | Expressive-syntax detection configuration. |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/ruby/detectors.py
RubyPreferFailDetector ¶
Bases: ViolationDetector[RubyPreferFailConfig], LocationHelperMixin
Flags use of raise where fail is the preferred convention for programmer errors.
The Ruby community convention (popularized by RuboCop) reserves fail for signalling programmer errors in methods and raise for re-raising exceptions in rescue blocks. Consistent use of fail for initial error signalling makes it immediately obvious whether an exception is being raised for the first time or re-raised after partial handling.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'ruby_prefer_fail' for registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Detector identifier for the prefer-fail rule. TYPE: |
Methods:¶
detect ¶
Flag files that use raise without any corresponding fail calls.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with Ruby source text. TYPE: |
config | Prefer-fail detection configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/ruby/detectors.py
Rust¶
mcp_zen_of_languages.languages.rust.detectors ¶
Rule detectors for rust code quality and architecture checks.
Classes¶
RustUnwrapUsageDetector ¶
Bases: ViolationDetector[RustUnwrapUsageConfig]
Flags excessive unwrap() and expect() calls that bypass Rust's error model.
Rust's Result and Option types encode fallibility in the type system, but unwrap() and expect() short-circuit that safety by panicking on Err or None. In library code, panics are unrecoverable by callers. This detector uses a regex to count .unwrap( and .expect( occurrences and flags files that exceed the configured maximum.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/rust/detectors.py
RustUnsafeBlocksDetector ¶
Bases: ViolationDetector[RustUnsafeBlocksConfig]
Ensures every unsafe block is preceded by a // SAFETY: comment.
Rust allows opting out of borrow-checker guarantees with unsafe, but the Rust community convention requires a // SAFETY: comment explaining why the invariants hold. This detector scans each line containing the unsafe keyword and checks the preceding two lines for the required safety justification, skipping commented-out code.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/rust/detectors.py
RustCloneOverheadDetector ¶
Bases: ViolationDetector[RustCloneOverheadConfig]
Detects excessive .clone() calls that undermine Rust's zero-cost abstraction goal.
Cloning performs a deep copy, which can be expensive for heap-allocated types like String or Vec. Idiomatic Rust prefers borrowing or Cow<T> to avoid unnecessary allocations. This detector counts .clone() invocations via regex and flags files that exceed the configured ceiling.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/rust/detectors.py
RustErrorHandlingDetector ¶
Bases: ViolationDetector[RustErrorHandlingConfig]
Flags functions that use Result without propagating errors and detects panic! abuse.
Rust's error model relies on Result<T, E> with the ? operator for ergonomic propagation. Functions that declare Result returns but never use ? likely swallow errors silently. Additionally, panic! in library code is an anti-pattern because callers cannot recover. This detector checks both conditions via regex scans.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/rust/detectors.py
RustTypeSafetyDetector ¶
Bases: ViolationDetector[RustTypeSafetyConfig]
Flags structs that use raw primitive types instead of domain-specific newtypes.
Rust's type system is strong enough to prevent entire categories of bugs via newtypes (e.g., struct UserId(u64) instead of bare u64). Raw primitives in struct fields lose semantic meaning and allow accidental mixing of unrelated values. This detector scans struct bodies for configured primitive types and suggests wrapping them in dedicated newtypes or enums.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/rust/detectors.py
RustIteratorPreferenceDetector ¶
Bases: ViolationDetector[RustIteratorPreferenceConfig]
Flags excessive manual loops where iterator adapters would be more idiomatic.
Rust's iterator combinators (map, filter, fold, etc.) are zero-cost abstractions that the compiler can optimize as well as hand-written loops, while being more expressive and less error-prone. This detector counts for and while loops and flags files that exceed the configured maximum, encouraging iterator-based transformations instead.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/rust/detectors.py
RustMustUseDetector ¶
Bases: ViolationDetector[RustMustUseConfig]
Detects Result-returning code that omits the #[must_use] attribute.
When a function returns Result but the caller ignores the return value, errors are silently discarded. The #[must_use] attribute causes a compiler warning when a return value is unused, making neglected errors visible at build time. This detector flags files that contain Result< without any #[must_use] annotation.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/rust/detectors.py
RustDebugDeriveDetector ¶
Bases: ViolationDetector[RustDebugDeriveConfig]
Ensures public structs derive Debug for ergonomic logging and diagnostics.
In Rust, #[derive(Debug)] enables {:?} formatting, which is essential for logging, test assertions, and interactive debugging. Public structs without Debug force consumers to work blindly with opaque values. This detector checks whether files containing pub struct also include #[derive(Debug)] somewhere.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/rust/detectors.py
RustNewtypePatternDetector ¶
Bases: ViolationDetector[RustNewtypePatternConfig]
Flags type aliases to primitives that should be tuple-struct newtypes.
A type Alias = u64 creates a transparent synonym with no type safety: a UserId and a PostId are freely interchangeable. A tuple-struct newtype (struct UserId(u64)) is a distinct type the compiler enforces at every call site. This detector scans for type X = <primitive> patterns and suggests newtypes instead.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/rust/detectors.py
RustStdTraitsDetector ¶
Bases: ViolationDetector[RustStdTraitsConfig]
Detects structs that lack standard trait implementations like From or Display.
Implementing standard library traits (From, Into, Default, Display) lets a struct participate in Rust's ecosystem idioms — conversions, default construction, and user-facing formatting — without custom methods. This detector flags files containing struct definitions that have no impl blocks for any of these key traits.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/rust/detectors.py
RustEnumOverBoolDetector ¶
Bases: ViolationDetector[RustEnumOverBoolConfig]
Flags structs with too many boolean fields that should be expressed as enums.
Multiple bool fields in a struct create combinatorial state explosions and make call sites confusing (new(true, false, true)). An enum with named variants (enum Mode { Read, Write }) is self-documenting and the compiler can verify exhaustive matching. This detector counts : bool annotations and flags files that exceed the configured maximum.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/rust/detectors.py
RustLifetimeUsageDetector ¶
Bases: ViolationDetector[RustLifetimeUsageConfig]
Flags excessive explicit lifetime annotations where elision would suffice.
Rust's lifetime elision rules handle the majority of borrow cases automatically. Overusing explicit lifetimes ('a, 'static) adds visual noise and cognitive overhead without improving safety. This detector counts explicit lifetime parameters and 'static annotations via regex and flags files that exceed the configured threshold.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/rust/detectors.py
RustInteriorMutabilityDetector ¶
Bases: ViolationDetector[RustInteriorMutabilityConfig]
Detects Rc<RefCell<T>> and Arc<Mutex<T>> patterns that signal design issues.
Interior mutability types let you mutate data behind shared references, but Rc<RefCell<T>> panics on borrow violations at runtime and Arc<Mutex<T>> risks deadlocks. Frequent use of these wrappers often indicates that ownership boundaries need rethinking. This detector scans for both patterns via regex and flags their presence.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/rust/detectors.py
RustSendSyncDetector ¶
Bases: ViolationDetector[RustSendSyncConfig]
Flags unsafe Send/Sync implementations without SAFETY comments.
unsafe impl Send or unsafe impl Sync should always be accompanied by a // SAFETY: comment explaining the soundness justification.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return detector identifier.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string. TYPE: |
Methods:¶
detect ¶
Detect unsafe Send/Sync without safety comments.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with source code. TYPE: |
config | Detector configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Detected violations. |
Source code in src/mcp_zen_of_languages/languages/rust/detectors.py
RustErrorTraitsDetector ¶
Bases: ViolationDetector[RustErrorTraitsConfig]
Flags error types that do not implement std::error::Error.
Custom error structs/enums should implement std::error::Error and Display so they integrate with the standard error ecosystem.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return detector identifier.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string. TYPE: |
Methods:¶
detect ¶
Detect error types missing std::error::Error impls.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with source code. TYPE: |
config | Detector configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Detected violations. |
Source code in src/mcp_zen_of_languages/languages/rust/detectors.py
RustNamingDetector ¶
Bases: ViolationDetector[RustNamingConfig]
Flags functions using camelCase instead of snake_case.
RFC 430 mandates snake_case for function names in Rust.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return detector identifier.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string. TYPE: |
Methods:¶
detect ¶
Detect camelCase function names violating RFC 430.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with source code. TYPE: |
config | Detector configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Detected violations. |
Source code in src/mcp_zen_of_languages/languages/rust/detectors.py
RustDefaultImplDetector ¶
Bases: ViolationDetector[RustDefaultImplConfig]
Flags public structs that lack a Default implementation.
Public structs with an obvious default state should implement Default so callers can construct them ergonomically.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return detector identifier.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string. TYPE: |
Methods:¶
detect ¶
Detect public structs without Default derivation.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with source code. TYPE: |
config | Detector configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Detected violations. |
Source code in src/mcp_zen_of_languages/languages/rust/detectors.py
RustFromIntoDetector ¶
Bases: ViolationDetector[RustFromIntoConfig]
Flags ad-hoc conversion functions that should use From/Into traits.
Idiomatic Rust uses From/Into traits for type conversions rather than standalone from_*/to_*/into_* functions.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return detector identifier.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string. TYPE: |
Methods:¶
detect ¶
Detect ad-hoc conversion functions missing From/Into impls.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context with source code. TYPE: |
config | Detector configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Detected violations. |
Source code in src/mcp_zen_of_languages/languages/rust/detectors.py
TOML¶
mcp_zen_of_languages.languages.toml.detectors ¶
Detectors for TOML file quality, enforcing table structure, key conventions, and value formatting.
Classes¶
TomlNoInlineTablesDetector ¶
Bases: ViolationDetector[TomlNoInlineTablesConfig], LocationHelperMixin
Flags inline table syntax (key = { ... }) that should use full table sections.
Inline tables are compact but become hard to read and diff when they grow beyond a few key-value pairs. The TOML specification intentionally limits inline tables to a single line, so complex structures are better expressed as standard [table] sections for clarity and version-control friendliness.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'toml-001' identifying the inline tables detector.
| RETURNS | DESCRIPTION |
|---|---|
str | The TYPE: |
Methods:¶
detect ¶
Scan for = { patterns indicating inline table assignments.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context holding the raw TOML text. TYPE: |
config | Inline table thresholds and violation message templates. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: One violation per line containing an inline table. |
Source code in src/mcp_zen_of_languages/languages/toml/detectors.py
TomlDuplicateKeysDetector ¶
Bases: ViolationDetector[TomlDuplicateKeysConfig], LocationHelperMixin
Catches repeated bare keys within the same scope of a TOML file.
TOML forbids duplicate keys at the same level; most parsers will either error or silently use the last value. This detector performs a linear scan of top-level assignments (outside [table] headers) to surface duplicates before they cause parser failures or data loss.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'toml-002' identifying the duplicate keys detector.
| RETURNS | DESCRIPTION |
|---|---|
str | The TYPE: |
Methods:¶
detect ¶
Track seen keys and flag any that appear more than once at the same level.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context holding the raw TOML text. TYPE: |
config | Duplicate key thresholds and violation message templates. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: One violation per duplicate key occurrence. |
Source code in src/mcp_zen_of_languages/languages/toml/detectors.py
TomlLowercaseKeysDetector ¶
Bases: ViolationDetector[TomlLowercaseKeysConfig], LocationHelperMixin
Enforces lowercase key names throughout the TOML document.
TOML keys are case-sensitive, so Name and name are distinct keys. Mixing cases within a project invites hard-to-spot bugs where a consumer references the wrong variant. Standardising on lowercase (with hyphens or underscores for word separation) improves predictability and grep-ability.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'toml-003' identifying the lowercase keys detector.
| RETURNS | DESCRIPTION |
|---|---|
str | The TYPE: |
Methods:¶
detect ¶
Scan key assignments and flag any containing uppercase characters.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context holding the raw TOML text. TYPE: |
config | Lowercase key thresholds and violation message templates. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: One violation per key that contains uppercase letters. |
Source code in src/mcp_zen_of_languages/languages/toml/detectors.py
TomlTrailingCommasDetector ¶
Bases: ViolationDetector[TomlTrailingCommasConfig], LocationHelperMixin
Detects trailing commas inside TOML arrays and inline tables.
Unlike JSON5 or JavaScript, TOML does not permit trailing commas in arrays or inline tables. Their presence causes parser errors, and some editors may silently insert them during copy-paste. This detector catches the pattern early to prevent downstream parsing failures.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'toml-004' identifying the trailing commas detector.
| RETURNS | DESCRIPTION |
|---|---|
str | The TYPE: |
Methods:¶
detect ¶
Search for comma-then-closing-bracket patterns on each line.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context holding the raw TOML text. TYPE: |
config | Trailing comma thresholds and violation message templates. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: One violation per line containing a trailing comma. |
Source code in src/mcp_zen_of_languages/languages/toml/detectors.py
TomlCommentClarityDetector ¶
Bases: ViolationDetector[TomlCommentClarityConfig], LocationHelperMixin
Ensures TOML files with non-trivial configuration include explanatory comments.
Configuration files often contain "magic" values whose purpose is unclear without context. A TOML file that assigns values but lacks any # comments forces readers to guess intent. This detector compares the number of comment lines against a configurable minimum and flags under-documented files.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'toml-005' identifying the comment clarity detector.
| RETURNS | DESCRIPTION |
|---|---|
str | The TYPE: |
Methods:¶
detect ¶
Count comment lines and flag the file when fewer than min_comment_lines exist.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context holding the raw TOML text. TYPE: |
config | Comment clarity thresholds including TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: A single violation when comment coverage is below the threshold. |
Source code in src/mcp_zen_of_languages/languages/toml/detectors.py
TomlOrderDetector ¶
Bases: ViolationDetector[TomlOrderConfig], LocationHelperMixin
Detects poorly grouped table sections that are separated by excessive whitespace.
Logically related TOML tables should appear near each other so readers can scan the file top-to-bottom without jumping. When two consecutive [table] headers are separated by more than ten lines, this detector flags the gap to encourage tighter grouping and optional blank-line separators.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'toml-006' identifying the table order detector.
| RETURNS | DESCRIPTION |
|---|---|
str | The TYPE: |
Methods:¶
detect ¶
Measure line gaps between consecutive [table] headers and flag large separations.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context holding the raw TOML text. TYPE: |
config | Table order thresholds and violation message templates. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: A single violation when any inter-table gap exceeds ten lines. |
Source code in src/mcp_zen_of_languages/languages/toml/detectors.py
TomlIsoDatetimeDetector ¶
Bases: ViolationDetector[TomlIsoDatetimeConfig], LocationHelperMixin
Enforces ISO 8601 datetime formatting in quoted TOML string values.
TOML supports native datetime literals, but quoted strings with locale-specific formats like MM/DD/YYYY are still common in hand-edited files. This detector identifies such patterns and recommends ISO 8601 (YYYY-MM-DD or YYYY-MM-DDTHH:MM:SSZ) for consistency and unambiguous parsing.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'toml-007' identifying the ISO datetime detector.
| RETURNS | DESCRIPTION |
|---|---|
str | The TYPE: |
Methods:¶
detect ¶
Search quoted string values for non-ISO date patterns like MM/DD/YYYY.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context holding the raw TOML text. TYPE: |
config | ISO datetime thresholds and violation message templates. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations for the first non-ISO date string found. |
Source code in src/mcp_zen_of_languages/languages/toml/detectors.py
TomlFloatIntegerDetector ¶
Bases: ViolationDetector[TomlFloatIntegerConfig], LocationHelperMixin
Flags float literals ending in .0 that should be plain integers.
Writing count = 5.0 when the value is conceptually an integer introduces unnecessary type ambiguity. Downstream consumers may treat it as a float, leading to unexpected behaviour in integer-only contexts. This detector identifies N.0 patterns and suggests using the integer form instead.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'toml-008' identifying the float/integer precision detector.
| RETURNS | DESCRIPTION |
|---|---|
str | The TYPE: |
Methods:¶
detect ¶
Scan assignments for numeric values matching the N.0 pattern.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context holding the raw TOML text. TYPE: |
config | Float/integer thresholds and violation message templates. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: A single violation for the first |
Source code in src/mcp_zen_of_languages/languages/toml/detectors.py
TypeScript¶
mcp_zen_of_languages.languages.typescript.detectors ¶
Rule detectors for typescript code quality and architecture checks.
Classes¶
TsAnyUsageDetector ¶
Bases: ViolationDetector[TsAnyUsageConfig], LocationHelperMixin
Detects excessive use of the any type that undermines TypeScript's value.
The any type disables all type checking for a value, silently propagating unsafety through every expression it touches. This detector counts any annotations via detect_ts_any_usage and flags files that exceed the configured threshold, encouraging the use of unknown, generics, or concrete types instead.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/typescript/detectors.py
TsStrictModeDetector ¶
Bases: ViolationDetector[TsStrictModeConfig]
Checks whether strict compiler options are enabled in the project.
TypeScript's strict flag activates strictNullChecks, noImplicitAny, and other safety options that catch common bugs at compile time. Without strict mode, TypeScript behaves almost like plain JavaScript, making the type system advisory rather than enforced. This detector raises a violation when strict mode is required by configuration but not detected in the source.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
_context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/typescript/detectors.py
TsInterfacePreferenceDetector ¶
Bases: ViolationDetector[TsInterfacePreferenceConfig], LocationHelperMixin
Flags object-shaped type aliases that should be interfaces instead.
In TypeScript, interface declarations are open for extension via declaration merging and produce clearer error messages than type aliases for object shapes. This detector uses detect_ts_object_type_aliases to count type Foo = { ... } patterns and flags files that exceed the configured limit, encouraging the use of interface for plain object contracts.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/typescript/detectors.py
TsReturnTypeDetector ¶
Bases: ViolationDetector[TsReturnTypeConfig], LocationHelperMixin
Flags exported functions that lack explicit return type annotations.
When functions omit return types, TypeScript infers them, which can silently widen the contract and break callers after refactoring. Explicit return types serve as documentation and a stability guarantee at API boundaries. This detector uses detect_ts_missing_return_types to scan for exported functions without a declared return type.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/typescript/detectors.py
TsReadonlyDetector ¶
Bases: ViolationDetector[TsReadonlyConfig], LocationHelperMixin
Detects insufficient use of readonly for immutable properties and arrays.
Marking properties and array types as readonly prevents accidental mutation, a common source of bugs in shared state. This detector counts readonly annotations via detect_ts_readonly_usage and flags files where the count falls below the configured minimum, nudging authors toward immutability by default.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/typescript/detectors.py
TsTypeGuardDetector ¶
Bases: ViolationDetector[TsTypeGuardConfig], LocationHelperMixin
Flags overuse of type assertions (as T) instead of user-defined type guards.
Type assertions bypass the compiler's narrowing logic and can mask runtime type mismatches. User-defined type guards (x is Foo) let TypeScript narrow types safely within conditional branches. This detector uses detect_ts_type_assertions to count as casts and flags files that exceed the configured ceiling.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/typescript/detectors.py
TsUtilityTypesDetector ¶
Bases: ViolationDetector[TsUtilityTypesConfig], LocationHelperMixin
Detects missed opportunities to use built-in utility types like Partial or Pick.
TypeScript ships with utility types (Partial<T>, Readonly<T>, Pick<T, K>, etc.) that express common type transformations concisely. When a codebase defines many object type aliases but rarely uses utility types, authors are likely duplicating structure that could be derived. This detector cross-checks utility-type usage against object-alias counts and flags the gap.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/typescript/detectors.py
TsNonNullAssertionDetector ¶
Bases: ViolationDetector[TsNonNullAssertionConfig], LocationHelperMixin
Flags excessive non-null assertion operators (!) that silence null safety.
The postfix ! operator tells TypeScript to trust that a value is neither null nor undefined, but it offers no runtime protection. Chained assertions like obj!.prop! are especially dangerous. This detector combines results from detect_ts_non_null_assertions with a regex scan for chained patterns and flags files that exceed the configured limit.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/typescript/detectors.py
TsEnumConstDetector ¶
Bases: ViolationDetector[TsEnumConstConfig], LocationHelperMixin
Detects plain object literals used as constants instead of enums or as const.
Plain objects masquerading as enumerations lose TypeScript's exhaustiveness checking and allow arbitrary string or number values to slip through. Using enum or as const assertions gives the compiler a closed set of values it can verify at every usage site. This detector uses detect_ts_plain_enum_objects to count constant-like object patterns and flags files above the threshold.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/typescript/detectors.py
TsUnknownOverAnyDetector ¶
Bases: ViolationDetector[TsUnknownOverAnyConfig], LocationHelperMixin
Flags codebases that use any without ever using the safer unknown alternative.
unknown is the type-safe counterpart of any: it accepts every value but requires narrowing before use, catching mistakes that any would silently allow. This detector checks whether any annotations appear above the configured ceiling while unknown is entirely absent, indicating that authors may not be aware of the safer option.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier used by registry wiring.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string consumed by callers. TYPE: |
Methods:¶
detect ¶
Detect violations for the current analysis context.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context containing source text and intermediate metrics. TYPE: |
config | Typed detector or analyzer configuration that controls thresholds. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations detected for the analyzed context. |
Source code in src/mcp_zen_of_languages/languages/typescript/detectors.py
TsOptionalChainingDetector ¶
Bases: ViolationDetector[TsOptionalChainingConfig], LocationHelperMixin
Detects manual null-check chains replaceable by optional chaining (?.).
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string. TYPE: |
Methods:¶
detect ¶
Detect manual null-check chain violations.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context. TYPE: |
config | Detector configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations found. |
Source code in src/mcp_zen_of_languages/languages/typescript/detectors.py
TsIndexLoopDetector ¶
Bases: ViolationDetector[TsIndexLoopConfig], LocationHelperMixin
Detects C-style index-based for loops replaceable by for-of or array methods.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string. TYPE: |
Methods:¶
detect ¶
Detect index-loop violations.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context. TYPE: |
config | Detector configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations found. |
Source code in src/mcp_zen_of_languages/languages/typescript/detectors.py
TsPromiseChainDetector ¶
Bases: ViolationDetector[TsPromiseChainConfig], LocationHelperMixin
Detects raw .then() promise chains replaceable by async/await.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string. TYPE: |
Methods:¶
detect ¶
Detect promise chain violations.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context. TYPE: |
config | Detector configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations found. |
Source code in src/mcp_zen_of_languages/languages/typescript/detectors.py
TsDefaultExportDetector ¶
Bases: ViolationDetector[TsDefaultExportConfig], LocationHelperMixin
Detects export default statements encouraging named exports instead.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string. TYPE: |
Methods:¶
detect ¶
Detect default export violations.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context. TYPE: |
config | Detector configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations found. |
Source code in src/mcp_zen_of_languages/languages/typescript/detectors.py
TsCatchAllTypeDetector ¶
Bases: ViolationDetector[TsCatchAllTypeConfig], LocationHelperMixin
Detects catch-all type annotations (Object, object, {}).
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string. TYPE: |
Methods:¶
detect ¶
Detect catch-all type violations.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context. TYPE: |
config | Detector configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations found. |
Source code in src/mcp_zen_of_languages/languages/typescript/detectors.py
TsConsoleUsageDetector ¶
Bases: ViolationDetector[TsConsoleUsageConfig], LocationHelperMixin
Detects console.* calls in TypeScript production code.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string. TYPE: |
Methods:¶
detect ¶
Detect console usage violations.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context. TYPE: |
config | Detector configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations found. |
Source code in src/mcp_zen_of_languages/languages/typescript/detectors.py
TsRequireImportDetector ¶
Bases: ViolationDetector[TsRequireImportConfig], LocationHelperMixin
Detects require() calls encouraging ES module imports instead.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string. TYPE: |
Methods:¶
detect ¶
Detect require import violations.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context. TYPE: |
config | Detector configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations found. |
Source code in src/mcp_zen_of_languages/languages/typescript/detectors.py
TsStringConcatDetector ¶
Bases: ViolationDetector[TsStringConcatConfig], LocationHelperMixin
Detects string concatenation patterns encouraging template literals.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string. TYPE: |
Methods:¶
detect ¶
Detect string concatenation violations.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context. TYPE: |
config | Detector configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations found. |
Source code in src/mcp_zen_of_languages/languages/typescript/detectors.py
TsAsyncAwaitDetector ¶
Bases: ViolationDetector[TsAsyncAwaitConfig], LocationHelperMixin
Detects raw .then() promise chains encouraging async/await usage.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string. TYPE: |
Methods:¶
detect ¶
Detect raw promise-chain violations.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context. TYPE: |
config | Detector configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations found. |
Source code in src/mcp_zen_of_languages/languages/typescript/detectors.py
TsForOfDetector ¶
Bases: ViolationDetector[TsForOfConfig], LocationHelperMixin
Detects C-style index-based for loops encouraging for...of iteration.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string. TYPE: |
Methods:¶
detect ¶
Detect index-based loop violations.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context. TYPE: |
config | Detector configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations found. |
Source code in src/mcp_zen_of_languages/languages/typescript/detectors.py
TsImportOrderDetector ¶
Bases: ViolationDetector[TsImportOrderConfig], LocationHelperMixin
Detects CommonJS require() calls mixed with ES module imports.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string. TYPE: |
Methods:¶
detect ¶
Detect mixed import style violations.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context. TYPE: |
config | Detector configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations found. |
Source code in src/mcp_zen_of_languages/languages/typescript/detectors.py
TsNamedExportDetector ¶
Bases: ViolationDetector[TsNamedExportConfig], LocationHelperMixin
Detects export default usages encouraging named exports.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string. TYPE: |
Methods:¶
detect ¶
Detect default-export violations.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context. TYPE: |
config | Detector configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations found. |
Source code in src/mcp_zen_of_languages/languages/typescript/detectors.py
TsNoConsoleDetector ¶
Bases: ViolationDetector[TsNoConsoleConfig], LocationHelperMixin
Detects console.* calls in production code.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string. TYPE: |
Methods:¶
detect ¶
Detect console statement violations.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context. TYPE: |
config | Detector configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations found. |
Source code in src/mcp_zen_of_languages/languages/typescript/detectors.py
TsObjectTypeDetector ¶
Bases: ViolationDetector[TsObjectTypeConfig], LocationHelperMixin
Detects generic Object/object/{} type annotations.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string. TYPE: |
Methods:¶
detect ¶
Detect generic object-type violations.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context. TYPE: |
config | Detector configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations found. |
Source code in src/mcp_zen_of_languages/languages/typescript/detectors.py
TsTemplateLiteralDetector ¶
Bases: ViolationDetector[TsTemplateLiteralConfig], LocationHelperMixin
Detects string concatenation patterns encouraging template literals.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return the detector identifier.
| RETURNS | DESCRIPTION |
|---|---|
str | Identifier string. TYPE: |
Methods:¶
detect ¶
Detect string concatenation violations.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context. TYPE: |
config | Detector configuration. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: Violations found. |
Source code in src/mcp_zen_of_languages/languages/typescript/detectors.py
Functions:¶
XML¶
mcp_zen_of_languages.languages.xml.detectors ¶
Detectors for XML document quality, enforcing semantic markup, namespace hygiene, and hierarchy.
Classes¶
XmlSemanticMarkupDetector ¶
Bases: ViolationDetector[XmlSemanticMarkupConfig], LocationHelperMixin
Flags presentational HTML-era tags and inline style attributes in XML.
Tags like <font>, <center>, <b>, and <i> embed presentation concerns into a document that should express structure. Similarly, style="..." attributes couple layout decisions to content. This detector encourages separating presentation from semantics by using CSS or XSL stylesheets instead.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'xml-001' identifying the semantic markup detector.
| RETURNS | DESCRIPTION |
|---|---|
str | The TYPE: |
Methods:¶
detect ¶
Search for presentational tags (<font>, <b>, etc.) and inline style attributes.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context holding the raw XML markup. TYPE: |
config | Semantic markup thresholds and violation message templates. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: A single violation when presentational elements are found. |
Source code in src/mcp_zen_of_languages/languages/xml/detectors.py
XmlAttributeUsageDetector ¶
Bases: ViolationDetector[XmlAttributeUsageConfig], LocationHelperMixin
Identifies oversized attribute values that belong in child elements instead.
XML attributes are designed for short metadata—identifiers, flags, or references. When an attribute value exceeds 30 characters it typically contains data that is better expressed as element content, where it can be formatted, validated, and read more easily.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'xml-002' identifying the attribute usage detector.
| RETURNS | DESCRIPTION |
|---|---|
str | The TYPE: |
Methods:¶
detect ¶
Scan for attribute values longer than 30 characters that should be child elements.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context holding the raw XML markup. TYPE: |
config | Attribute usage thresholds and violation message templates. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: A single violation for the first oversized attribute found. |
Source code in src/mcp_zen_of_languages/languages/xml/detectors.py
XmlNamespaceDetector ¶
Bases: ViolationDetector[XmlNamespaceConfig], LocationHelperMixin
Detects prefixed element names that lack a corresponding xmlns declaration.
Namespace prefixes like <ns:element> are meaningless without a xmlns:ns="..." binding. Missing declarations cause parser errors and make the document non-well-formed. This detector catches the oversight early so authors can add the proper namespace URI.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'xml-003' identifying the namespace declaration detector.
| RETURNS | DESCRIPTION |
|---|---|
str | The TYPE: |
Methods:¶
detect ¶
Check whether prefixed elements (<prefix:tag>) have a matching xmlns binding.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context holding the raw XML markup. TYPE: |
config | Namespace thresholds and violation message templates. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: A single violation when prefixed tags exist without |
Source code in src/mcp_zen_of_languages/languages/xml/detectors.py
XmlValidityDetector ¶
Bases: ViolationDetector[XmlValidityConfig], LocationHelperMixin
Checks for schema or DTD references that enable structural validation.
An XML document without xsi:schemaLocation or DOCTYPE cannot be validated against a formal grammar, making it fragile and error-prone. This detector flags documents that lack any schema reference so authors can add one to enable automated validation tooling.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'xml-004' identifying the schema validity detector.
| RETURNS | DESCRIPTION |
|---|---|
str | The TYPE: |
Methods:¶
detect ¶
Search for xsi:schemaLocation or DOCTYPE references in the document.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context holding the raw XML markup. TYPE: |
config | Validity thresholds and violation message templates. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: A single violation when no schema reference is present. |
Source code in src/mcp_zen_of_languages/languages/xml/detectors.py
XmlHierarchyDetector ¶
Bases: ViolationDetector[XmlHierarchyConfig], LocationHelperMixin
Flags repeated sibling elements that lack a grouping parent container.
When the same tag name appears more than twice without being wrapped in a logical parent (e.g., <group>), readers struggle to understand the document's hierarchy. This detector recommends introducing a container element to clarify the relationship between repeated siblings.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'xml-005' identifying the element hierarchy detector.
| RETURNS | DESCRIPTION |
|---|---|
str | The TYPE: |
Methods:¶
detect ¶
Count opening tags and flag any that repeat more than twice without a <group> wrapper.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context holding the raw XML markup. TYPE: |
config | Hierarchy thresholds and violation message templates. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: A single violation when ungrouped repeated elements are found. |
Source code in src/mcp_zen_of_languages/languages/xml/detectors.py
XmlClosingTagsDetector ¶
Bases: ViolationDetector[XmlClosingTagsConfig], LocationHelperMixin
Identifies self-closing tags (<tag />) where explicit closing tags are preferred.
Self-closing syntax is valid XML, but in contexts where an element is expected to hold content (e.g., <description />) it can mask missing data. This detector flags self-closing elements so authors can verify that the empty content is intentional.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'xml-006' identifying the closing tags detector.
| RETURNS | DESCRIPTION |
|---|---|
str | The TYPE: |
Methods:¶
detect ¶
Search for self-closing tag syntax (<tag />) in the XML document.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context holding the raw XML markup. TYPE: |
config | Closing tag thresholds and violation message templates. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: A single violation when self-closing tags are found. |
Source code in src/mcp_zen_of_languages/languages/xml/detectors.py
YAML¶
mcp_zen_of_languages.languages.yaml.detectors ¶
Detectors for YAML file quality, enforcing indentation, key conventions, and structural consistency.
Classes¶
YamlIndentationDetector ¶
Bases: ViolationDetector[YamlIndentationConfig], LocationHelperMixin
Enforces uniform indentation width across all non-blank, non-comment lines.
YAML's block structure relies entirely on whitespace indentation, so inconsistent widths can silently change document semantics. This detector verifies that every indented line uses a multiple of the configured indent size (defaulting to two spaces) and flags deviations before they cause parsing surprises.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'yaml-001' identifying the indentation detector.
| RETURNS | DESCRIPTION |
|---|---|
str | The TYPE: |
Methods:¶
detect ¶
Check each non-blank line's leading spaces against the configured indent width.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context holding the raw YAML text. TYPE: |
config | Indentation thresholds including TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: One violation per line whose leading whitespace is not a multiple of indent_size. |
Source code in src/mcp_zen_of_languages/languages/yaml/detectors.py
YamlNoTabsDetector ¶
Bases: ViolationDetector[YamlNoTabsConfig], LocationHelperMixin
Detects tab characters anywhere in YAML content.
The YAML specification explicitly prohibits tab characters for indentation; only spaces are allowed. Tabs embedded in values are technically legal but often indicate copy-paste errors. This detector flags every line containing a tab to prevent subtle parsing failures.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'yaml-002' identifying the no-tabs detector.
| RETURNS | DESCRIPTION |
|---|---|
str | The TYPE: |
Methods:¶
detect ¶
Scan every line for tab characters and report their positions.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context holding the raw YAML text. TYPE: |
config | No-tabs thresholds and violation message templates. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: One violation per line containing a tab character. |
Source code in src/mcp_zen_of_languages/languages/yaml/detectors.py
YamlDuplicateKeysDetector ¶
Bases: ViolationDetector[YamlDuplicateKeysConfig], LocationHelperMixin
Catches repeated top-level mapping keys that cause silent data loss.
YAML 1.1 allows duplicate keys with "last wins" semantics, while YAML 1.2 discourages them. Either way, duplicates usually indicate a merge conflict remnant or copy-paste mistake. This detector tracks seen top-level keys and flags any that appear more than once.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'yaml-003' identifying the duplicate keys detector.
| RETURNS | DESCRIPTION |
|---|---|
str | The TYPE: |
Methods:¶
detect ¶
Track top-level keys and flag any that appear more than once.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context holding the raw YAML text. TYPE: |
config | Duplicate key thresholds and violation message templates. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: One violation per duplicate key occurrence. |
Source code in src/mcp_zen_of_languages/languages/yaml/detectors.py
YamlLowercaseKeysDetector ¶
Bases: ViolationDetector[YamlLowercaseKeysConfig], LocationHelperMixin
Enforces lowercase mapping keys throughout the YAML document.
YAML keys are case-sensitive, so Name and name are distinct. Mixing cases within a project causes confusion and breaks tools that rely on consistent key naming. This detector flags any key containing uppercase characters to encourage a uniform lowercase convention.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'yaml-004' identifying the lowercase keys detector.
| RETURNS | DESCRIPTION |
|---|---|
str | The TYPE: |
Methods:¶
detect ¶
Scan mapping keys and flag any containing uppercase characters.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context holding the raw YAML text. TYPE: |
config | Lowercase key thresholds and violation message templates. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: One violation per key with uppercase letters. |
Source code in src/mcp_zen_of_languages/languages/yaml/detectors.py
YamlKeyClarityDetector ¶
Bases: ViolationDetector[YamlKeyClarityConfig], LocationHelperMixin
Flags overly short mapping keys that sacrifice readability for brevity.
Single- or two-character keys like x or id are acceptable in some contexts but often indicate a missed opportunity for self-documenting names. This detector compares each key's length against a configurable minimum (default 3) and reports the first offender.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'yaml-005' identifying the key clarity detector.
| RETURNS | DESCRIPTION |
|---|---|
str | The TYPE: |
Methods:¶
detect ¶
Check each key's length and flag the first one shorter than min_key_length.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context holding the raw YAML text. TYPE: |
config | Key clarity thresholds including TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: A single violation for the first overly short key found. |
Source code in src/mcp_zen_of_languages/languages/yaml/detectors.py
YamlConsistencyDetector ¶
Bases: ViolationDetector[YamlConsistencyConfig], LocationHelperMixin
Ensures a single, consistent list-marker style is used throughout the document.
YAML allows - and * as sequence entry indicators, but mixing them in the same file confuses readers and may trip strict linters. This detector collects all markers used and flags the document when more than one style appears or when a disallowed marker is used.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'yaml-006' identifying the list-marker consistency detector.
| RETURNS | DESCRIPTION |
|---|---|
str | The TYPE: |
Methods:¶
detect ¶
Collect list markers (- vs *) and flag mixed or disallowed usage.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context holding the raw YAML text. TYPE: |
config | Consistency thresholds including TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: A single violation when marker styles are inconsistent or disallowed. |
Source code in src/mcp_zen_of_languages/languages/yaml/detectors.py
YamlCommentIntentDetector ¶
Bases: ViolationDetector[YamlCommentIntentConfig], LocationHelperMixin
Ensures complex YAML files include explanatory comments.
Configuration files that exceed a minimum line count without any # comments are difficult for new contributors to understand. This detector counts non-empty content lines and comment lines, flagging documents that fall below the configured comment threshold relative to their size.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'yaml-007' identifying the comment intent detector.
| RETURNS | DESCRIPTION |
|---|---|
str | The TYPE: |
Methods:¶
detect ¶
Count non-empty and comment lines, flagging when comment coverage is too low.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context holding the raw YAML text. TYPE: |
config | Comment intent thresholds including TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: A single violation when the file is large enough but lacks sufficient comments. |
Source code in src/mcp_zen_of_languages/languages/yaml/detectors.py
YamlStringStyleDetector ¶
Bases: ViolationDetector[YamlStringStyleConfig], LocationHelperMixin
Flags unquoted string values that contain spaces or special YAML characters.
Unquoted strings with colons, hashes, or spaces can be misinterpreted by parsers—for example, key: value: extra may be parsed differently than intended. This detector identifies such values and recommends wrapping them in single or double quotes to eliminate ambiguity.
Note
Boolean literals (true, false, null) and plain numbers are excluded from this check.
Source code in src/mcp_zen_of_languages/analyzers/base.py
Attributes¶
name property ¶
Return 'yaml-008' identifying the string style detector.
| RETURNS | DESCRIPTION |
|---|---|
str | The TYPE: |
Methods:¶
detect ¶
Search for unquoted values containing spaces, colons, or hashes that need quoting.
| PARAMETER | DESCRIPTION |
|---|---|
context | Analysis context holding the raw YAML text. TYPE: |
config | String style thresholds including TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[Violation] | list[Violation]: A single violation for the first unquoted special-character value found. |