gitoria

calendar

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitb37cc1dab37cc1da|||PR Vendor Hybriel day59Atlasb37cc1da/tests/letcount.py

3.6 KB

  1. #!/usr/bin/env python3
  2. # tests/letcount.py (copied from tickets.worldapi.org mission 010 via gitoria 002 / notes 002; calendar mission 001: sub-folders too): the code-order counts of an app tree (antcolony docs/code-order.md) — root .hl files, project.hl lines, and every `let`:
  3. # reassigned the name is assigned again later in its block → `let` is right
  4. # loop-bound declared inside a for/while body (re-bound each pass —
  5. # Hybriel refuses a plain declaration there on pass 2) → `let` is right
  6. # never neither → should be a plain declaration
  7. # python3 tests/letcount.py . [-v] (-v lists every `let` that should be a plain declaration) (scans *.hl, components/, lib/, tools/, tests/ with sub-folders; not plugins/)
  8. import os, re, sys
  9. root = sys.argv[1]; verbose = '-v' in sys.argv
  10. files = []
  11. files += [os.path.join(root, f) for f in sorted(os.listdir(root)) if f.endswith('.hl')]
  12. for d in ['components', 'lib', 'tools', 'tests']: # with their sub-folders (components/month-view/)
  13. for dp, dn, fn in sorted(os.walk(os.path.join(root, d))): dn.sort(); files += [os.path.join(dp, f) for f in sorted(fn) if f.endswith('.hl')]
  14. def strip(src):
  15. # blank out strings and comments (same length) so braces/names inside them do not count
  16. out = list(src); i = 0; n = len(src)
  17. while i < n:
  18. c = src[i]
  19. if src.startswith('//', i):
  20. j = src.find('\n', i); j = n if j < 0 else j
  21. for k in range(i, j): out[k] = ' '
  22. i = j; continue
  23. if c in '\'"`':
  24. j = i + 1
  25. while j < n and src[j] != c:
  26. if c == "'" and src[j] == '\\' and j + 1 < n and src[j + 1] == "'": j += 2; continue
  27. j += 1
  28. for k in range(i + 1, min(j, n)):
  29. if out[k] != '\n': out[k] = ' '
  30. i = j + 1; continue
  31. i += 1
  32. return ''.join(out)
  33. tot = {'reassigned': 0, 'loop-bound': 0, 'never': 0}
  34. per = {}
  35. for f in files:
  36. s = strip(open(f).read())
  37. opens = []; match = {}; stack = []
  38. for i, c in enumerate(s):
  39. if c == '{': stack.append(i)
  40. elif c == '}' and stack: match[stack.pop()] = i
  41. for m in re.finditer(r'\blet\s+(\w+)\s*=', s):
  42. name, p = m.group(1), m.start()
  43. encl = [o for o, e in match.items() if o < p < e]
  44. encl.sort(reverse=True) # innermost first
  45. inner_end = match[encl[0]] if encl else len(s)
  46. kind = 'never'
  47. if re.search(r'(?<![\w.#])' + re.escape(name) + r'\s*(=(?!=)|\+\+|--|\+=|-=)', s[m.end():inner_end]): kind = 'reassigned'
  48. else:
  49. for o in encl:
  50. head = s[max(0, o - 300):o]
  51. line = head[head.rfind('\n') + 1:] if '\n' in head else head
  52. 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): break
  53. if re.search(r'\b(for|while)\s*\([^{}]*\)\s*$', head): kind = 'loop-bound'; break
  54. tot[kind] += 1
  55. per.setdefault(os.path.relpath(f, root), {'reassigned': 0, 'loop-bound': 0, 'never': 0})[kind] += 1
  56. if verbose and kind == 'never': print(f' never: {os.path.relpath(f, root)}:{s.count(chr(10), 0, p) + 1} {name}')
  57. rootHl = [f for f in os.listdir(root) if f.endswith('.hl')]
  58. pl = sum(1 for _ in open(os.path.join(root, 'project.hl')))
  59. print(f'root .hl files: {len(rootHl)} ({" ".join(sorted(rootHl))})')
  60. print(f'project.hl lines: {pl}')
  61. print(f'let total {sum(tot.values())}: reassigned {tot["reassigned"]}, loop-bound {tot["loop-bound"]}, never reassigned {tot["never"]}')
  62. for f, k in sorted(per.items()): print(f' {f}: {k}')

Branches

Latest commits

  • b37cc1da|||PR Vendor Hybriel day59Atlas
  • 05665102Merge branch 'vendor-day56' into mainAtlas
  • 687296fb|||PR Vendor Hybriel day56Atlas
  • a6166d4eMerge branch 'hl-standard-3' into mainAtlas
  • 6d0eb3b0|||PR Calendar day add buttons only when signed in (Kunibert minor)Atlas
  • add4b499|||PR Make calendar day actions keyboard accessibleAtlas
  • 79e49b4dMerge branch 'hl-standard' into mainAtlas
  • e9fec7bb|||PR HL-STANDARD clean-up: typed parameters, plain locals, by-reference cacheAtlas
  • eff166a4Re-vendor complete Hybriel plugins and runtime to day44mre
  • cef81394Wait for the DST fixture page instead of an unused socketmre
  • 42434f47Check lazy-session cookies after login with a stored anonymous fixturemre
  • 728e84e3Re-vendor complete Hybriel day41 plugin directoriesmre
  • cbd7ff43Backup tar: --hard-dereference, so mpackdb sidecars are never stored as hard links (Tracker's finding)mre
  • 59d1da0acalendar: plain declarations instead of needless let in 9 files (calendar#17): 49 declarations that are never reassigned; reassigned ones and the timer closure's p stay letmre
  • f5415cf9calendar: the Style blocks in the language's nested form (calendar#16): rules named after the View's own elements with their children nested, pseudo-classes and @media nested, merged duplicate select rule; same CSS, shots identical in Chrome at 4 sizesmre
  • edb7c947calendar: the sign-in callback keeps the session it finds and signs it in (same cookie, nothing signed out; ident#28); security gate 56+4 failing → 60 passedmre
  • bf8cc0fcStyles move into their components: the shell's styles into main.hl, the events and the editors into the month view's Style block; styles.hl keeps only the theme inherit, the accent and the message line; .gitignore ignores a bin symlink too; tests/styles-shots.mjs for the before/after pixel comparemre
  • 5d8579d7README: login.js stays by caramboleyo's explicit rulemre
  • cc759328Merge sb3-standby: calendar deploys through its standbymre
  • f2fcdc6dcalendar: a standby container (port 45015, profile standby, reminder clock off) and a /health page; deploy hands over through standby-swap.sh without a gapmre