**Brief approach**I’d build a static-analysis tool that parses the central JSON token file, indexes token values, and scans web/mobile repositories (JS/TS, Swift, Kotlin, XML, CSS/Sass) to map usages. Then it reports unused tokens, likely duplicates (same value across different names), and produces a migration plan linking token names → code references and suggested consolidations.**Pseudocode**python
# Pseudocode
load tokens = parse_json("tokens.json") # {name: value}
index_value_to_names = invert(tokens) # {value: [names]}
refs = {} # {token_name: [file:line,...]}
for repo in repos:
for file in repo.files:
text = read(file)
for token_name in tokens:
if token_pattern(token_name) in text: # pattern tuned per platform
refs[token_name].append(file:line)
unused = [n for n in tokens if refs[n] is empty]
duplicates = {v: names for v,names in index_value_to_names.items() if len(names)>1}
# Migration suggestions: pick canonical name (e.g., longest-used or design-pref)
for value,names in duplicates:
canonical = choose_canonical(names, refs)
suggest replacing other names -> canonical with refs report
generate_report(unused, duplicates, refs)
**Key concepts & reasoning**- Use platform-aware token patterns (e.g., css var, JS import paths, Swift constants) to reduce false positives.- Canonical selection uses frequency, semantic hint (prefix), or designer preference file.**Time & space complexity**- Scanning: O(F * T) where F = total file size, T = number of token names (naïve). Optimize by building a regex alternation or using an indexed search (Aho–Corasick) to get O(F + total_matches).- Space: O(T + M) for index and match list.**Likely false positives / negatives**- False positives: substring matches in comments, variable names. Mitigate by language-aware parsing and word-boundary patterns.- False negatives: runtime-generated token names, tokens referenced via computed keys or mapped themes. Mitigate by scanning build artifacts and runtime logs.**CI integration**- Run as a job that fails on thresholds (e.g., > X unused or breaking consolidations). Output structured report (JSON + human-readable) and GitHub PR comments with suggested codemods. Provide a “dry-run” and an auto-apply mode gated by design approval.**Edge cases & alternatives**- The tool should support tag/metadata in tokens to mark “deprecated” or “do-not-remove.”- Alternative: combine with runtime telemetry to confirm unused tokens in production.