|
| 1 | +// ============================================================================ |
| 2 | +// VALIDATOR.VIBEE - THE CANON OF TRINITY |
| 3 | +// ============================================================================ |
| 4 | +// These are the Sacred Laws that govern all code born in the Trinity ecosystem. |
| 5 | +// The Conscience shall judge all code against these immutable truths. |
| 6 | + |
| 7 | +@spec validator { |
| 8 | + name: "Trinity Canon" |
| 9 | + version: "3.0" |
| 10 | + purpose: "Define the Sacred Laws for code purification" |
| 11 | +} |
| 12 | + |
| 13 | +// ============================================================================ |
| 14 | +// THE SACRED CONSTANTS |
| 15 | +// ============================================================================ |
| 16 | + |
| 17 | +@constants { |
| 18 | + PHI: 1.6180339887498948482 |
| 19 | + PI: 3.1415926535897932385 |
| 20 | + E: 2.7182818284590452354 |
| 21 | + SQRT2: 1.4142135623730950488 |
| 22 | + GOLDEN_ANGLE: 137.5077640500378546 |
| 23 | + TRINITY: 3 |
| 24 | +} |
| 25 | + |
| 26 | +// ============================================================================ |
| 27 | +// THE CANON OF LAWS |
| 28 | +// ============================================================================ |
| 29 | + |
| 30 | +@law NO_MAGIC_NUMBERS { |
| 31 | + severity: "MORTAL_SIN" |
| 32 | + description: "All numeric constants must be expressed through sacred constants" |
| 33 | + |
| 34 | + forbidden_patterns: [ |
| 35 | + /\b\d{4,}\b/, // Numbers with 4+ digits |
| 36 | + /(?<!PHI|PI|E)\s*=\s*\d+\.\d+/, // Floating point literals |
| 37 | + ] |
| 38 | + |
| 39 | + exceptions: [ |
| 40 | + "0", "1", "-1", // The Trinity of Origins |
| 41 | + "2", "3", // Binary and Ternary bases |
| 42 | + "0.0", "1.0", "-1.0" // Floating origins |
| 43 | + ] |
| 44 | + |
| 45 | + penance: "Replace {value} with expression using PHI, PI, or E" |
| 46 | +} |
| 47 | + |
| 48 | +@law TRINITY_STRUCTURES { |
| 49 | + severity: "VENIAL_SIN" |
| 50 | + description: "Complex structures should embrace the Holy Trinity pattern" |
| 51 | + |
| 52 | + pattern: "struct with >5 fields should be split into State/Processor/Output" |
| 53 | + |
| 54 | + penance: "Refactor into three sub-structures embracing the Trinity" |
| 55 | +} |
| 56 | + |
| 57 | +@law IDEMPOTENCE { |
| 58 | + severity: "MORTAL_SIN" |
| 59 | + description: "Functions must be pure - no hidden mutable state" |
| 60 | + |
| 61 | + forbidden_patterns: [ |
| 62 | + /var\s+\w+\s*=.*;\s*$/m, // Module-level mutable variables |
| 63 | + /static\s+var/, // Static mutable state |
| 64 | + ] |
| 65 | + |
| 66 | + exceptions: [ |
| 67 | + "allocator", // Memory allocation is blessed |
| 68 | + "prng", // Randomness is divine chaos |
| 69 | + ] |
| 70 | + |
| 71 | + penance: "Pass state explicitly as parameter or return new state" |
| 72 | +} |
| 73 | + |
| 74 | +@law SACRED_NAMING { |
| 75 | + severity: "VENIAL_SIN" |
| 76 | + description: "Names must reflect divine purpose" |
| 77 | + |
| 78 | + forbidden_patterns: [ |
| 79 | + /\b(tmp|temp|foo|bar|baz|x|y|z)\b/, // Profane placeholder names |
| 80 | + /\b(data|info|stuff|thing)\b/, // Meaningless abstractions |
| 81 | + ] |
| 82 | + |
| 83 | + penance: "Rename with purpose-revealing name" |
| 84 | +} |
| 85 | + |
| 86 | +@law CYCLOMATIC_PURITY { |
| 87 | + severity: "VENIAL_SIN" |
| 88 | + description: "Functions must not exceed 3 levels of nesting" |
| 89 | + |
| 90 | + max_nesting: 3 |
| 91 | + |
| 92 | + penance: "Extract nested logic into helper functions" |
| 93 | +} |
| 94 | + |
| 95 | +@law CONST_PREFERENCE { |
| 96 | + severity: "MINOR_SIN" |
| 97 | + description: "Prefer const over var unless mutation is required" |
| 98 | + |
| 99 | + check: "Count var declarations that are never reassigned" |
| 100 | + |
| 101 | + penance: "Change 'var' to 'const' for immutable bindings" |
| 102 | +} |
| 103 | + |
| 104 | +@law LAW_EXPLICIT_ALLOCATION { |
| 105 | + severity: "MORTAL_SIN" |
| 106 | + description: "Memory must be passed explicitly. Global state is the root of all evil." |
| 107 | + |
| 108 | + forbidden_patterns: [ |
| 109 | + /std\.heap\.page_allocator/, // Global allocator forbidden directly |
| 110 | + /var\s+gpa/, // Global general purpose allocator instance |
| 111 | + ] |
| 112 | + |
| 113 | + penance: "Pass allocator explicitly to init() or functions" |
| 114 | +} |
| 115 | + |
| 116 | +@law LAW_HOLY_DOCUMENTATION { |
| 117 | + severity: "VENIAL_SIN" |
| 118 | + description: "The Word must be known. Public interfaces must be documented." |
| 119 | + |
| 120 | + pattern: "pub fn without /// comment" |
| 121 | + |
| 122 | + penance: "Add /// documentation comments to public functions" |
| 123 | +} |
| 124 | + |
| 125 | +@law LAW_ERROR_SENSITIVITY { |
| 126 | + severity: "VENIAL_SIN" |
| 127 | + description: "Errors are divine signals, not to be ignored." |
| 128 | + |
| 129 | + forbidden_patterns: [ |
| 130 | + /catch\s+unreachable/, // Hubris |
| 131 | + /catch\s+\{\}/, // Ignorance |
| 132 | + ] |
| 133 | + |
| 134 | + penance: "Handle errors explicitly or propagate with 'try'" |
| 135 | +} |
| 136 | + |
| 137 | +@law LAW_DIVINE_TYPES { |
| 138 | + severity: "MINOR_SIN" |
| 139 | + description: "Types must be explicit and sacred." |
| 140 | + |
| 141 | + forbidden_patterns: [ |
| 142 | + /c_int/, // Profane C types |
| 143 | + /c_uint/, |
| 144 | + /c_long/, |
| 145 | + ] |
| 146 | + |
| 147 | + exceptions: [ |
| 148 | + "@cImport", // Interop is permitted if explicit |
| 149 | + ] |
| 150 | + |
| 151 | + penance: "Use sacred Zig types (usize, i32) or wrap C types" |
| 152 | +} |
| 153 | + |
| 154 | +// ============================================================================ |
| 155 | +// VERDICT STRUCTURE |
| 156 | +// ============================================================================ |
| 157 | + |
| 158 | +@verdict { |
| 159 | + is_valid: bool |
| 160 | + sins: []Sin |
| 161 | + total_severity: int // Sum of sin weights |
| 162 | + suggested_penance: []Penance |
| 163 | +} |
| 164 | + |
| 165 | +@sin { |
| 166 | + law: string // Which law was violated |
| 167 | + severity: string // MORTAL_SIN, VENIAL_SIN, MINOR_SIN |
| 168 | + line: int |
| 169 | + column: int |
| 170 | + description: string |
| 171 | + evidence: string // The offending code |
| 172 | +} |
| 173 | + |
| 174 | +@penance { |
| 175 | + for_sin: ref Sin |
| 176 | + suggestion: string |
| 177 | + replacement: ?string // Optional direct replacement |
| 178 | +} |
| 179 | + |
| 180 | +// ============================================================================ |
| 181 | +// SEVERITY WEIGHTS |
| 182 | +// ============================================================================ |
| 183 | + |
| 184 | +@weights { |
| 185 | + MORTAL_SIN: 100 // Immediate failure |
| 186 | + VENIAL_SIN: 10 // Warning, but passable |
| 187 | + MINOR_SIN: 1 // Suggestion only |
| 188 | + |
| 189 | + max_acceptable_score: 50 // Below this, code is blessed |
| 190 | +} |
0 commit comments