nx_code_quality.nx
buildroot/runtime/nx_code_quality.nx
about
nx_code_quality.nx -- qualitative + quantitative code refactor verdict.
Six measurable axes -> Q10 score per axis + sealed-enum CodeQualityVerdict.
Operates on a source-text byte buffer (any language whose lexical
substrate uses { } ( ) [ ] for nesting + // for comments -- which covers
NishiLang, C, Rust, Go, Java, JavaScript, TypeScript, C++).
Refactor triggers (each maps to a Q10 axis):
1. NULL_PTR_HAZARD count of `0 as *` patterns (NULL sentinel)
normalized by source length
2. HARDCODING_SCORE count of `* 8`, `* 4` literals not in
comments (cardinal-violation signal:
should be NX_SIZEOF_NX_INT etc.)
3. NESTING_HAZARD maximum bracket nesting depth (cyclomatic
proxy; deep nesting -> refactor)
4. REPETITION_HAZARD line-length-diversity proxy (very uniform
line lengths -> repetition; very long
single lines -> readability issue)
5. COMMENT_DEFICIT comment density below threshold ->
documentation gap
6. TIER_COMPLIANCE bare `i64 ` occurrences (should use
nx_int / nx_size / nx_idx aliases)
Composite_q10 = inverse-weighted sum across axes (low hazard count
+ good comment density + nx_tier compliance = high composite).
Sealed-enum verdict:
NX_CQ_REFACTOR_HOT composite < 300 immediate refactor
NX_CQ_REFACTOR_RECOMMENDED 300 <= comp < 600
NX_CQ_ACCEPTABLE 600 <= comp < 800
NX_CQ_EXCELLENT comp >= 800
Cross-language: same primitive over any text-source byte stream
(NishiLang .nx, C .c, Rust .rs, prose .txt -- though the cardinal-
violation axes 1, 2, 6 are NishiLang-specific; they read as
no-op on other languages where those patterns don't appear).
"Competitive coding best practices" reading per dual-reading
cardinal: the qualitative verdict names WHICH refactor is most
dependencies 2 imports · 1 importers
imports: nx_syscalls.nxnx_tier.nx
imported by: nx_code_quality_test.nx
structs
| 74 | struct CodeQualityReport |
consts
| 57 | const NX_CQ_Q: nx_int = 1024 |
| 58 | const NX_CQ_MAX_NESTING_OK: nx_int = 5 |
| 60 | const NX_CQ_REFACTOR_HOT: nx_int = 0 |
| 61 | const NX_CQ_REFACTOR_RECOMMENDED: nx_int = 1 |
| 62 | const NX_CQ_ACCEPTABLE: nx_int = 2 |
| 63 | const NX_CQ_EXCELLENT: nx_int = 3 |
| 64 | const NX_CQ_N_VERDICTS: nx_int = 4 |
| 66 | const NX_CQ_AXIS_NULL_PTR: nx_int = 0 |
| 67 | const NX_CQ_AXIS_HARDCODING: nx_int = 1 |
| 68 | const NX_CQ_AXIS_NESTING: nx_int = 2 |
| 69 | const NX_CQ_AXIS_REPETITION: nx_int = 3 |
| 70 | const NX_CQ_AXIS_COMMENT: nx_int = 4 |
| 71 | const NX_CQ_AXIS_TIER: nx_int = 5 |
| 72 | const NX_CQ_N_AXES: nx_int = 6 |
functions
| 95 | func _cq_match_at(buf: *u8, len: nx_int, pos: nx_int, lit: *u8, n: nx_int) -> nx_int called by 1: nx_code_quality_scan |
| 108 | func _cq_in_comment(buf: *u8, pos: nx_int) -> nx_int called by 1: nx_code_quality_scan |
| 127 | func nx_code_quality_scan(buf: *u8, len: nx_int, report: *CodeQualityReport) -> nx_int |
| 286 | func nx_code_quality_score(report: *CodeQualityReport) -> nx_int called by 1: nx_code_quality_compute |
| 371 | func nx_code_quality_verdict_is_valid(v: nx_int) -> nx_int called by 1: main |
| 377 | func nx_code_quality_axis_is_valid(a: nx_int) -> nx_int called by 1: main |
| 385 | func nx_code_quality_compute(buf: *u8, len: nx_int, report: *CodeQualityReport) -> nx_int |