Lint: the new route inventory, its tests and the touched tests

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-11-26 20:33:04 +01:00
co-authored by Claude Opus 5.5
parent d4fe3bf4ba
commit 8f443c9214
8 changed files with 19 additions and 18 deletions
+2 -2
View File
@@ -65,10 +65,10 @@ export const securityRules: DoctorRule[] = [
// first segment merely STARTS with those letters (/administracja, /apis): no locale redirect, and no CSP from the
// proxy on a single-locale site (IAWL idea 36, fixed in the documented literal in 1.17.1).
id: 'proxy-matcher',
check: async (ctx) => {
check: (ctx) => {
const file = `${ctx.src}proxy.ts`
const code = stripComments(ctx.read(file))
const loose = [...code.matchAll(/\(\?!((?:[\w-]+\|)*[\w-]+)\|/g)].map((m) => m[1]!.split('|')).find((names) => names.some((n) => ['_next', 'admin', 'api'].includes(n)))
const loose = [...code.matchAll(/\(\?!((?:[\w-]+\|)*[\w-]+)\|/g)].map((m) => m[1].split('|')).find((names) => names.some((n) => ['_next', 'admin', 'api'].includes(n)))
if (!loose) {return []}
return [{
file,
+1
View File
@@ -59,6 +59,7 @@ function walk(dir: string): string[] {
*/
export async function runRouteCheck(options: RunRouteCheckOptions): Promise<number> {
const cwd = options.cwd ?? process.cwd()
// eslint-disable-next-line no-console -- a command-line check prints its report
const log = options.log ?? ((line: string) => console.log(line))
const appDir = join(cwd, options.appDir ?? 'src/app')
const snapshotFile = join(cwd, options.snapshot ?? 'e2e/routes.snapshot.json')
+4 -4
View File
@@ -80,7 +80,7 @@ export function listNextRouteFiles(
for (const file of files) {
const parts = file.split('/').filter((p) => p && !/^\(.*\)$/.test(p))
const name = parts.pop() ?? ''
const base = name.replace(/\.(?:[cm]?[jt]sx?)$/, '')
const base = name.replace(/\.[cm]?[jt]sx?$/, '')
const path = `/${parts.join('/')}`
if (base === 'route') {
const code = read(file)
@@ -99,12 +99,12 @@ export function listNextRouteFiles(
export type RouteSnapshot = Record<string, string>
export type RouteSnapshotDiff = {
/** Routes the snapshot has and the config no longer opens (not a failure; `--update` drops them). */
gone: string[]
/** Entries whose reason is empty or still says TODO. */
unexplained: string[]
/** Routes the config has and the snapshot does not. */
unjudged: string[]
/** Routes the snapshot has and the config no longer opens (not a failure; `--update` drops them). */
gone: string[]
}
export function compareRouteSnapshot(current: string[], snapshot: RouteSnapshot): RouteSnapshotDiff {
@@ -112,7 +112,7 @@ export function compareRouteSnapshot(current: string[], snapshot: RouteSnapshot)
const now = new Set(current)
return {
gone: [...judged].filter((id) => !now.has(id)).sort(),
unexplained: [...judged].filter((id) => now.has(id) && (!snapshot[id]?.trim() || /^TODO\b/i.test(snapshot[id]!.trim()))).sort(),
unexplained: [...judged].filter((id) => now.has(id) && (!snapshot[id]?.trim() || /^TODO\b/i.test(snapshot[id].trim()))).sort(),
unjudged: current.filter((id) => !judged.has(id)),
}
}