✅ Task 1: Fallback Guarantee (create_box failure → ring1/core-ro auto fallback) - Three-tier fallback system: plugin → builtin → core-ro - Mode control: auto/plugin-only/core-ro - New: src/box_factory/builtin_impls/file_box.rs - New: tools/test_filebox_fallback_smoke.sh ✅ Task 2: Provider Registration SSOT (static/dynamic/core-ro unified) - ProviderFactory trait with priority-based selection - Global registry PROVIDER_FACTORIES implementation - Priority: dynamic(100) > builtin(10) > core-ro(0) - New: src/boxes/file/builtin_factory.rs - New: tools/smoke_provider_modes.sh ✅ Task 3: FileBox Publication Unification - Verified: basic/file_box.rs already minimized (11 lines) - Perfect re-export pattern maintained ✅ Task 4: ENV Unification (FILEBOX_MODE/DISABLE_PLUGINS priority) - Removed auto-setting of NYASH_USE_PLUGIN_BUILTINS - Removed auto-setting of NYASH_PLUGIN_OVERRIDE_TYPES - Added deprecation warnings with migration guide - ENV hierarchy: DISABLE_PLUGINS > BOX_FACTORY_POLICY > FILEBOX_MODE ✅ Task 5: Error Log Visibility (Analyzer rule execution errors to stderr) - Added [rule/exec] logging before IR-based rule execution - Format: [rule/exec] HC012 (dead_static_box) <filepath> - VM errors now traceable via stderr output ✅ Task 6: Unnecessary Using Removal (14 rules Str alias cleanup) - Removed unused `using ... as Str` from 14 rule files - All rules use local _itoa() helper instead - 14 lines of dead code eliminated ✅ Task 7: HC017 Skip & TODO Documentation (UTF-8 support required) - Enhanced run_tests.sh with clear skip message - Added "Known Limitations" section to README.md - Technical requirements documented (3 implementation options) - Re-enable timeline: Phase 22 (Unicode Support Phase) 📊 Test Results: - Analyzer: 10 tests PASS, 1 skipped (HC017) - FileBox fallback: All 3 modes PASS - Provider modes: All 4 modes PASS - Build: Success (0 errors, 0 warnings) 🎯 Key Achievements: - 28 files modified/created - Three-Tier Fallback System (stability) - SSOT Provider Registry (extensibility) - ENV unification (operational clarity) - Error visibility (debugging efficiency) - Code cleanup (maintainability) - Comprehensive documentation (Phase 22 ready) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
115 lines
2.8 KiB
Plaintext
115 lines
2.8 KiB
Plaintext
// tools/hako_check/rules/rule_top_level_local.hako — HC018: Top-level local in prelude
|
|
// Detects top-level `local` statements (outside of methods/boxes), which are cleanup omissions.
|
|
|
|
static box RuleTopLevelLocalBox {
|
|
method apply(text, path, out) {
|
|
if text == null { return 0 }
|
|
|
|
local lines = me._split_lines(text)
|
|
local i = 0
|
|
local in_box = 0
|
|
local in_method = 0
|
|
local brace_depth = 0
|
|
|
|
while i < lines.size() {
|
|
local ln = lines.get(i)
|
|
local trimmed = me._trim(ln)
|
|
|
|
// Track context: are we inside a box or method?
|
|
if trimmed.indexOf("box ") == 0 || trimmed.indexOf("static box ") == 0 {
|
|
in_box = 1
|
|
}
|
|
if in_box == 1 && (trimmed.indexOf("method ") >= 0 || trimmed.indexOf("birth(") >= 0) {
|
|
in_method = 1
|
|
}
|
|
|
|
// Track brace depth
|
|
local j = 0
|
|
while j < trimmed.length() {
|
|
local ch = trimmed.substring(j, j+1)
|
|
if ch == "{" { brace_depth = brace_depth + 1 }
|
|
if ch == "}" {
|
|
brace_depth = brace_depth - 1
|
|
if brace_depth == 0 {
|
|
in_method = 0
|
|
in_box = 0
|
|
}
|
|
}
|
|
j = j + 1
|
|
}
|
|
|
|
// Check for top-level local (not inside method, not a comment)
|
|
if trimmed.indexOf("local ") == 0 {
|
|
if in_method == 0 && me._is_comment(trimmed) == 0 {
|
|
out.push("[HC018] top-level local declaration (not allowed): " + path + ":" + me._itoa(i+1))
|
|
}
|
|
}
|
|
|
|
i = i + 1
|
|
}
|
|
return out.size()
|
|
}
|
|
|
|
_trim(s) {
|
|
if s == null { return "" }
|
|
local start = 0
|
|
local end = s.length()
|
|
|
|
// Trim leading whitespace
|
|
while start < end {
|
|
local ch = s.substring(start, start+1)
|
|
if ch == " " || ch == "\t" { start = start + 1 } else { break }
|
|
}
|
|
|
|
// Trim trailing whitespace
|
|
while end > start {
|
|
local ch = s.substring(end-1, end)
|
|
if ch == " " || ch == "\t" || ch == "\n" || ch == "\r" { end = end - 1 } else { break }
|
|
}
|
|
|
|
return s.substring(start, end)
|
|
}
|
|
|
|
_is_comment(s) {
|
|
if s == null { return 0 }
|
|
local trimmed = me._trim(s)
|
|
if trimmed.indexOf("//") == 0 { return 1 }
|
|
return 0
|
|
}
|
|
|
|
_split_lines(s) {
|
|
local arr = new ArrayBox()
|
|
if s == null { return arr }
|
|
local n = s.length()
|
|
local last = 0
|
|
local i = 0
|
|
loop(i < n) {
|
|
local ch = s.substring(i, i+1)
|
|
if ch == "\n" {
|
|
arr.push(s.substring(last, i))
|
|
last = i + 1
|
|
}
|
|
i = i + 1
|
|
}
|
|
if last <= n { arr.push(s.substring(last)) }
|
|
return arr
|
|
}
|
|
|
|
_itoa(n) {
|
|
local v = 0 + n
|
|
if v == 0 { return "0" }
|
|
local out = ""
|
|
local digits = "0123456789"
|
|
local tmp = ""
|
|
while v > 0 {
|
|
local d = v % 10
|
|
tmp = digits.substring(d, d+1) + tmp
|
|
v = v / 10
|
|
}
|
|
out = tmp
|
|
return out
|
|
}
|
|
}
|
|
|
|
static box RuleTopLevelLocalMain { method main(args) { return 0 } }
|