|
| 1 | +import os |
| 2 | + |
| 3 | +def fix_file(filepath, replacements): |
| 4 | + with open(filepath, "r") as f: |
| 5 | + code = f.read() |
| 6 | + for old, new in replacements: |
| 7 | + code = code.replace(old, new) |
| 8 | + with open(filepath, "w") as f: |
| 9 | + f.write(code) |
| 10 | + |
| 11 | +fix_file("src/hooks/useNoteStorage.ts", [ |
| 12 | + ("import { Note } from '../store/useAppStore'", "import type { Note } from '../store/useAppStore'"), |
| 13 | + ("note.content", "note?.content || ''") |
| 14 | +]) |
| 15 | + |
| 16 | +fix_file("src/hooks/useReminders.ts", [ |
| 17 | + ("body: label,", "body: label || '',") |
| 18 | +]) |
| 19 | + |
| 20 | +fix_file("src/hooks/useVariables.ts", [ |
| 21 | + ("const name = varMatch[1]", "const name = varMatch[1]!"), |
| 22 | + ("globals[name] = mathjs.evaluate(varMatch[2]", "globals[name] = mathjs.evaluate(varMatch[2]!"), |
| 23 | + ("globals[name] = varMatch[2].trim()", "globals[name] = varMatch[2]!.trim()") |
| 24 | +]) |
| 25 | + |
| 26 | +fix_file("src/lib/editor/plugins.ts", [ |
| 27 | + ("const name = match[1]", "const name = match[1]!"), |
| 28 | + ("mathjs.evaluate(match[2]", "mathjs.evaluate(match[2]!"), |
| 29 | + ("scope[name] = match[2].trim()", "scope[name] = match[2]!.trim()"), |
| 30 | + ("const targetStr = match[4]", "const targetStr = match[4] || ''"), |
| 31 | + ("const targetMs = new Date(targetStr).getTime()", "const targetMs = targetStr ? new Date(targetStr).getTime() : 0"), |
| 32 | + ("const label = match[3]", "const label = match[3] || ''"), |
| 33 | + ("const exprPart = calcMatch[1]", "const exprPart = calcMatch[1]!"), |
| 34 | + ("const oldResult = calcMatch[2]", "const oldResult = calcMatch[2]!"), |
| 35 | + ("console.log(e)", ""), |
| 36 | + ("const url = match[1]", "const url = match[1]!"), |
| 37 | + ("const path = match[1]", "const path = match[1]!"), |
| 38 | + ("const isDone = match[1] ===", "const isDone = match[1]! ==="), |
| 39 | + ("text.slice(match.index + 2, match.index + match[0].length - 2)", "text.slice(match.index + 2, match.index + match[0]!.length - 2)") |
| 40 | +]) |
| 41 | + |
| 42 | +fix_file("src/utils.ts", [ |
| 43 | + ("const lastPart = parts.pop()", "const lastPart = parts.pop() || ''"), |
| 44 | + ("parts.length > 0", "parts && parts.length > 0") |
| 45 | +]) |
| 46 | + |
| 47 | +fix_file("src/utils.test.ts", [ |
| 48 | + ("const lastPart = parts.pop()", "const lastPart = parts.pop() || ''") |
| 49 | +]) |
| 50 | + |
| 51 | +fix_file("src/App.tsx", [ |
| 52 | + ("const name = match[1]", "const name = match[1]!"), |
| 53 | + ("mathjs.evaluate(match[2]", "mathjs.evaluate(match[2]!"), |
| 54 | + ("scope[name] = match[2].trim()", "scope[name] = match[2]!.trim()"), |
| 55 | + ("const exprPart = calcMatch[1]", "const exprPart = calcMatch[1]!"), |
| 56 | + ("const oldResult = calcMatch[2]", "const oldResult = calcMatch[2]!"), |
| 57 | + ("const filename = note.id.replace", "const filename = note?.id.replace"), |
| 58 | + ("note.content.split", "note?.content.split"), |
| 59 | + ("selNote.id", "selNote?.id"), |
| 60 | + ("selNote.content", "selNote?.content") |
| 61 | +]) |
| 62 | + |
| 63 | +fix_file("src/components/RemindersPage.tsx", [ |
| 64 | + ("const label = match[3]", "const label = match[3] || ''") |
| 65 | +]) |
| 66 | + |
| 67 | +fix_file("src/GraphView.tsx", [ |
| 68 | + ("targetId: match[1]", "targetId: match[1]!") |
| 69 | +]) |
| 70 | + |
0 commit comments