periderm-cli 0.1.71 → 0.1.72
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/scanner/checks.js +98 -25
- package/dist/scanner/seo-checks.js +3 -4
- package/dist/scanner/walk.js +6 -0
- package/package.json +1 -1
package/dist/scanner/checks.js
CHANGED
|
@@ -10,6 +10,31 @@ import { reportCliError } from "../error-report.js";
|
|
|
10
10
|
// @babel/traverse ships CJS; pick the default export defensively.
|
|
11
11
|
const traverse = traverseDefault.default ??
|
|
12
12
|
traverseDefault;
|
|
13
|
+
function isToolingPath(file) {
|
|
14
|
+
return (/(^|\/)(scripts|vite\.config|vitest\.config|eslint\.config)/.test(file) ||
|
|
15
|
+
/\.(?:test|spec)\./.test(file) ||
|
|
16
|
+
/(^|\/)(test\d*|test-server)\.js$/.test(file));
|
|
17
|
+
}
|
|
18
|
+
function isInsideCreateServerFn(p) {
|
|
19
|
+
let cur = p;
|
|
20
|
+
while (cur) {
|
|
21
|
+
if (cur.node?.type === "CallExpression") {
|
|
22
|
+
let n = cur.node.callee;
|
|
23
|
+
while (n) {
|
|
24
|
+
if (n.type === "Identifier" && n.name === "createServerFn")
|
|
25
|
+
return true;
|
|
26
|
+
if (n.type === "MemberExpression")
|
|
27
|
+
n = n.object;
|
|
28
|
+
else if (n.type === "CallExpression")
|
|
29
|
+
n = n.callee;
|
|
30
|
+
else
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
cur = cur.parentPath;
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
13
38
|
const lineOf = (source, idx) => source.slice(0, idx).split("\n").length;
|
|
14
39
|
function stripStrings(source) {
|
|
15
40
|
return source.replace(/`[^`]*`|"[^"\n]*"|'[^'\n]*'/g, "''");
|
|
@@ -40,7 +65,7 @@ const silentCatch = (source, file, ast) => {
|
|
|
40
65
|
CatchClause(p) {
|
|
41
66
|
const body = p.node.body.body;
|
|
42
67
|
const catchSrc = source.slice(p.node.start ?? 0, p.node.end ?? 0);
|
|
43
|
-
if (/periderm-ignore
|
|
68
|
+
if (/periderm-ignore|keep original|ignore auth|unauthenticated|fallback/i.test(catchSrc))
|
|
44
69
|
return;
|
|
45
70
|
if (body.length === 0) {
|
|
46
71
|
out.push(mkFinding({
|
|
@@ -66,6 +91,8 @@ const silentCatch = (source, file, ast) => {
|
|
|
66
91
|
e.callee.object.name === "console");
|
|
67
92
|
});
|
|
68
93
|
if (onlyConsole) {
|
|
94
|
+
if (isToolingPath(file) || isInsideCreateServerFn(p))
|
|
95
|
+
return;
|
|
69
96
|
out.push(mkFinding({
|
|
70
97
|
id: "silent-catch-console",
|
|
71
98
|
category: "Runtime Stability",
|
|
@@ -87,6 +114,8 @@ const silentCatch = (source, file, ast) => {
|
|
|
87
114
|
// ───────────────────────────────────────────────────────────────────────
|
|
88
115
|
const envLeak = (source, file) => {
|
|
89
116
|
const out = [];
|
|
117
|
+
if (isToolingPath(file) || /(^|\/)scripts\//.test(file))
|
|
118
|
+
return out;
|
|
90
119
|
const isServer = /\.server\.|\/api\/|\.functions\.|server-fn|createServerFn/.test(file + source);
|
|
91
120
|
if (isServer)
|
|
92
121
|
return out;
|
|
@@ -96,6 +125,9 @@ const envLeak = (source, file) => {
|
|
|
96
125
|
const name = m[1];
|
|
97
126
|
if (/^(NODE_ENV|VITE_)/.test(name))
|
|
98
127
|
continue;
|
|
128
|
+
// Public-by-design names (Supabase anon / publishable keys, etc.)
|
|
129
|
+
if (/(PUBLISHABLE|ANON|PUBLIC)/.test(name))
|
|
130
|
+
continue;
|
|
99
131
|
if (/(SECRET|KEY|TOKEN|PASSWORD|PRIVATE)/.test(name)) {
|
|
100
132
|
out.push(mkFinding({
|
|
101
133
|
id: "env-leak",
|
|
@@ -386,7 +418,7 @@ const consoleLog = (source, file) => {
|
|
|
386
418
|
const out = [];
|
|
387
419
|
if (!/\.(tsx|jsx|ts|js)$/.test(file))
|
|
388
420
|
return out;
|
|
389
|
-
if (/\.test\.|\.spec\.|\/scripts\//.test(file))
|
|
421
|
+
if (/\.test\.|\.spec\.|\/scripts\//.test(file) || isToolingPath(file))
|
|
390
422
|
return out;
|
|
391
423
|
const matches = source.match(/console\.log\s*\(/g);
|
|
392
424
|
if (matches && matches.length >= 1) {
|
|
@@ -461,31 +493,60 @@ const placeholderContent = (source, file) => {
|
|
|
461
493
|
// ───────────────────────────────────────────────────────────────────────
|
|
462
494
|
// 15. fetch call without .catch / try/catch nearby
|
|
463
495
|
// ───────────────────────────────────────────────────────────────────────
|
|
464
|
-
const unhandledFetch = (source, file) => {
|
|
496
|
+
const unhandledFetch = (source, file, ast) => {
|
|
465
497
|
const out = [];
|
|
466
498
|
if (!/\.(tsx|jsx|ts|js)$/.test(file))
|
|
467
499
|
return out;
|
|
500
|
+
if (isToolingPath(file) || /(^|\/)scripts\//.test(file))
|
|
501
|
+
return out;
|
|
502
|
+
const push = (line) => {
|
|
503
|
+
if (out.length)
|
|
504
|
+
return;
|
|
505
|
+
out.push(mkFinding({
|
|
506
|
+
id: "unhandled-fetch",
|
|
507
|
+
category: "Runtime Stability",
|
|
508
|
+
severity: "high",
|
|
509
|
+
file,
|
|
510
|
+
line,
|
|
511
|
+
message: "fetch call has no visible .catch or try/catch.",
|
|
512
|
+
why: "Network requests fail. Without a catch, the UI silently breaks and the user has no idea why.",
|
|
513
|
+
fix: "Wrap in try/catch (for await) or chain .catch — set an error state and surface a retry path.",
|
|
514
|
+
aiPrompt: `In ${file} near line ${line}, wrap the fetch call in try/catch (or chain .catch), set an error UI state on failure, and offer the user a retry button.`,
|
|
515
|
+
}));
|
|
516
|
+
};
|
|
517
|
+
if (ast) {
|
|
518
|
+
traverse(ast, {
|
|
519
|
+
CallExpression(p) {
|
|
520
|
+
const callee = p.node.callee;
|
|
521
|
+
if (callee.type !== "Identifier" || callee.name !== "fetch")
|
|
522
|
+
return;
|
|
523
|
+
let cur = p;
|
|
524
|
+
while (cur) {
|
|
525
|
+
if (cur.node?.type === "TryStatement")
|
|
526
|
+
return;
|
|
527
|
+
if (cur.node?.type === "CallExpression") {
|
|
528
|
+
const c = cur.node.callee;
|
|
529
|
+
if (c?.type === "MemberExpression" &&
|
|
530
|
+
c.property?.type === "Identifier" &&
|
|
531
|
+
c.property.name === "catch")
|
|
532
|
+
return;
|
|
533
|
+
}
|
|
534
|
+
cur = cur.parentPath;
|
|
535
|
+
}
|
|
536
|
+
push(p.node.loc?.start.line ?? 1);
|
|
537
|
+
},
|
|
538
|
+
});
|
|
539
|
+
return out;
|
|
540
|
+
}
|
|
468
541
|
const re = /\bfetch\s*\(/g;
|
|
469
542
|
let m;
|
|
470
543
|
while ((m = re.exec(source))) {
|
|
471
|
-
|
|
472
|
-
const
|
|
473
|
-
const handled = /\.catch\s*\(
|
|
474
|
-
/try\s*\{/.test(
|
|
475
|
-
if (!handled)
|
|
476
|
-
|
|
477
|
-
id: "unhandled-fetch",
|
|
478
|
-
category: "Runtime Stability",
|
|
479
|
-
severity: "high",
|
|
480
|
-
file,
|
|
481
|
-
line: lineOf(source, m.index),
|
|
482
|
-
message: "fetch call has no visible .catch or try/catch.",
|
|
483
|
-
why: "Network requests fail. Without a catch, the UI silently breaks and the user has no idea why.",
|
|
484
|
-
fix: "Wrap in try/catch (for await) or chain .catch — set an error state and surface a retry path.",
|
|
485
|
-
aiPrompt: `In ${file} near line ${lineOf(source, m.index)}, wrap the fetch call in try/catch (or chain .catch), set an error UI state on failure, and offer the user a retry button.`,
|
|
486
|
-
}));
|
|
487
|
-
return out; // one per file is enough signal
|
|
488
|
-
}
|
|
544
|
+
const before = source.slice(Math.max(0, m.index - 2500), m.index);
|
|
545
|
+
const after = source.slice(m.index, m.index + 400);
|
|
546
|
+
const handled = /\.catch\s*\(/.test(before + after) ||
|
|
547
|
+
/try\s*\{/.test(before);
|
|
548
|
+
if (!handled)
|
|
549
|
+
push(lineOf(source, m.index));
|
|
489
550
|
}
|
|
490
551
|
return out;
|
|
491
552
|
};
|
|
@@ -602,7 +663,9 @@ const idorDataFetch = (source, file) => {
|
|
|
602
663
|
let m;
|
|
603
664
|
while ((m = re.exec(source))) {
|
|
604
665
|
const window = source.slice(Math.max(0, m.index - 50), m.index + 200);
|
|
605
|
-
if (!window.includes(".eq('user_id'") &&
|
|
666
|
+
if (!window.includes(".eq('user_id'") &&
|
|
667
|
+
!window.includes('.eq("user_id"') &&
|
|
668
|
+
!/\.eq\(\s*['"]id['"]\s*,\s*(currentUserId|userId|context\.userId|user\.id|data\.userId)/.test(window)) {
|
|
606
669
|
out.push(mkFinding({
|
|
607
670
|
id: "idor-data-fetch",
|
|
608
671
|
category: "Security",
|
|
@@ -629,6 +692,9 @@ const deadEndPage = (source, file) => {
|
|
|
629
692
|
return out; // Only check route pages
|
|
630
693
|
if (/__root|_layout|\.server/.test(file))
|
|
631
694
|
return out; // Ignore layouts
|
|
695
|
+
// Nested dashboard / admin / auth / device-login routes inherit chrome or are transient.
|
|
696
|
+
if (/\/dashboard\/|_authenticated[/\\]|cli-login|auth\.callback|\/auth\./.test(file))
|
|
697
|
+
return out;
|
|
632
698
|
const isRoute = /createFileRoute|export default function/i.test(source);
|
|
633
699
|
if (!isRoute)
|
|
634
700
|
return out;
|
|
@@ -1057,8 +1123,12 @@ const missingErrorTyping = (source, file, ast) => {
|
|
|
1057
1123
|
const hasGuard = new RegExp(`instanceof\\s+Error|typeof\\s+${errorName}\\s*===?\\s*['"]object['"]|${errorName}\\s+is\\s+|as\\s+Error`).test(catchBodySrc) ||
|
|
1058
1124
|
new RegExp(`\\b${errorName}\\s+instanceof\\b`).test(catchBodySrc) ||
|
|
1059
1125
|
/Error\s*\(/.test(catchBodySrc) ||
|
|
1060
|
-
new RegExp(`isError\\s*\\(\\s*${errorName}\\s*\\)`).test(catchBodySrc)
|
|
1061
|
-
|
|
1126
|
+
new RegExp(`isError\\s*\\(\\s*${errorName}\\s*\\)`).test(catchBodySrc) ||
|
|
1127
|
+
new RegExp(`\\b${errorName}\\?\\.(message|code|name|stack)\\b`).test(catchBodySrc) ||
|
|
1128
|
+
new RegExp(`String\\s*\\(\\s*${errorName}\\s*\\)`).test(catchBodySrc);
|
|
1129
|
+
const param = p.node.param;
|
|
1130
|
+
const isExplicitAny = param.typeAnnotation?.typeAnnotation?.type === "TSAnyKeyword";
|
|
1131
|
+
if (!hasGuard && !isExplicitAny) {
|
|
1062
1132
|
out.push(mkFinding({
|
|
1063
1133
|
id: "missing-error-typing",
|
|
1064
1134
|
category: "Data Integrity",
|
|
@@ -1083,7 +1153,7 @@ const unusedVariablesImports = (source, file, ast) => {
|
|
|
1083
1153
|
const out = [];
|
|
1084
1154
|
if (!ast || !/\.(tsx|jsx|ts|js|mjs|cjs)$/.test(file))
|
|
1085
1155
|
return out;
|
|
1086
|
-
if (/\.d\.ts$/.test(file))
|
|
1156
|
+
if (/\.d\.ts$/.test(file) || isToolingPath(file))
|
|
1087
1157
|
return out;
|
|
1088
1158
|
traverse(ast, {
|
|
1089
1159
|
Program(p) {
|
|
@@ -1167,6 +1237,9 @@ const emptyLinkText = (source, file, ast) => {
|
|
|
1167
1237
|
(a.name.name === "aria-label" || a.name.name === "aria-labelledby"));
|
|
1168
1238
|
if (hasAriaLabel)
|
|
1169
1239
|
return;
|
|
1240
|
+
const hasSpread = p.node.attributes.some((a) => a.type === "JSXSpreadAttribute");
|
|
1241
|
+
if (hasSpread)
|
|
1242
|
+
return;
|
|
1170
1243
|
const parent = p.parentPath.node;
|
|
1171
1244
|
if (parent.type !== "JSXElement")
|
|
1172
1245
|
return;
|
|
@@ -23,11 +23,10 @@ async function readMaybe(p) {
|
|
|
23
23
|
function isMarketingRoute(rel) {
|
|
24
24
|
if (!/routes\//.test(rel))
|
|
25
25
|
return false;
|
|
26
|
-
if (/_authenticated|admin|dashboard|api
|
|
26
|
+
if (/_authenticated|admin|dashboard|api\/|auth\.|cli-login|callback/.test(rel))
|
|
27
27
|
return false;
|
|
28
|
-
return (/(?:^|\/)index
|
|
29
|
-
/routes\/(?:index|__root)\.(tsx|jsx)$/.test(rel)
|
|
30
|
-
!/_authenticated|admin/.test(rel));
|
|
28
|
+
return (/(?:^|\/)(?:index|about|docs|privacy|terms|reddit)(?:-reddit)?\.(tsx|jsx)$/.test(rel) ||
|
|
29
|
+
/routes\/(?:index|__root|about|docs|privacy|terms|reddit)\.(tsx|jsx)$/.test(rel));
|
|
31
30
|
}
|
|
32
31
|
export const SEO_CHECK_COUNT = 5;
|
|
33
32
|
export async function runSeoChecks(root, files) {
|
package/dist/scanner/walk.js
CHANGED
|
@@ -11,6 +11,12 @@ export async function walk(root, extraIgnores = []) {
|
|
|
11
11
|
"!**/*.d.ts",
|
|
12
12
|
"!**/routeTree.gen.*",
|
|
13
13
|
"!**/packages/cli/**", // never scan the scanner itself
|
|
14
|
+
"!**/scripts/**",
|
|
15
|
+
"!**/test.js",
|
|
16
|
+
"!**/test2.js",
|
|
17
|
+
"!**/test-server.js",
|
|
18
|
+
"!**/fix-*.mjs",
|
|
19
|
+
"!**/*.{test,spec}.{ts,tsx,js,jsx,mjs,cjs}",
|
|
14
20
|
];
|
|
15
21
|
// Cloud policy ignores: normalize to negated globs
|
|
16
22
|
const cloudIgnoreGlobs = extraIgnores.map((ig) => (ig.startsWith("!") ? ig : `!${ig}`));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "periderm-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.72",
|
|
4
4
|
"description": "Periderm CLI: A pre-launch checklist to catch user-losing bugs, legal liabilities, revenue leaks, runaway cloud bills and so many more before you ship.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"preferGlobal": true,
|