Regexes with super-linear backtracking (S8786 x16) are rewritten to stay linear on long runs; each new pattern gives the same results as the old one on 150k-450k fuzzed inputs (except where noted) and finishes adversarial 50k-character inputs in under 3 ms: - tag-generator QUALIFIER_SUFFIX_RE starts just before a `:`/space run (`(^|[^:\s])…` + "$1"), never inside one - timeline-parser matches `line.trimEnd()` with a greedy label, and renders with trimEnd(); cleanCpuName collapses whitespace before the patterns - editor-store endings, Google Play urlPattern (lookahead for `id=`), channel-phrase punctuation, SPDX OR/AND split, legal-docs slug and link stripping (link text/URL may not contain `[`), base64url padding, and a loop for trailing slashes in the worker router Others: - S2871: sorts take the shared code-unit comparator (same order as before; THIRD_PARTY_NOTICES is unchanged) - S4822: ErrorBoundary catches the logger import with .catch(), which a try/catch never could - S3516: migrateProfilesState returns a new object - S7773: Number.parseInt (x10) - S9379: Modal takes an initialFocusRef (Radix onOpenAutoFocus), so the shortcut search box gets focus without an autoFocus attribute - S2245: generateId drops the Math.random fallback; getRandomValues exists everywhere the app runs, and a non-random ID is worse than an error - S4036: NOSONAR on the dev script's `git` call (PATH lookup by design) - S6505/S8543: every workflow installs with `npm ci --ignore-scripts`, and CI runs `npm run cf:check` instead of `npx wrangler …` - S6358: Android sets allowBackup="false" — app data is no longer copied to Google Drive backups; Backup & Restore moves it to a new phone Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
112 lines
4.0 KiB
TypeScript
112 lines
4.0 KiB
TypeScript
/**
|
|
* Copyright years, kept current.
|
|
*
|
|
* npm run check:copyright fail if a notice states the wrong years
|
|
* npm run update:copyright rewrite them to the expected years
|
|
*
|
|
* The years are written by hand in three files — NOTICE, REUSE.toml and the
|
|
* installers' copyright string in src-tauri/tauri.conf.json — and nothing
|
|
* used to keep them current. Each must state `copyrightYears(year)` from
|
|
* src/config/brand.ts: "2026", then "2026-2027" from the first commit made in
|
|
* 2027, and so on.
|
|
*
|
|
* "This year" is the year HEAD was committed, not the clock: re-running CI on
|
|
* an old commit stays green, and the first new work in a new year is what asks
|
|
* for the bump. Without git (a source tarball) it falls back to the UTC year.
|
|
*
|
|
* Deliberately left alone: the `[yyyy]` placeholder in the Apache-2.0
|
|
* appendix (LICENSE, LICENSES/Apache-2.0.txt), the Gradle wrapper's own 2015
|
|
* notice, CHANGELOG history and the `{{year}}` of generated descriptions.
|
|
*/
|
|
import { execFileSync } from "child_process";
|
|
import { readFileSync, writeFileSync } from "fs";
|
|
import { resolve } from "path";
|
|
import { copyrightYears } from "../../src/config/brand.ts";
|
|
|
|
const ROOT = resolve(import.meta.dirname, "../..");
|
|
|
|
export interface Notice {
|
|
/** Repo-relative path. */
|
|
file: string;
|
|
/** Finds the notice; capture group 1 is its years ("2026", "2026-2027"). */
|
|
pattern: RegExp;
|
|
}
|
|
|
|
export const NOTICES: readonly Notice[] = [
|
|
{ file: "NOTICE", pattern: /^Copyright ([0-9]{4}(?:-[0-9]{4})?) poli0981 /m },
|
|
{
|
|
file: "REUSE.toml",
|
|
pattern: /^SPDX-FileCopyrightText = "([0-9]{4}(?:-[0-9]{4})?) poli0981 /m,
|
|
},
|
|
{
|
|
file: "src-tauri/tauri.conf.json",
|
|
pattern: /"copyright": "Copyright ([0-9]{4}(?:-[0-9]{4})?) poli0981 /,
|
|
},
|
|
];
|
|
|
|
export interface NoticeCheck {
|
|
notice: Notice;
|
|
/** The years the file states now, or null when the notice is not found. */
|
|
found: string | null;
|
|
expected: string;
|
|
}
|
|
|
|
function readRepoFile(file: string): string {
|
|
return readFileSync(resolve(ROOT, file), "utf8");
|
|
}
|
|
|
|
/** The year HEAD was committed, or this UTC year when git is unavailable. */
|
|
export function headCommitYear(): number {
|
|
try {
|
|
const options = { cwd: ROOT, encoding: "utf8" } as const;
|
|
// A dev/CI script: `git` is whichever one the developer's PATH or the CI
|
|
// image provides, by design — there is no fixed install path to pin.
|
|
const iso = execFileSync("git", ["log", "-1", "--format=%cI"], options); // NOSONAR
|
|
const year = Number(iso.trim().slice(0, 4));
|
|
if (Number.isInteger(year) && year >= 2000) return year;
|
|
} catch {
|
|
// Not a git checkout.
|
|
}
|
|
return new Date().getUTCFullYear();
|
|
}
|
|
|
|
/** Every notice's current years against the ones `year` calls for. */
|
|
export function checkNotices(year: number, read = readRepoFile): NoticeCheck[] {
|
|
const expected = copyrightYears(year);
|
|
return NOTICES.map((notice) => ({
|
|
notice,
|
|
found: notice.pattern.exec(read(notice.file))?.[1] ?? null,
|
|
expected,
|
|
}));
|
|
}
|
|
|
|
/** `raw` with the notice's years swapped for `years`; nothing else changes. */
|
|
export function withYears(raw: string, notice: Notice, years: string): string {
|
|
return raw.replace(notice.pattern, (match, current: string) => match.replace(current, years));
|
|
}
|
|
|
|
export function main(): void {
|
|
const write = process.argv.includes("--write");
|
|
let failed = false;
|
|
for (const { notice, found, expected } of checkNotices(headCommitYear())) {
|
|
if (found === expected) {
|
|
console.log(`✓ ${notice.file}: ${found}`);
|
|
} else if (found === null) {
|
|
failed = true;
|
|
console.error(`✗ ${notice.file}: no copyright notice found (expected ${expected}).`);
|
|
} else if (write) {
|
|
writeFileSync(
|
|
resolve(ROOT, notice.file),
|
|
withYears(readRepoFile(notice.file), notice, expected),
|
|
);
|
|
console.log(`✎ ${notice.file}: ${found} → ${expected}`);
|
|
} else {
|
|
failed = true;
|
|
console.error(
|
|
`✗ ${notice.file}: ${found}, expected ${expected}. Run: npm run update:copyright`,
|
|
);
|
|
}
|
|
}
|
|
if (failed) process.exit(1);
|
|
}
|