loadwise 0.7.0 → 0.8.0
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/README.md +23 -15
- package/dist/bin/loadwise.js +12 -24
- package/dist/lib/accessibility/analyze.js +5 -3
- package/dist/lib/accessibility/angular-inline.js +9 -11
- package/dist/lib/accessibility/angular-literal.js +39 -0
- package/dist/lib/accessibility/form-context.js +36 -0
- package/dist/lib/accessibility/frame-head.js +92 -0
- package/dist/lib/accessibility/frame-viewport.js +149 -0
- package/dist/lib/accessibility/jsx-elements.js +13 -3
- package/dist/lib/accessibility/markup-files.js +7 -2
- package/dist/lib/accessibility/rule-ids.js +3 -0
- package/dist/lib/accessibility/rules.js +128 -41
- package/dist/lib/accessibility/site-fixes/buttons.js +5 -1
- package/dist/lib/accessibility/template-attributes.js +5 -3
- package/dist/lib/accessibility/template-elements.js +25 -6
- package/dist/lib/accessibility/template-file.js +40 -25
- package/dist/lib/editor/accessibility-examples.js +6 -1
- package/dist/lib/editor/actions.js +46 -7
- package/dist/lib/editor/apply-fix.js +69 -4
- package/dist/lib/editor/configured-setup.js +5 -3
- package/dist/lib/editor/diagnostics.js +206 -17
- package/dist/lib/editor/dismissals.js +85 -26
- package/dist/lib/editor/editor-document.js +5 -2
- package/dist/lib/editor/editor-launcher.js +7 -2
- package/dist/lib/editor/language-server.js +64 -25
- package/dist/lib/editor/native-setup.js +3 -2
- package/dist/lib/editor/perf-watch.js +8 -6
- package/dist/lib/editor/reliability-examples.js +15 -0
- package/dist/lib/editor/scan-session.js +29 -8
- package/dist/lib/editor/server-commands.js +36 -9
- package/dist/lib/editor/setup-server.js +1 -1
- package/dist/lib/editor/setup-vim.js +6 -4
- package/dist/lib/editor/workspace-files.js +61 -7
- package/dist/lib/editor/workspace-paths.js +41 -1
- package/dist/lib/maintainability/analysis/analyze-source.js +1 -1
- package/dist/lib/maintainability/architecture/architecture.js +4 -4
- package/dist/lib/maintainability/cli/changed-lines.js +20 -2
- package/dist/lib/maintainability/cli/inputs.js +9 -1
- package/dist/lib/maintainability/cli.js +4 -0
- package/dist/lib/maintainability/entry-points/entry-points.js +44 -15
- package/dist/lib/maintainability/entry-points/html-entry-points.js +5 -1
- package/dist/lib/maintainability/quality/functions.js +9 -6
- package/dist/lib/maintainability/quality/limits.js +19 -0
- package/dist/lib/maintainability/quality/size-limits.js +8 -2
- package/dist/lib/maintainability/quality/stray-console.js +62 -1
- package/dist/lib/maintainability/quality/tsconfig-strict.js +2 -0
- package/dist/lib/maintainability/scan-changed.js +4 -1
- package/dist/lib/maintainability/scan-worker.js +6 -2
- package/dist/lib/maintainability/scan.js +21 -8
- package/dist/lib/maintainability/unused/module-usage.js +43 -21
- package/dist/lib/maintainability/unused/unused-modules.js +5 -10
- package/dist/lib/performance/analysis/source-inputs.js +7 -2
- package/dist/lib/performance/analysis/source-options.js +7 -6
- package/dist/lib/performance/analyze.js +16 -3
- package/dist/lib/performance/cli/cli-output.js +1 -0
- package/dist/lib/performance/cli/cli-scan.js +21 -2
- package/dist/lib/performance/cli.js +8 -3
- package/dist/lib/performance/collections/memory-growth.js +55 -12
- package/dist/lib/performance/contracts/openapi.js +13 -4
- package/dist/lib/performance/datastores/pg-integrity.js +61 -22
- package/dist/lib/performance/datastores/pg-session-release.js +114 -0
- package/dist/lib/performance/datastores/pg-session-sql.js +144 -0
- package/dist/lib/performance/datastores/pooling.js +56 -2
- package/dist/lib/performance/datastores/redis.js +94 -18
- package/dist/lib/performance/datastores/session-store.js +2 -1
- package/dist/lib/performance/db/checks.js +19 -8
- package/dist/lib/performance/db/gateway.js +3 -1
- package/dist/lib/performance/db/plan-estimates.js +4 -4
- package/dist/lib/performance/engine/native.js +11 -7
- package/dist/lib/performance/evidence/plans.js +7 -5
- package/dist/lib/performance/evidence/traces.js +21 -1
- package/dist/lib/performance/frontend/angular-teardown.js +96 -0
- package/dist/lib/performance/frontend/effect-cleanup.js +148 -0
- package/dist/lib/performance/frontend/frontend-dom-perf.js +14 -2
- package/dist/lib/performance/frontend/frontend-helpers.js +1 -9
- package/dist/lib/performance/frontend/frontend-perf.js +72 -57
- package/dist/lib/performance/migrations/extract-code-sql.js +16 -4
- package/dist/lib/performance/migrations/extract-code.js +13 -5
- package/dist/lib/performance/migrations/extract-sql.js +82 -38
- package/dist/lib/performance/migrations/operations.js +56 -13
- package/dist/lib/performance/migrations/postgres-lock-timeout.js +52 -0
- package/dist/lib/performance/migrations/postgres-registry.js +127 -26
- package/dist/lib/performance/migrations/postgres-settings.js +78 -0
- package/dist/lib/performance/migrations/rules-postgres-add-column.js +3 -3
- package/dist/lib/performance/migrations/rules-postgres-shared.js +9 -0
- package/dist/lib/performance/migrations/rules-postgres.js +88 -39
- package/dist/lib/performance/orm/offset-pagination.js +6 -4
- package/dist/lib/performance/orm/prisma-aggregates.js +69 -18
- package/dist/lib/performance/orm/unbounded-list-chain.js +29 -0
- package/dist/lib/performance/orm/unbounded-list-queries.js +18 -13
- package/dist/lib/performance/polyglot.js +111 -14
- package/dist/lib/performance/projects.js +3 -3
- package/dist/lib/performance/query-loops/sequential-loops.js +1 -0
- package/dist/lib/performance/request/backend-mastery.js +151 -42
- package/dist/lib/performance/request/mongoose-lean.js +175 -10
- package/dist/lib/performance/request/phase5-rules.js +74 -13
- package/dist/lib/performance/request/sql-select-star.js +150 -0
- package/dist/lib/performance/request/unbounded-promise-all.js +54 -29
- package/dist/lib/performance/request/upload-limits.js +5 -1
- package/dist/lib/performance/site-fix.js +4 -4
- package/dist/lib/performance/site-fixes/backend-mastery-fixes.js +298 -16
- package/dist/lib/performance/site-fixes/frontend-fixes.js +350 -10
- package/dist/lib/performance/site-fixes/migration-context.js +8 -1
- package/dist/lib/performance/site-fixes/migration-lock-rules.js +66 -30
- package/dist/lib/performance/site-fixes/prisma-aggregates.js +29 -9
- package/dist/lib/performance/site-fixes/small-rewrites.js +168 -10
- package/dist/lib/performance/site-fixes/sync-calls.js +14 -12
- package/dist/lib/performance/site-fixes/upload-limits.js +13 -7
- package/dist/lib/performance/sql/mysql-tokens.js +38 -12
- package/dist/lib/reliability/boundary-access.js +114 -57
- package/dist/lib/reliability/react-bugs.js +18 -4
- package/dist/lib/reliability/resource-leak-intervals.js +258 -0
- package/dist/lib/reliability/resource-leaks.js +209 -195
- package/dist/lib/reliability/rule-ids.js +10 -1
- package/dist/lib/reliability/site-fixes/resource-leaks.js +16 -1
- package/dist/lib/reliability/swallowed-errors.js +107 -21
- package/dist/lib/reliability/test-cleanup-after-await.js +92 -18
- package/dist/lib/reliability/walk.js +3 -2
- package/dist/lib/security/auth-crypto/hashing.js +24 -8
- package/dist/lib/security/auth-crypto/jwt.js +21 -6
- package/dist/lib/security/auth-crypto/secrets.js +44 -1
- package/dist/lib/security/auth-crypto/shared.js +3 -1
- package/dist/lib/security/auth-crypto/signing-algorithm.js +79 -0
- package/dist/lib/security/auth-crypto/transport-and-ciphers.js +85 -1
- package/dist/lib/security/cli.js +6 -2
- package/dist/lib/security/cookie-credentials.js +115 -0
- package/dist/lib/security/cookie-csrf.js +241 -0
- package/dist/lib/security/deps/advisory.js +50 -109
- package/dist/lib/security/deps/cli.js +1 -1
- package/dist/lib/security/deps/cvss-score.js +14 -0
- package/dist/lib/security/deps/fixed-version.js +97 -0
- package/dist/lib/security/deps/lockfiles.js +135 -74
- package/dist/lib/security/deps/osv.js +11 -3
- package/dist/lib/security/deps/scan.js +47 -20
- package/dist/lib/security/deps/yarn-lock.js +158 -0
- package/dist/lib/security/examples/injection.cjs +4 -0
- package/dist/lib/security/exposure/cookies.js +17 -2
- package/dist/lib/security/exposure/cors-origin-regex.js +2 -3
- package/dist/lib/security/exposure/frontend-security.js +21 -14
- package/dist/lib/security/exposure/jsx-url.js +18 -33
- package/dist/lib/security/exposure/logging.js +49 -10
- package/dist/lib/security/exposure/prototype-pollution.js +126 -56
- package/dist/lib/security/exposure/react-html.js +26 -0
- package/dist/lib/security/exposure/reflected-xss.js +34 -5
- package/dist/lib/security/files/compose.js +126 -1
- package/dist/lib/security/files/dockerfile.js +62 -4
- package/dist/lib/security/files/index.js +1 -1
- package/dist/lib/security/injection/command.js +46 -18
- package/dist/lib/security/injection/index.js +2 -0
- package/dist/lib/security/injection/ldap.js +86 -0
- package/dist/lib/security/injection/nosql.js +28 -4
- package/dist/lib/security/injection/redos.js +1 -1
- package/dist/lib/security/injection/rule-ids.js +1 -0
- package/dist/lib/security/injection/shared.js +5 -1
- package/dist/lib/security/injection/sql.js +28 -13
- package/dist/lib/security/lexical-declaration.js +113 -0
- package/dist/lib/security/pg-dynamic-query.js +28 -1
- package/dist/lib/security/pg-identifier-guards.js +107 -3
- package/dist/lib/security/phase5-rules.js +26 -135
- package/dist/lib/security/polyglot.js +2 -2
- package/dist/lib/security/redirect-settings.js +98 -0
- package/dist/lib/security/request-forgery/open-redirect.js +18 -5
- package/dist/lib/security/request-forgery/path-traversal.js +84 -6
- package/dist/lib/security/request-forgery/shared.js +1 -7
- package/dist/lib/security/request-forgery/ssrf.js +176 -14
- package/dist/lib/security/rule-descriptions.js +5 -1
- package/dist/lib/security/rule-ids.js +7 -0
- package/dist/lib/security/site-fixes/auth-crypto.js +5 -78
- package/dist/lib/security/site-fixes/exposure.js +21 -3
- package/dist/lib/security/site-fixes/files.js +11 -13
- package/dist/lib/security/site-fixes/frontend-security-fixes.js +2 -2
- package/dist/lib/security/site-fixes/injection.js +17 -4
- package/dist/lib/security/site-fixes/jwt.js +1 -20
- package/dist/lib/security/site-fixes/request-forgery.js +37 -29
- package/dist/lib/security/taint/binding-inputs.js +236 -0
- package/dist/lib/security/taint/filename-guard.js +45 -45
- package/dist/lib/security/taint/guards.js +14 -8
- package/dist/lib/security/taint/index.js +126 -154
- package/dist/lib/security/taint/propagate.js +43 -9
- package/dist/lib/security/taint/record-writes.js +161 -0
- package/dist/lib/security/taint/resolution-cache.js +13 -7
- package/dist/lib/security/taint/sanitizers.js +89 -5
- package/dist/lib/security/taint/trace-nodes.js +61 -0
- package/dist/lib/security/taint/validators.js +89 -9
- package/dist/lib/shared/agent/agent-init.js +2 -1
- package/dist/lib/shared/agent/agent-verify.js +4 -1
- package/dist/lib/shared/agent/git-hook.js +17 -6
- package/dist/lib/shared/agent/review-mcp.js +8 -2
- package/dist/lib/shared/analysis/ast-semantics.js +2 -2
- package/dist/lib/shared/analysis/scan-cache.js +96 -12
- package/dist/lib/shared/cli-dispatch.js +17 -0
- package/dist/lib/shared/config.js +27 -10
- package/dist/lib/shared/explain.js +1 -1
- package/dist/lib/shared/fix/fix-convergence.js +5 -3
- package/dist/lib/shared/fix/fix-imports.js +4 -171
- package/dist/lib/shared/fix/fix-presentation-comments.js +23 -9
- package/dist/lib/shared/fix/fix-presentation.js +5 -3
- package/dist/lib/shared/fix/fix-safety.js +7 -1
- package/dist/lib/shared/fix/fix-typecheck.js +8 -4
- package/dist/lib/shared/fix/import-text-edits.js +148 -0
- package/dist/lib/shared/fix.js +31 -7
- package/dist/lib/shared/formats/finding-location.js +4 -1
- package/dist/lib/shared/formats/github.js +3 -3
- package/dist/lib/shared/formats/sarif.js +9 -3
- package/dist/lib/shared/report-fp.js +6 -2
- package/dist/lib/shared/reporting/baseline.js +7 -5
- package/dist/lib/shared/reporting/pillars.js +9 -3
- package/dist/lib/shared/reporting/source-report.js +1 -0
- package/dist/lib/shared/system/glob.js +34 -8
- package/dist/lib/shared/system/sentry.js +26 -7
- package/dist/lib/shared/workspaces.js +15 -3
- package/package.json +5 -1
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/hooks/check-edited-file.mjs +27 -5
- package/polyglot/performance/rules/csharp.yml +34 -5
- package/polyglot/performance/rules/java.yml +24 -1
- package/polyglot/performance/rules/python.yml +74 -2
- package/polyglot/performance/sgconfig.yml +1 -0
- package/polyglot/reliability/rules/csharp.yml +12 -6
- package/polyglot/reliability/rules/go.yml +86 -6
- package/polyglot/reliability/rules/java.yml +22 -1
- package/polyglot/reliability/sgconfig.yml +1 -0
- package/polyglot/security/rules/go.yml +100 -22
- package/polyglot/security/rules/python.yml +74 -6
- package/polyglot/security/rules/rust.yml +65 -0
- package/polyglot/security/sgconfig.yml +1 -0
- package/schema/loadwise.config.schema.json +554 -76
- /package/polyglot/{performance/rules → shared-rules}/input.yml +0 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import * as ts from 'typescript';
|
|
2
|
+
function parseImportStatement(statement) {
|
|
3
|
+
if (!ts.isStringLiteral(statement.moduleSpecifier))
|
|
4
|
+
return;
|
|
5
|
+
const moduleSpecifier = statement.moduleSpecifier.text;
|
|
6
|
+
const clause = statement.importClause;
|
|
7
|
+
// Leave declarations with attributes, comments, or a nonstandard phase intact. Only declarations represented losslessly
|
|
8
|
+
// below may be formatted again.
|
|
9
|
+
if (!clause || statement.attributes || statement.modifiers?.length || /\/[/*]/.test(statement.getText()))
|
|
10
|
+
return;
|
|
11
|
+
if (clause.phaseModifier !== undefined && clause.phaseModifier !== ts.SyntaxKind.TypeKeyword)
|
|
12
|
+
return;
|
|
13
|
+
const isTypeOnly = Boolean(clause.isTypeOnly);
|
|
14
|
+
const defaultName = clause.name?.text;
|
|
15
|
+
const named = [];
|
|
16
|
+
let namespaceName;
|
|
17
|
+
if (clause.namedBindings) {
|
|
18
|
+
if (ts.isNamespaceImport(clause.namedBindings)) {
|
|
19
|
+
namespaceName = clause.namedBindings.name.text;
|
|
20
|
+
}
|
|
21
|
+
else if (ts.isNamedImports(clause.namedBindings)) {
|
|
22
|
+
for (const element of clause.namedBindings.elements) {
|
|
23
|
+
const imported = element.propertyName
|
|
24
|
+
? `${element.propertyName.getText()} as ${element.name.text}`
|
|
25
|
+
: element.name.text;
|
|
26
|
+
named.push((element.isTypeOnly ? 'type ' : '') + imported);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return { moduleSpecifier, named, defaultName, namespaceName, isTypeOnly };
|
|
31
|
+
}
|
|
32
|
+
function formatImport(entry) {
|
|
33
|
+
const prefix = entry.isTypeOnly ? 'import type ' : 'import ';
|
|
34
|
+
const literal = /^[\w@./#:-]+$/.test(entry.moduleSpecifier)
|
|
35
|
+
? `'${entry.moduleSpecifier}'`
|
|
36
|
+
: JSON.stringify(entry.moduleSpecifier);
|
|
37
|
+
const parts = [];
|
|
38
|
+
if (entry.defaultName)
|
|
39
|
+
parts.push(entry.defaultName);
|
|
40
|
+
if (entry.namespaceName)
|
|
41
|
+
parts.push(`* as ${entry.namespaceName}`);
|
|
42
|
+
if (entry.named.length)
|
|
43
|
+
parts.push(`{ ${[...new Set(entry.named)].join(', ')} }`);
|
|
44
|
+
if (!parts.length)
|
|
45
|
+
return `${prefix}${literal};`;
|
|
46
|
+
return `${prefix}${parts.join(', ')} from ${literal};`;
|
|
47
|
+
}
|
|
48
|
+
function acceptsImportEdit(target, edit) {
|
|
49
|
+
if (target.moduleSpecifier !== edit.moduleSpecifier || target.isTypeOnly !== Boolean(edit.isTypeOnly))
|
|
50
|
+
return false;
|
|
51
|
+
if (target.defaultName && edit.defaultName && target.defaultName !== edit.defaultName)
|
|
52
|
+
return false;
|
|
53
|
+
if (target.namespaceName && edit.namespaceName && target.namespaceName !== edit.namespaceName)
|
|
54
|
+
return false;
|
|
55
|
+
const hasNamed = target.named.length || edit.named?.length;
|
|
56
|
+
const hasNamespace = target.namespaceName || edit.namespaceName;
|
|
57
|
+
if (hasNamed && hasNamespace)
|
|
58
|
+
return false;
|
|
59
|
+
return !(target.isTypeOnly && (target.defaultName || edit.defaultName) && (hasNamed || hasNamespace));
|
|
60
|
+
}
|
|
61
|
+
function mergeEditIntoParsed(target, edit) {
|
|
62
|
+
if (edit.defaultName && !target.defaultName)
|
|
63
|
+
target.defaultName = edit.defaultName;
|
|
64
|
+
if (edit.namespaceName && !target.namespaceName)
|
|
65
|
+
target.namespaceName = edit.namespaceName;
|
|
66
|
+
if (edit.named?.length)
|
|
67
|
+
target.named.push(...edit.named);
|
|
68
|
+
}
|
|
69
|
+
function newImportInsertion(text, source, existingImports, lines) {
|
|
70
|
+
const joined = lines.join('\n');
|
|
71
|
+
if (existingImports.length) {
|
|
72
|
+
const last = existingImports[existingImports.length - 1];
|
|
73
|
+
return { start: last.getEnd(), text: `\n${joined}` };
|
|
74
|
+
}
|
|
75
|
+
let lastDirective;
|
|
76
|
+
for (const stmt of source.statements) {
|
|
77
|
+
if (!ts.isExpressionStatement(stmt) || !ts.isStringLiteralLike(stmt.expression))
|
|
78
|
+
break;
|
|
79
|
+
lastDirective = stmt;
|
|
80
|
+
}
|
|
81
|
+
if (lastDirective) {
|
|
82
|
+
return { start: lastDirective.getEnd(), text: `\n${joined}` };
|
|
83
|
+
}
|
|
84
|
+
const shebang = /^#![^\n]*\r?\n/.exec(text);
|
|
85
|
+
if (shebang) {
|
|
86
|
+
return { start: shebang[0].length, text: `${joined}\n` };
|
|
87
|
+
}
|
|
88
|
+
return { start: 0, text: `${joined}\n` };
|
|
89
|
+
}
|
|
90
|
+
export function importTextEdits(text, edits, fileName) {
|
|
91
|
+
if (!edits.length)
|
|
92
|
+
return [];
|
|
93
|
+
const source = ts.createSourceFile(fileName, text, ts.ScriptTarget.Latest, true);
|
|
94
|
+
const existingImports = source.statements.filter(ts.isImportDeclaration);
|
|
95
|
+
const matchedReplacements = new Map();
|
|
96
|
+
const parsedImports = existingImports.map((declaration) => ({
|
|
97
|
+
declaration,
|
|
98
|
+
parsed: parseImportStatement(declaration),
|
|
99
|
+
}));
|
|
100
|
+
const newImports = [];
|
|
101
|
+
for (const edit of edits) {
|
|
102
|
+
const match = parsedImports.find(({ parsed }) => parsed && acceptsImportEdit(parsed, edit));
|
|
103
|
+
if (match?.parsed) {
|
|
104
|
+
mergeEditIntoParsed(match.parsed, edit);
|
|
105
|
+
matchedReplacements.set(match.declaration, match.parsed);
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
// Import attributes affect module loading. A plain requested import cannot safely inherit or omit them.
|
|
109
|
+
if (existingImports.some((declaration) => declaration.attributes &&
|
|
110
|
+
ts.isStringLiteral(declaration.moduleSpecifier) &&
|
|
111
|
+
declaration.moduleSpecifier.text === edit.moduleSpecifier))
|
|
112
|
+
throw new Error(`Cannot combine a generated import with import attributes for ${edit.moduleSpecifier}. No fixes applied.`);
|
|
113
|
+
let current = newImports.find((entry) => acceptsImportEdit(entry, edit));
|
|
114
|
+
if (!current) {
|
|
115
|
+
current = { moduleSpecifier: edit.moduleSpecifier, named: [], isTypeOnly: Boolean(edit.isTypeOnly) };
|
|
116
|
+
newImports.push(current);
|
|
117
|
+
}
|
|
118
|
+
mergeEditIntoParsed(current, edit);
|
|
119
|
+
}
|
|
120
|
+
const textEdits = [...matchedReplacements.entries()].map(([decl, parsed]) => ({
|
|
121
|
+
start: decl.getStart(source),
|
|
122
|
+
end: decl.getEnd(),
|
|
123
|
+
text: formatImport(parsed),
|
|
124
|
+
}));
|
|
125
|
+
if (newImports.length) {
|
|
126
|
+
const insertion = newImportInsertion(text, source, existingImports, newImports.map(formatImport));
|
|
127
|
+
textEdits.push({ start: insertion.start, end: insertion.start, text: insertion.text });
|
|
128
|
+
}
|
|
129
|
+
return textEdits.filter((edit) => text.slice(edit.start, edit.end) !== edit.text);
|
|
130
|
+
}
|
|
131
|
+
export function parsePureImportBlock(text) {
|
|
132
|
+
const trimmed = text.trim();
|
|
133
|
+
if (!trimmed)
|
|
134
|
+
return undefined;
|
|
135
|
+
const source = ts.createSourceFile('import-edit.ts', trimmed, ts.ScriptTarget.Latest, true);
|
|
136
|
+
if (source.parseDiagnostics?.length || !source.statements.length)
|
|
137
|
+
return undefined;
|
|
138
|
+
const edits = [];
|
|
139
|
+
for (const statement of source.statements) {
|
|
140
|
+
if (!ts.isImportDeclaration(statement))
|
|
141
|
+
return undefined;
|
|
142
|
+
const parsed = parseImportStatement(statement);
|
|
143
|
+
if (!parsed)
|
|
144
|
+
return undefined;
|
|
145
|
+
edits.push(parsed);
|
|
146
|
+
}
|
|
147
|
+
return edits;
|
|
148
|
+
}
|
package/dist/lib/shared/fix.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { registeredRuleIds } from './reporting/pillar-rules.js';
|
|
1
2
|
import fs from 'node:fs';
|
|
2
3
|
import { fixScopeGuard } from './fix/fix-scope.js';
|
|
3
4
|
import path from 'node:path';
|
|
@@ -52,6 +53,7 @@ function parseFixArgs(args) {
|
|
|
52
53
|
allowPositionals: true,
|
|
53
54
|
tokens: true,
|
|
54
55
|
options: {
|
|
56
|
+
help: { type: 'boolean', short: 'h' },
|
|
55
57
|
config: { type: 'string' },
|
|
56
58
|
workspace: { type: 'string', multiple: true, default: [] },
|
|
57
59
|
staged: { type: 'boolean' },
|
|
@@ -78,8 +80,17 @@ function parseFixArgs(args) {
|
|
|
78
80
|
function fixTarget(values, positionals) {
|
|
79
81
|
const selected = new Set();
|
|
80
82
|
const checkerFor = (selector) => pillars.find(({ name, jsonKey }) => selector === name || selector === jsonKey);
|
|
81
|
-
const directoryOperands = positionals.filter((value) =>
|
|
82
|
-
|
|
83
|
+
const directoryOperands = positionals.filter((value) => {
|
|
84
|
+
if (value.split(',').every((item) => checkerFor(item.trim())))
|
|
85
|
+
return false;
|
|
86
|
+
const target = fs.statSync(value, { throwIfNoEntry: false });
|
|
87
|
+
if (target?.isDirectory())
|
|
88
|
+
return true;
|
|
89
|
+
if (target || path.isAbsolute(value) || value.includes('/') || value.includes(path.sep)) {
|
|
90
|
+
throw new Error(`Project directory "${value}" ${target ? 'is not a directory' : 'does not exist'}.`);
|
|
91
|
+
}
|
|
92
|
+
return false;
|
|
93
|
+
});
|
|
83
94
|
if (directoryOperands.length > 1)
|
|
84
95
|
throw new Error('fix accepts at most one project directory.');
|
|
85
96
|
const directory = path.resolve(directoryOperands[0] ?? '.');
|
|
@@ -111,8 +122,7 @@ function fixTarget(values, positionals) {
|
|
|
111
122
|
selected: selected.size ? [...selected] : undefined,
|
|
112
123
|
};
|
|
113
124
|
}
|
|
114
|
-
function fixOptions(args) {
|
|
115
|
-
const { values, positionals, tokens } = parseFixArgs(args);
|
|
125
|
+
function fixOptions(args, { values, positionals, tokens }) {
|
|
116
126
|
const applyAutomatic = values.apply || values.yes;
|
|
117
127
|
if (values.handoff && (applyAutomatic || values.all || values.recipe !== undefined))
|
|
118
128
|
throw new Error('--handoff is read-only. Use it separately from --apply, --yes, --all and --recipe.');
|
|
@@ -134,6 +144,12 @@ function fixOptions(args) {
|
|
|
134
144
|
const rules = (values.rule ?? []).flatMap((entry) => entry.split(',').map((rule) => rule.trim()));
|
|
135
145
|
if (rules.includes(''))
|
|
136
146
|
throw new Error('--rule must be a nonempty rule ID for each selection.');
|
|
147
|
+
if (rules.length) {
|
|
148
|
+
const knownRules = registeredRuleIds();
|
|
149
|
+
const unknown = rules.find((rule) => !knownRules.has(rule));
|
|
150
|
+
if (unknown)
|
|
151
|
+
throw new Error(`Unknown Loadwise rule "${unknown}" in --rule.`);
|
|
152
|
+
}
|
|
137
153
|
// Remove mode flags by token index so option values and operands after "--" stay verbatim.
|
|
138
154
|
const modeIndexes = new Set(tokens
|
|
139
155
|
.filter((token) => token.kind === 'option' && ['apply', 'yes', 'dry-run'].includes(token.name))
|
|
@@ -315,11 +331,12 @@ async function prepareFixes(scanned, { recipe, scope, comments, ids }) {
|
|
|
315
331
|
return findings;
|
|
316
332
|
}
|
|
317
333
|
async function runFix(args) {
|
|
318
|
-
|
|
334
|
+
const parsed = parseFixArgs(args);
|
|
335
|
+
if (parsed.values.help) {
|
|
319
336
|
console.log(usage);
|
|
320
337
|
return 0;
|
|
321
338
|
}
|
|
322
|
-
const options = fixOptions(args);
|
|
339
|
+
const options = fixOptions(args, parsed);
|
|
323
340
|
const { selected, includeReview, dryRun, applyCommand, ids, rules, handoff, json, requestReview, format, verifyTypes, scope, scopeArgs, } = options;
|
|
324
341
|
const action = dryRun ? 'Previewing fixes' : 'Applying fixes';
|
|
325
342
|
const scannedAll = await scanForFixes(selected, scopeArgs, json || handoff ? undefined : action);
|
|
@@ -352,7 +369,14 @@ async function runFix(args) {
|
|
|
352
369
|
? `To apply these fixes, run:\n${applyCommand}`
|
|
353
370
|
: 'No proposed edits to apply.'
|
|
354
371
|
: fixInstructions(findings.length, selected, manual.length, scopeArgs, rules);
|
|
355
|
-
const notApplied = refused.map(({ finding, reason }) => ({
|
|
372
|
+
const notApplied = refused.map(({ finding, reason }) => ({
|
|
373
|
+
checker: finding.checker,
|
|
374
|
+
id: finding.id,
|
|
375
|
+
ruleId: finding.ruleId,
|
|
376
|
+
...(finding.file && { file: finding.file }),
|
|
377
|
+
...(finding.line !== undefined && { line: finding.line }),
|
|
378
|
+
reason,
|
|
379
|
+
}));
|
|
356
380
|
const report = { changedFiles, dryRun, applied, manual, pendingReview, notApplied, instructions };
|
|
357
381
|
if (requestReview && !dryRun)
|
|
358
382
|
await writeReviewHandoff(scope.directory, 'fix', {
|
|
@@ -32,4 +32,7 @@ function repositoryPathFor(findingRoot, repositoryDirectory = findingRoot) {
|
|
|
32
32
|
.split(path.sep)
|
|
33
33
|
.join('/');
|
|
34
34
|
}
|
|
35
|
-
|
|
35
|
+
function positivePosition(value) {
|
|
36
|
+
return typeof value === 'number' && Number.isFinite(value) && value >= 1 ? Math.trunc(value) : 1;
|
|
37
|
+
}
|
|
38
|
+
export { findingLevel, findRepositoryRoot, positivePosition, repositoryPathFor };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { findingLevel, repositoryPathFor } from './finding-location.js';
|
|
1
|
+
import { findingLevel, positivePosition, repositoryPathFor } from './finding-location.js';
|
|
2
2
|
// GitHub workflow commands: the message escapes % and line breaks, and properties also escape : and
|
|
3
3
|
// ,.
|
|
4
4
|
const commandNames = { error: 'error', warning: 'warning', note: 'notice' };
|
|
@@ -11,8 +11,8 @@ function escapeProperty(text) {
|
|
|
11
11
|
function annotation(pillar, repositoryPath, finding) {
|
|
12
12
|
const properties = [
|
|
13
13
|
`file=${escapeProperty(repositoryPath(finding.file))}`,
|
|
14
|
-
`line=${finding.line
|
|
15
|
-
`col=${finding.column
|
|
14
|
+
`line=${positivePosition(finding.line)}`,
|
|
15
|
+
`col=${positivePosition(finding.column)}`,
|
|
16
16
|
`title=${escapeProperty(finding.ruleId)}`,
|
|
17
17
|
];
|
|
18
18
|
return `::${commandNames[findingLevel(pillar, finding)]} ${properties.join(',')}::${escapeData(finding.message)}`;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
1
2
|
import { packageManifest } from '../package-root.js';
|
|
2
3
|
const { version: toolVersion } = packageManifest;
|
|
3
|
-
import { findingLevel, repositoryPathFor } from './finding-location.js';
|
|
4
|
+
import { findingLevel, positivePosition, repositoryPathFor } from './finding-location.js';
|
|
4
5
|
import { rulesByPillar } from '../rule-registry.js';
|
|
5
6
|
import { repositoryUrl, ruleDocUrl } from '../reporting/rule-docs.js';
|
|
6
7
|
const sarifSchema = 'https://json.schemastore.org/sarif-2.1.0.json';
|
|
@@ -34,7 +35,7 @@ function resultFor(pillar, repositoryPath, finding) {
|
|
|
34
35
|
{
|
|
35
36
|
physicalLocation: {
|
|
36
37
|
artifactLocation: { uri, uriBaseId: sourceRootId },
|
|
37
|
-
region: { startLine: finding.line
|
|
38
|
+
region: { startLine: positivePosition(finding.line), startColumn: positivePosition(finding.column) },
|
|
38
39
|
},
|
|
39
40
|
},
|
|
40
41
|
],
|
|
@@ -65,6 +66,11 @@ function invocationsFor(repositoryPath, skippedFiles) {
|
|
|
65
66
|
function runFor({ pillar, root, repositoryDirectory, report }) {
|
|
66
67
|
const findings = report.findings;
|
|
67
68
|
const repositoryPath = repositoryPathFor(root, repositoryDirectory);
|
|
69
|
+
// Findings can be relative to the caller's cwd even when this scan only covers a package.
|
|
70
|
+
const scope = repositoryPath(path.resolve(repositoryDirectory ?? root));
|
|
71
|
+
const category = scope
|
|
72
|
+
? `loadwise/${pillar}/${scope.split('/').map(encodeURIComponent).join('/')}/`
|
|
73
|
+
: `loadwise/${pillar}/`;
|
|
68
74
|
return {
|
|
69
75
|
tool: {
|
|
70
76
|
driver: {
|
|
@@ -74,7 +80,7 @@ function runFor({ pillar, root, repositoryDirectory, report }) {
|
|
|
74
80
|
rules: rulesFor(pillar, findings),
|
|
75
81
|
},
|
|
76
82
|
},
|
|
77
|
-
automationDetails: { id:
|
|
83
|
+
automationDetails: { id: category },
|
|
78
84
|
originalUriBaseIds: { [sourceRootId]: { description: { text: 'Root of the checked repository or project.' } } },
|
|
79
85
|
results: findings.map((finding) => resultFor(pillar, repositoryPath, finding)),
|
|
80
86
|
...invocationsFor(repositoryPath, report.skippedFiles),
|
|
@@ -8,7 +8,11 @@ const fpRepoIssuesUrl = 'https://github.com/IbrahimHafez1/loadwise/issues/new';
|
|
|
8
8
|
const fpUsage = 'Usage: loadwise report-fp --rule <rule-id> [--command "<cmd>"] [--expected "<text>"] [--note "<generic reason>"] [--open]';
|
|
9
9
|
/** Redacts local paths, credentialed URLs, tokens, and emails before placing text in an issue URL. */
|
|
10
10
|
function sanitizeFpText(text) {
|
|
11
|
-
return text
|
|
11
|
+
return (text
|
|
12
|
+
// Quoted paths run before the URL rule so a credentialed URL inside one cannot eat the closing quote;
|
|
13
|
+
// In POSIX paths a backslash before the quote is an escaped quote; in Windows paths it is a trailing separator.
|
|
14
|
+
.replaceAll(/(['"`])[A-Za-z]:\\(?:(?!\1)[^\r\n])+\1/g, '$1<redacted-path>$1')
|
|
15
|
+
.replaceAll(/(['"`])\/(?:\\\1|(?!\1)[^\r\n])+\1/g, '$1<redacted-path>$1')
|
|
12
16
|
.replaceAll(/\b(?:postgres|mysql|mongodb|redis|https?):\/\/[^/\s]+@[^\s]+/gi, '<redacted-url>')
|
|
13
17
|
.replaceAll(/\bBearer\s+\S+/gi, 'Bearer <redacted-token>')
|
|
14
18
|
.replaceAll(/\b(?:gh[pousr]_[A-Za-z0-9_]+|github_pat_[A-Za-z0-9_]+|sk-[A-Za-z0-9_-]{8,}|(?:AKIA|ASIA)[0-9A-Z]{16}|xox[baprs]-[A-Za-z0-9-]+|eyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]*)\b/g, '<redacted-token>')
|
|
@@ -19,7 +23,7 @@ function sanitizeFpText(text) {
|
|
|
19
23
|
.replaceAll(/\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/g, '<redacted-email>')
|
|
20
24
|
.replaceAll(/\s+/g, ' ')
|
|
21
25
|
.trim()
|
|
22
|
-
.slice(0, 400);
|
|
26
|
+
.slice(0, 400));
|
|
23
27
|
}
|
|
24
28
|
/** Validates `rule` and constructs a pre-filled `.github/ISSUE_TEMPLATE/false-positive.yml` URL. */
|
|
25
29
|
function buildFpIssueUrl(options) {
|
|
@@ -130,14 +130,16 @@ function createOutsideScan(baselineFile, pillar, scope, projectRoot) {
|
|
|
130
130
|
// Replaces one pillar's section and keeps the others, so pillars can be baselined one at a time.
|
|
131
131
|
// Entries outside a partial scan's scope are kept, so baselining one workspace or rule set leaves
|
|
132
132
|
// the rest recorded.
|
|
133
|
-
function writePillarBaseline(baselineFile, pillar, findings, findingKeys, isOutsideScan) {
|
|
133
|
+
function writePillarBaseline(baselineFile, pillar, findings, findingKeys, { isOutsideScan, skippedFiles }) {
|
|
134
|
+
const document = readDocument(baselineFile);
|
|
135
|
+
if (document && skippedFiles.length && (document.pillars[pillar] || recordedEntries(document, pillar).length))
|
|
136
|
+
throw new Error(`Cannot refresh the ${pillar} baseline because the scan skipped ${skippedFiles[0].file}. Resolve skipped files and retry.`);
|
|
134
137
|
const counts = new Map();
|
|
135
138
|
for (const { key } of findingKeys(findings)) {
|
|
136
139
|
const entry = counts.get(keyText(key)) ?? { ...key, count: 0 };
|
|
137
140
|
entry.count++;
|
|
138
141
|
counts.set(keyText(key), entry);
|
|
139
142
|
}
|
|
140
|
-
const document = readDocument(baselineFile);
|
|
141
143
|
for (const entry of document?.pillars[pillar]?.findings ?? []) {
|
|
142
144
|
if (isOutsideScan(entry) && !counts.has(keyText(entry)))
|
|
143
145
|
counts.set(keyText(entry), entry);
|
|
@@ -195,7 +197,7 @@ function filterPillarBaseline(baselineFile, pillar, findings, findingKeys, parti
|
|
|
195
197
|
// Returns undefined without baseline flags, { written, file } after --write-baseline, or the
|
|
196
198
|
// filtered result.
|
|
197
199
|
// `idRoot` is the folder the finding ids were computed against.
|
|
198
|
-
function applyBaselineOptions({ options, pillar, findings, projectRoot, absoluteFileOf, idRoot, }) {
|
|
200
|
+
function applyBaselineOptions({ options, pillar, findings, skippedFiles = [], projectRoot, absoluteFileOf, idRoot, }) {
|
|
199
201
|
if (options.baseline && options.writeBaseline)
|
|
200
202
|
throw new Error('Choose either --baseline or --write-baseline.');
|
|
201
203
|
const option = options.writeBaseline ?? options.baseline;
|
|
@@ -205,9 +207,9 @@ function applyBaselineOptions({ options, pillar, findings, projectRoot, absolute
|
|
|
205
207
|
const findingKeys = createFindingKeys(file, absoluteFileOf, idRoot);
|
|
206
208
|
if (options.writeBaseline) {
|
|
207
209
|
const isOutsideScan = createOutsideScan(file, pillar, options.scope, projectRoot);
|
|
208
|
-
return { written: writePillarBaseline(file, pillar, findings, findingKeys, isOutsideScan), file };
|
|
210
|
+
return { written: writePillarBaseline(file, pillar, findings, findingKeys, { isOutsideScan, skippedFiles }), file };
|
|
209
211
|
}
|
|
210
|
-
const partialScan = options.partialScan || limitedToPaths(file, options.scope);
|
|
212
|
+
const partialScan = options.partialScan || skippedFiles.length > 0 || limitedToPaths(file, options.scope);
|
|
211
213
|
return filterPillarBaseline(file, pillar, findings, findingKeys, partialScan);
|
|
212
214
|
}
|
|
213
215
|
// `scannedPaths` are the absolute files or folders the scan was limited to, if any.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// The checkers `loadwise check` can run, in report order. Each runs as a child process of the loadwise CLI, so it keeps
|
|
2
2
|
// its own process-wide state and output. A new checker registers by adding one entry here.
|
|
3
|
-
import path from 'node:path';
|
|
4
3
|
import { spawn } from 'node:child_process';
|
|
4
|
+
import { packagePath } from '../package-root.js';
|
|
5
5
|
import { allowedHeapMegabytes, childHeapFlags, isHeapExhaustion } from '../system/heap-limit.js';
|
|
6
6
|
import { configlessSources, coveringConfig, hasWorkspaceSources, missingSourcesDetail, projectConfig, } from '../workspaces.js';
|
|
7
7
|
import { cachedRun, withSharedInputFingerprint } from '../analysis/scan-cache.js';
|
|
@@ -29,7 +29,7 @@ function titleList(names) {
|
|
|
29
29
|
const titles = names.map((name) => pillars.find((pillar) => pillar.name === name)?.title.toLowerCase() ?? name);
|
|
30
30
|
return titles.length < 2 ? titles.join('') : `${titles.slice(0, -1).join(', ')} and ${titles[titles.length - 1]}`;
|
|
31
31
|
}
|
|
32
|
-
const cli =
|
|
32
|
+
const cli = packagePath('dist/bin/loadwise.js');
|
|
33
33
|
const invalidInputCode = 2;
|
|
34
34
|
// An unchanged project replays the stored report; see scan-cache.cjs for what invalidates it.
|
|
35
35
|
function runChecker(args, cwd = process.cwd()) {
|
|
@@ -385,7 +385,13 @@ async function runSharedSourceCheck(shared, options) {
|
|
|
385
385
|
}
|
|
386
386
|
catch {
|
|
387
387
|
return {
|
|
388
|
-
reports: Object.fromEntries(
|
|
388
|
+
reports: Object.fromEntries(shared.map((pillar, index) => {
|
|
389
|
+
const base = index ? { ...failed, stderr: '' } : failed;
|
|
390
|
+
return [
|
|
391
|
+
pillar.jsonKey,
|
|
392
|
+
pillar.name === 'rel' ? mergeContractReport(base, contracts, contractOptions?.contractFlags) : base,
|
|
393
|
+
];
|
|
394
|
+
})),
|
|
389
395
|
};
|
|
390
396
|
}
|
|
391
397
|
// The child's warnings and combined fix signal belong to the run once.
|
|
@@ -62,6 +62,7 @@ async function printResult(result, values, pillar, print = console.log) {
|
|
|
62
62
|
options: values.baselineOptions ?? {},
|
|
63
63
|
pillar: 'security',
|
|
64
64
|
findings: result.findings,
|
|
65
|
+
skippedFiles: result.skippedFiles,
|
|
65
66
|
projectRoot: values.projectDirectory,
|
|
66
67
|
absoluteFileOf: (finding) => path.resolve(finding.file ?? ''),
|
|
67
68
|
idRoot,
|
|
@@ -1,9 +1,35 @@
|
|
|
1
1
|
// One glob dialect for every loadwise pattern (config ignore and overrides, workspace package lists): `*` matches
|
|
2
2
|
// within a folder, `**` any depth, `?` one character and `{a,b}` alternatives.
|
|
3
|
+
const MAX_BRACE_DEPTH = 8;
|
|
4
|
+
// Maps each opening brace that has a closing brace to whether it is a real alternation group. Braces nested
|
|
5
|
+
// deeper than MAX_BRACE_DEPTH stay paired but literal, so their commas and closers never alter an outer group.
|
|
6
|
+
function pairBraces(pattern) {
|
|
7
|
+
const closeOfOpen = new Map();
|
|
8
|
+
const openIndexes = [];
|
|
9
|
+
for (let index = 0; index < pattern.length; index++) {
|
|
10
|
+
if (pattern[index] === '{')
|
|
11
|
+
openIndexes.push(index);
|
|
12
|
+
else if (pattern[index] === '}' && openIndexes.length)
|
|
13
|
+
closeOfOpen.set(openIndexes.pop() ?? index, index);
|
|
14
|
+
}
|
|
15
|
+
// Unmatched openings stay literal and must not count toward the nesting depth of real pairs.
|
|
16
|
+
const pairs = new Map();
|
|
17
|
+
const pairedCloses = [];
|
|
18
|
+
for (let index = 0; index < pattern.length; index++) {
|
|
19
|
+
if (closeOfOpen.has(index)) {
|
|
20
|
+
pairs.set(index, pairedCloses.length < MAX_BRACE_DEPTH);
|
|
21
|
+
pairedCloses.push(closeOfOpen.get(index) ?? index);
|
|
22
|
+
}
|
|
23
|
+
else if (pairedCloses.at(-1) === index)
|
|
24
|
+
pairedCloses.pop();
|
|
25
|
+
}
|
|
26
|
+
return pairs;
|
|
27
|
+
}
|
|
3
28
|
function globSource(rawPattern) {
|
|
4
29
|
const pattern = rawPattern.replaceAll(/(?:\*\*\/)+/g, '**/').replaceAll(/\*{3,}/g, '**');
|
|
5
30
|
let source = '';
|
|
6
|
-
|
|
31
|
+
const bracePairs = pairBraces(pattern);
|
|
32
|
+
const openBraceIsGroup = [];
|
|
7
33
|
for (let index = 0; index < pattern.length; index++) {
|
|
8
34
|
const character = pattern[index];
|
|
9
35
|
if (character === '*' && pattern[index + 1] === '*') {
|
|
@@ -15,15 +41,15 @@ function globSource(rawPattern) {
|
|
|
15
41
|
source += '[^/]*';
|
|
16
42
|
else if (character === '?')
|
|
17
43
|
source += '[^/]';
|
|
18
|
-
else if (character === '{' &&
|
|
19
|
-
|
|
20
|
-
|
|
44
|
+
else if (character === '{' && bracePairs.has(index)) {
|
|
45
|
+
const isGroup = bracePairs.get(index) === true;
|
|
46
|
+
openBraceIsGroup.push(isGroup);
|
|
47
|
+
source += isGroup ? '(?:' : String.raw `\{`;
|
|
21
48
|
}
|
|
22
|
-
else if (character === ',' &&
|
|
49
|
+
else if (character === ',' && openBraceIsGroup.at(-1))
|
|
23
50
|
source += '|';
|
|
24
|
-
else if (character === '}' &&
|
|
25
|
-
|
|
26
|
-
source += ')';
|
|
51
|
+
else if (character === '}' && openBraceIsGroup.length) {
|
|
52
|
+
source += openBraceIsGroup.pop() ? ')' : String.raw `\}`;
|
|
27
53
|
}
|
|
28
54
|
else
|
|
29
55
|
source += character.replaceAll(/[.+^$[\]\\(){}|]/g, '\\$&');
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// Opt-in Sentry crash reporting sends diagnostic metadata about Loadwise itself.
|
|
2
2
|
import crypto from 'node:crypto';
|
|
3
|
+
import { errorMessage } from './error-code.js';
|
|
4
|
+
import { terminalSafe } from './terminal-safe.js';
|
|
3
5
|
import { isIP } from 'node:net';
|
|
4
6
|
import { fileURLToPath } from 'node:url';
|
|
5
7
|
import { packageManifest, packageRoot } from '../package-root.js';
|
|
@@ -20,7 +22,7 @@ const BUILT_IN_ERROR_NAMES = new Set([
|
|
|
20
22
|
'TypeError',
|
|
21
23
|
'URIError',
|
|
22
24
|
]);
|
|
23
|
-
const EXPECTED_CLI_ERROR_RE = /^(?:Usage:|Unknown (?:option|.*rule|--)|Choose (?:either |one of )|Option '[^']+' argument|Pass one checker name|Expected (?:an existing|a project directory|a project-relative path|a nonempty)|--[a-z][a-z-]* (?:must be|is only valid|cannot be combined|supports|accepts|is read-only|apply to)|Invalid |Cannot (?:combine|load) |Cannot find (?:tsconfig|jsconfig|config|project|file|directory)\b|No (?:tsconfig|inputs were found|supported source files|package-lock\.json)|Baseline not found:|ENOENT:|error TS\d+:|Option '[^']+' must be|Unsupported |.* must be an array\.|check never changes (?:source )?files\.|--uncommitted requires a Git repository|fix accepts at most one project directory\.|Workspace packages are missing|Trace file contains invalid JSON|Initialize local review history|The (?:Performance|Reliability|Maintainability|Security|Accessibility) scan did not complete|.*\.findings contains a finding)/;
|
|
25
|
+
const EXPECTED_CLI_ERROR_RE = /^(?:Usage:|Unknown (?:option|.*rule|--)|Choose (?:either |one of )|Option '[^']+' argument|Pass one checker name|Expected (?:an existing|a project directory|a project-relative path|a nonempty)|--[a-z][a-z-]* (?:must be|is only valid|cannot be combined|supports|accepts|is read-only|apply to)|Invalid |Cannot (?:combine|load) |Cannot find (?:tsconfig|jsconfig|config|project|file|directory)\b|No (?:tsconfig|inputs were found|supported source files|package-lock\.json)|Baseline not found:|ENOENT:|error TS\d+:|Option '[^']+' must be|Unsupported |.* must be an array\.|check never changes (?:source )?files\.|--uncommitted requires a Git repository|fix accepts at most one project directory\.|Project directory ".*" (?:does not exist|is not a directory)\.|Workspace packages are missing|Trace file contains invalid JSON|The Sublime package link at .* has a missing target.|Initialize local review history|The (?:Performance|Reliability|Maintainability|Security|Accessibility) scan did not complete|.*\.findings contains a finding)/;
|
|
24
26
|
/**
|
|
25
27
|
* Parses a Sentry DSN into its Envelope endpoint URL and X-Sentry-Auth header.
|
|
26
28
|
* Returns null when the DSN is empty or malformed.
|
|
@@ -50,10 +52,18 @@ function parseSentryDsn(dsn) {
|
|
|
50
52
|
authHeader: `Sentry sentry_version=7, sentry_client=loadwise/${packageManifest.version}, sentry_key=${url.username}`,
|
|
51
53
|
};
|
|
52
54
|
}
|
|
55
|
+
class CliUsageError extends Error {
|
|
56
|
+
constructor(message) {
|
|
57
|
+
super(message);
|
|
58
|
+
this.name = 'CliUsageError';
|
|
59
|
+
}
|
|
60
|
+
}
|
|
53
61
|
/**
|
|
54
62
|
* Returns true for expected CLI usage, flag, or input validation errors that should not page Sentry.
|
|
55
63
|
*/
|
|
56
64
|
function isExpectedCliError(error) {
|
|
65
|
+
if (error instanceof CliUsageError)
|
|
66
|
+
return true;
|
|
57
67
|
const message = error instanceof Error ? error.message : String(error);
|
|
58
68
|
return EXPECTED_CLI_ERROR_RE.test(message.trim());
|
|
59
69
|
}
|
|
@@ -187,17 +197,26 @@ async function reportCrash(error, command, dsnOrTarget = resolveCrashReportTarge
|
|
|
187
197
|
return false;
|
|
188
198
|
}
|
|
189
199
|
}
|
|
200
|
+
/** Formats a thrown value for stderr; unprintable values (e.g. Object.create(null)) must not stop the exit-2 path. */
|
|
201
|
+
function describeCrash(error) {
|
|
202
|
+
try {
|
|
203
|
+
return terminalSafe(errorMessage(error));
|
|
204
|
+
}
|
|
205
|
+
catch {
|
|
206
|
+
return 'unprintable error value';
|
|
207
|
+
}
|
|
208
|
+
}
|
|
190
209
|
/**
|
|
191
210
|
* Installs uncaughtException / unhandledRejection listeners when crash reporting is enabled.
|
|
192
211
|
*/
|
|
193
212
|
function installGlobalCrashHandlers(command, target = resolveCrashReportTarget()) {
|
|
194
213
|
if (!target)
|
|
195
214
|
return;
|
|
196
|
-
|
|
215
|
+
const handleCrash = (error) => {
|
|
216
|
+
console.error('Unexpected Loadwise error: ' + describeCrash(error));
|
|
197
217
|
void reportCrash(error, command, target).finally(() => process.exit(2));
|
|
198
|
-
}
|
|
199
|
-
process.once('
|
|
200
|
-
|
|
201
|
-
});
|
|
218
|
+
};
|
|
219
|
+
process.once('uncaughtException', handleCrash);
|
|
220
|
+
process.once('unhandledRejection', handleCrash);
|
|
202
221
|
}
|
|
203
|
-
export { parseSentryDsn, resolveCrashReportTarget, buildEnvelope, reportCrash, isExpectedCliError, installGlobalCrashHandlers, };
|
|
222
|
+
export { CliUsageError, parseSentryDsn, resolveCrashReportTarget, buildEnvelope, reportCrash, isExpectedCliError, installGlobalCrashHandlers, };
|
|
@@ -225,7 +225,9 @@ function workspacePackagesAround(directory) {
|
|
|
225
225
|
for (let current = path.resolve(directory);; current = path.dirname(current)) {
|
|
226
226
|
if (isTempRoot(current))
|
|
227
227
|
return new Map();
|
|
228
|
-
const patterns = isFile(path.join(current, 'package.json')) ||
|
|
228
|
+
const patterns = isFile(path.join(current, 'package.json')) ||
|
|
229
|
+
isFile(path.join(current, 'pnpm-workspace.yaml')) ||
|
|
230
|
+
isFile(path.join(current, 'lerna.json'))
|
|
229
231
|
? workspacePatterns(current)
|
|
230
232
|
: [];
|
|
231
233
|
if (patterns.length) {
|
|
@@ -270,6 +272,14 @@ function workspaceSourceEntry(directory, subpath) {
|
|
|
270
272
|
}
|
|
271
273
|
return undefined;
|
|
272
274
|
}
|
|
275
|
+
function realDirectory(directory) {
|
|
276
|
+
try {
|
|
277
|
+
return fs.realpathSync.native(directory);
|
|
278
|
+
}
|
|
279
|
+
catch {
|
|
280
|
+
return path.resolve(directory);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
273
283
|
// A selector is a package name or a path to its folder, relative to the working directory or to the
|
|
274
284
|
// root.
|
|
275
285
|
function selectWorkspaces(packages, root, selectors, caller = process.cwd()) {
|
|
@@ -277,8 +287,10 @@ function selectWorkspaces(packages, root, selectors, caller = process.cwd()) {
|
|
|
277
287
|
return packages;
|
|
278
288
|
const chosen = new Set();
|
|
279
289
|
for (const selector of selectors) {
|
|
280
|
-
const
|
|
281
|
-
const
|
|
290
|
+
const resolvedCandidates = [path.resolve(caller, selector), path.resolve(root, selector)];
|
|
291
|
+
const candidates = new Set(resolvedCandidates);
|
|
292
|
+
const realCandidates = new Set(resolvedCandidates.map(realDirectory));
|
|
293
|
+
const matched = packages.filter(({ name, directory }) => name === selector || candidates.has(directory) || realCandidates.has(realDirectory(directory)));
|
|
282
294
|
if (!matched.length) {
|
|
283
295
|
throw new Error(`--workspace ${selector} matches no workspace package.`);
|
|
284
296
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "loadwise",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Local static analysis for TypeScript & JavaScript: catches N+1 queries, PostgreSQL pool leaks, unsafe migrations, unhandled async errors, and security/a11y bugs ESLint misses.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -77,6 +77,7 @@
|
|
|
77
77
|
"polyglot/performance/",
|
|
78
78
|
"polyglot/reliability/",
|
|
79
79
|
"polyglot/security/",
|
|
80
|
+
"polyglot/shared-rules/",
|
|
80
81
|
"schema/",
|
|
81
82
|
"examples/",
|
|
82
83
|
"docs/assets/cli-workflow.gif",
|
|
@@ -116,7 +117,9 @@
|
|
|
116
117
|
"lint:fix": "oxlint --fix ."
|
|
117
118
|
},
|
|
118
119
|
"dependencies": {
|
|
120
|
+
"@turingpointde/cvss.js": "2.1.0",
|
|
119
121
|
"libpg-query": "18.3.0",
|
|
122
|
+
"semver": "7.8.6",
|
|
120
123
|
"typescript": "6.0.3",
|
|
121
124
|
"vscode-languageserver": "11.0.2",
|
|
122
125
|
"vscode-languageserver-textdocument": "1.0.16"
|
|
@@ -147,6 +150,7 @@
|
|
|
147
150
|
},
|
|
148
151
|
"devDependencies": {
|
|
149
152
|
"@types/node": "26.6.11",
|
|
153
|
+
"@types/semver": "7.8.0",
|
|
150
154
|
"oxlint": "1.95.0",
|
|
151
155
|
"prettier": "3.10.1"
|
|
152
156
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "loadwise",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Runs the project's local loadwise checkers on each file Claude edits and sends findings back with their fix commands.",
|
|
5
5
|
"author": { "name": "Ibrahim Hafez" },
|
|
6
6
|
"homepage": "https://loadwise.mintlify.app/",
|