From 53a119daa231360c219551a6b0cf984a3c0d2238 Mon Sep 17 00:00:00 2001 From: Wolfvin Date: Sun, 12 Jul 2026 01:44:20 +0700 Subject: [PATCH] fix(circular): strip comments before import scan, fixes self-import false positive MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit _parse_js_imports() regex-matched 'import ... from ...' anywhere in raw file content, including inside // line comments and /* */ block comments. A file with a usage-example comment referencing its own import path (e.g. permission-gate.ts's docstring: '// import { requirePermission } from ../middleware/permission-gate') got flagged as importing itself, producing a false-positive self-loop 'circular import' cycle. Found via real-codebase validation (Coretax-Auto-Downloader KDS backend): deps --check circular reported 2 cycles, both self-loops on permission-gate.ts, ← both traced back to the same commented-out example line, not real code. Fix: reuse the existing _remove_comments() helper (already used by complexity_engine.py for the same class of false-positive) before running the import regexes. --- scripts/circular_engine.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/scripts/circular_engine.py b/scripts/circular_engine.py index 195e930a..81771378 100755 --- a/scripts/circular_engine.py +++ b/scripts/circular_engine.py @@ -785,6 +785,17 @@ def _parse_js_imports(content: str, file_rel_path: str, workspace: str) -> List[ imports = [] file_dir = os.path.dirname(file_rel_path) + # Strip comments before scanning. Without this, an `import ... from '...'` + # example inside a `//` line comment or a docstring-style block comment + # gets matched as a real import, producing false self-import "cycles" + # (found via real-codebase validation: permission-gate.ts's own usage + # example comment — `// import { requirePermission } from + # '../middleware/permission-gate'` — was detected as the file importing + # itself). + from complexity_engine import _remove_comments + ext = os.path.splitext(file_rel_path)[1].lower() + content = _remove_comments(content, ext) + # ES module imports: import X from './path' or '../path' for m in re.finditer(r'import\s+.*?from\s+["\'](\.{1,2}/[^"\']+)["\']', content): raw = m.group(1)