layouts
All repositories: gitoria
5.1 KB
#!/usr/bin/env python3# tests/letcount.py (copied from tickets.worldapi.org mission 010 via gitoria mission 002; ident mission 009 added `member` and `twice`; components mission 002: components/ recursive, `twice` also in methods): the code-order counts of an app tree (antcolony docs/code-order.md) — root .hl files, project.hl lines, and every `let`:# reassigned the name is assigned again later in its block → `let` is right# loop-bound declared inside a for/while body (re-bound each pass —# Hybriel refuses a plain declaration there on pass 2) → `let` is right# member the name is also a member / static / import of the file# (a plain `x = …` would assign that instead of declaring) → `let` is right# twice the name is declared twice in one function (sibling# blocks: Hybriel refuses the 2nd plain declaration) → `let` is right# never none of these → should be a plain declaration# python3 tests/letcount.py . [-v] (-v lists every `let` that should be a plain declaration) (scans *.hl, components/, lib/, tools/, tests/; not plugins/)import os, re, sysroot = sys.argv[1]; verbose = '-v' in sys.argvfiles = []files += [os.path.join(root, f) for f in sorted(os.listdir(root)) if f.endswith('.hl')]for d in ['components', 'lib', 'tools', 'tests']: # components.hybriel: recursive (one folder per component)for dp, dns, fns in sorted(os.walk(os.path.join(root, d))):dns.sort(); files += [os.path.join(dp, f) for f in sorted(fns) if f.endswith('.hl')]def strip(src):# blank out strings and comments (same length) so braces/names inside them do not countout = list(src); i = 0; n = len(src)while i < n:c = src[i]if src.startswith('//', i):j = src.find('\n', i); j = n if j < 0 else jfor k in range(i, j): out[k] = ' 'i = j; continueif c in '\'"`':j = i + 1while j < n and src[j] != c:if c == "'" and src[j] == '\\' and j + 1 < n and src[j + 1] == "'": j += 2; continuej += 1for k in range(i + 1, min(j, n)):if out[k] != '\n': out[k] = ' 'i = j + 1; continuei += 1return ''.join(out)tot = {'reassigned': 0, 'loop-bound': 0, 'member': 0, 'twice': 0, 'never': 0}per = {}for f in files:s = strip(open(f).read())names = set(re.findall(r'^(?:static\s+)?(?:[A-Z]\w*\s+)?#?(\w+)\s*(?:=|\()', s, re.M))for m in re.finditer(r'^import\s*\{([^}]*)\}', s, re.M): names |= {x.strip() for x in m.group(1).split(',') if x.strip()}names |= set(re.findall(r'^import\s+(\w+)\s+from', s, re.M))opens = []; match = {}; stack = []for i, c in enumerate(s):if c == '{': stack.append(i)elif c == '}' and stack: match[stack.pop()] = ifor m in re.finditer(r'\blet\s+(\w+)\s*=', s):name, p = m.group(1), m.start()encl = [o for o, e in match.items() if o < p < e]encl.sort(reverse=True) # innermost firstinner_end = match[encl[0]] if encl else len(s)kind = 'never'if re.search(r'(?<![\w.#])' + re.escape(name) + r'\s*(=(?!=)|\+\+|--|\+=|-=)', s[m.end():inner_end]): kind = 'reassigned'else:for o in encl:head = s[max(0, o - 300):o]line = head[head.rfind('\n') + 1:] if '\n' in head else headif re.search(r'=>\s*$', head) or re.match(r'\s*(on\s|static\s|\w+\s*\([^)]*\)\s*$)', line) and not re.match(r'\s*(if|for|while|else)\b', line): breakif re.search(r'\b(for|while)\s*\([^{}]*\)\s*$', head): kind = 'loop-bound'; breakif kind == 'never' and name in names: kind = 'member'if kind == 'never':fn = None # the enclosing function: lambda, `on`/`static` handler or a method `name(args) {` (components m002: methods too)for o in encl:head = s[max(0, o - 300):o]; line = head[head.rfind('\n') + 1:]if re.search(r'=>\s*$', head) or (re.match(r'\s*(on\s|static\s|\w+\s*\([^)]*\)\s*$)', line) and not re.match(r'\s*(if|for|while|else)\b', line)): fn = o; breakif fn is not None and len(re.findall(r'\blet\s+' + re.escape(name) + r'\s*=', s[fn:match[fn]])) > 1: kind = 'twice'tot[kind] += 1per.setdefault(os.path.relpath(f, root), {'reassigned': 0, 'loop-bound': 0, 'member': 0, 'twice': 0, 'never': 0})[kind] += 1if verbose and kind == 'never': print(f' never: {os.path.relpath(f, root)}:{s.count(chr(10), 0, p) + 1} {name}')rootHl = [f for f in os.listdir(root) if f.endswith('.hl')]pl = sum(1 for _ in open(os.path.join(root, 'project.hl')))print(f'root .hl files: {len(rootHl)} ({" ".join(sorted(rootHl))})')print(f'project.hl lines: {pl}')print(f'let total {sum(tot.values())}: reassigned {tot["reassigned"]}, loop-bound {tot["loop-bound"]}, member name {tot["member"]}, declared twice {tot["twice"]}, never reassigned {tot["never"]}')for f, k in sorted(per.items()): print(f' {f}: {k}')
Branches
Latest commits
- 7979397creport ML-mobilemre
- 85d2ed25gate: wordingmre
- 98a311c0gate: 390 px checks for list rows, table word, edited tap target, code in titlesmre
- 769b99d7theme: table cells keep a word whole, code in a title stays text-sized, 'edited' is a 44 px tap target on the phonemre
- c36b7595list rows (notes, mail) stack their parts full width: the date no longer a one-letter column beside the titlemre
- 02aa74aasync components.hybriel 134b4e3: MdEditor builds an editor put into the page at once, redraws a surface put in anew (F5, hybriel#211)mre
- 268b1c87sync components.hybriel 6b0936a: the 'edited' foldable drops the theme's border and marginmre
- c51d039fsync components.hybriel 8d79ff7: bubble hugs its content, quiet 'edited' label; gate checksmre
- f4ad7eecsync components 9a: shared Icon (icons/icons.hl), md-editor toolbar icons + single focus ring (components f4-icons ba96735)mre
- db258c11sync-components: copy icons/icons.hl + README (F4); testsmre
- badc1879md-editor.hl: verbatim copy of components f3-mdvalue (an older text handed back is kept)mre
- 867a8375md-editor.hl: verbatim copy of components f3-mdvalue (an outside value change is shown by the editor)mre
- 5d8d2c67tests: wait for hydration before real clicks after a navigation (H2)mre
- 99db79f0re-vendor Hybriel 5406d146 (hl:web batches 9+10: #72 emits while the socket is closed delivered after reconnect, browser boot linear, faster list appends; contains int 6–14 + m406)mre
- 30353f60tests: e2e-md-showcase Chrome range from LAYOUTS_GATE_CHROME_MD, default unchangedmre
- 16a7878cre-vendor Hybriel 6f8a0689 (int 6–11: streaming cursors, #203 index heal + close() fix, fd403 listDir/cursor fds, hl:time browser side, hl:web batches 5+6)mre
- 6af559e8docker-compose: nofile 65536 (Hybriel int 6+ boot opened >1024 files in the tracker)mre
- 5599cf56deploy: backup copies index files first and *.mpack data last (hot-copy skew, hybriel #203)mre
- 0bcc6294Mission 011: e2e-197, brief, report, LOGmre
- 137303c5MainMenu marks the current page from the route (hybriel#197, server-rendered); current prop/item.current stay as fallback; tracker demo drops current; gate: SSR marker; docsmre