Files
hakorune/tools/hako_check/rules/rule_static_top_assign.hako
nyash-codex 50ac8af2b8 Phase 21.4 Complete: FileBox SSOT + Analyzer Stabilization (7 Tasks)
 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>
2025-11-08 17:04:21 +09:00

56 lines
1.9 KiB
Plaintext

static box RuleStaticTopAssignBox {
apply(text, path, out) {
local n = text.length(); local line = 1
local in_static = 0; local brace = 0; local in_method = 0
local i = 0
while i < n {
local c = text.substring(i, i+1)
if c == "\n" { line = line + 1 }
if in_static == 0 {
if me._match_kw(text, i, "static box ") { in_static = 1; in_method = 0 }
}
if in_static == 1 {
if in_method == 0 && me._match_kw(text, i, "method ") { in_method = 1 }
if c == "{" { brace = brace + 1 }
if c == "}" { brace = brace - 1; if brace <= 0 { in_static = 0; in_method = 0 } }
if in_method == 0 {
if me._is_line_head(text, i) == 1 {
if me._is_ident_start(c) == 1 {
// find '=' before EOL
local seen_eq = 0
local off = 0; while off < n {
local j = i + 1 + off
if j >= n { break }
local cj = text.substring(j, j+1)
if cj == "\n" { break }
if cj == "=" { seen_eq = 1; break }
off = off + 1 }
if seen_eq == 1 {
out.push("[HC001] top-level assignment in static box (use lazy init in method): " + path + ":" + ("" + line))
}
}
}
}
}
i = i + 1
}
}
_match_kw(s,i,kw) { local k=kw.length(); if i+k>s.length() { return 0 }; if s.substring(i,i+k)==kw { return 1 } return 0 }
_is_ident_start(c) { if c=="_" {return 1}; if c>="A"&&c<="Z" {return 1}; if c>="a"&&c<="z" {return 1}; return 0 }
_is_line_head(s,i) {
local r = 0
while r <= i {
if i==0 {return 1}
local j=i-1-r
local cj=s.substring(j,j+1)
if cj=="\n" {return 1}
if cj!=" "&&cj!="\t" {return 0}
if j==0 {return 1}
r = r + 1
}
return 1
}
}
static box RuleStaticTopAssignMain { method main(args) { return 0 } }