loadwise 0.5.0 → 0.6.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 +543 -628
- package/bin/loadwise.js +5 -1
- package/lib/accessibility/frontend-detect.js +2 -1
- package/lib/accessibility/rule-ids.js +12 -9
- package/lib/accessibility/template-attributes.js +4 -2
- package/{editor/accessibility-examples.cjs → lib/editor/accessibility-examples.js} +20 -21
- package/lib/editor/actions.js +117 -0
- package/{editor/apply-fix.cjs → lib/editor/apply-fix.js} +1 -6
- package/{editor/control-flow-comparison.cjs → lib/editor/control-flow-comparison.js} +1 -3
- package/lib/editor/diagnostics.js +365 -0
- package/lib/editor/dismissals.js +111 -0
- package/lib/editor/editor-document.js +99 -0
- package/{editor/finding-comparison.cjs → lib/editor/finding-comparison.js} +4 -7
- package/lib/editor/fix-edits.js +200 -0
- package/lib/editor/language-server.js +437 -0
- package/{editor/maintainability-examples.cjs → lib/editor/maintainability-examples.js} +1 -3
- package/{editor/perf-site-comparison.cjs → lib/editor/perf-site-comparison.js} +1 -3
- package/lib/editor/perf-watch.js +78 -0
- package/{editor/performance-examples.cjs → lib/editor/performance-examples.js} +129 -128
- package/{editor/reliability-examples.cjs → lib/editor/reliability-examples.js} +100 -41
- package/lib/editor/scan-session.js +334 -0
- package/{editor/security-examples.cjs → lib/editor/security-examples.js} +28 -32
- package/lib/editor/server-commands.js +232 -0
- package/{editor/source-example.cjs → lib/editor/source-example.js} +3 -5
- package/{editor/standalone-performance-examples.cjs → lib/editor/standalone-performance-examples.js} +349 -333
- package/lib/editor/types/dismissal.js +1 -0
- package/lib/editor/types/fix-example.js +1 -0
- package/lib/editor/types/source-document.js +1 -0
- package/lib/editor/workspace-files.js +78 -0
- package/lib/editor/workspace-paths.js +22 -0
- package/lib/maintainability/analyze-source.js +2 -0
- package/lib/maintainability/apply-fix.js +1 -1
- package/lib/maintainability/cli.js +1 -1
- package/lib/maintainability/examples.js +58 -41
- package/lib/maintainability/rule-ids.js +29 -14
- package/lib/maintainability/scan-changed.js +3 -0
- package/lib/maintainability/scan.js +13 -9
- package/lib/maintainability/tsconfig-strict.js +69 -0
- package/lib/maintainability/type-safety-hygiene.js +204 -0
- package/lib/performance/analyze.js +2 -0
- package/lib/performance/cli-arguments.js +0 -2
- package/lib/performance/cli-policy.js +17 -9
- package/lib/performance/cli-scan.js +10 -8
- package/lib/performance/cli.js +4 -23
- package/lib/performance/editor-signal.js +1 -1
- package/lib/performance/finding-text.js +3 -3
- package/lib/performance/fix-cli.js +1 -1
- package/lib/performance/frontend-perf.js +7 -0
- package/lib/performance/frontend-render-perf.js +200 -0
- package/lib/performance/llm-max-tokens.js +56 -0
- package/lib/performance/native.js +46 -26
- package/lib/performance/polyglot.js +22 -1
- package/lib/performance/pooling.js +38 -23
- package/lib/performance/projects.js +42 -21
- package/lib/performance/rule-ids.js +236 -222
- package/lib/performance/site-fixes/database.js +3 -1
- package/lib/performance/site-fixes/integrity.js +15 -1
- package/lib/performance/source-inputs.js +18 -6
- package/lib/performance/unscanned-javascript.js +66 -19
- package/lib/reliability/analyze.js +12 -0
- package/lib/reliability/child-process.js +106 -0
- package/lib/reliability/error-values.js +177 -0
- package/lib/reliability/pool-timeout.js +79 -0
- package/lib/reliability/react-bugs.js +602 -0
- package/lib/reliability/resource-leaks.js +3 -6
- package/lib/reliability/rule-ids.js +169 -127
- package/lib/reliability/switch-exhaustive.js +284 -0
- package/lib/reliability/uncaught-exception.js +223 -0
- package/lib/security/auth-crypto/rule-ids.js +3 -2
- package/lib/security/cli.js +6 -5
- package/lib/security/deps/rule-ids.js +1 -0
- package/lib/security/examples/auth-crypto.cjs +5 -4
- package/lib/security/examples/deps.cjs +1 -0
- package/lib/security/examples/exposure.cjs +55 -42
- package/lib/security/examples/files.cjs +1 -0
- package/lib/security/examples/injection.cjs +1 -0
- package/lib/security/examples/moved.cjs +5 -4
- package/lib/security/examples/request-forgery.cjs +1 -0
- package/lib/security/exposure/client-env.js +113 -0
- package/lib/security/exposure/frontend-security.js +12 -10
- package/lib/security/exposure/index.js +14 -3
- package/lib/security/exposure/jsx-url.js +267 -0
- package/lib/security/exposure/next-image-config.js +34 -0
- package/lib/security/exposure/package-manifest.js +45 -0
- package/lib/security/exposure/react-version.js +45 -0
- package/lib/security/exposure/rule-ids.js +16 -12
- package/lib/security/files/index.js +1 -1
- package/lib/security/files/rule-ids.js +1 -0
- package/lib/security/injection/code.js +24 -10
- package/lib/security/injection/command.js +81 -28
- package/lib/security/injection/nosql.js +109 -22
- package/lib/security/injection/redos.js +152 -308
- package/lib/security/injection/regex-pattern.js +290 -0
- package/lib/security/injection/regex.js +30 -11
- package/lib/security/injection/rule-ids.js +2 -1
- package/lib/security/injection/shared.js +19 -1
- package/lib/security/injection/sql.js +83 -2
- package/lib/security/request-forgery/rule-ids.js +1 -0
- package/lib/security/rule-descriptions.js +36 -32
- package/lib/security/rule-ids.js +74 -67
- package/lib/security/taint/filename-guard.js +3 -1
- package/lib/security/taint/guards.js +84 -10
- package/lib/security/taint/index.js +124 -13
- package/lib/security/taint/propagate.js +10 -7
- package/lib/security/taint/sanitizers.js +7 -3
- package/lib/security/taint/sources.js +6 -3
- package/lib/security/taint/summaries.js +13 -1
- package/lib/security/taint/url-parts.js +14 -5
- package/lib/shared/agent-session.js +2 -2
- package/lib/shared/check.js +16 -6
- package/lib/shared/explain.js +5 -5
- package/lib/shared/fix-convergence.js +1 -1
- package/lib/shared/formats/finding-location.js +6 -2
- package/lib/shared/formats/sarif.js +3 -3
- package/lib/shared/heap-limit.js +20 -3
- package/lib/shared/pillars.js +7 -7
- package/lib/shared/rule-docs.js +12 -0
- package/lib/shared/scan-cache.js +0 -1
- package/lib/shared/workspaces.js +31 -9
- package/package.json +12 -19
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/schema/loadwise.config.schema.json +44 -0
- package/editor/README.md +0 -47
- package/examples/redis-keys.otlp.json +0 -22
- package/lib/maintainability/notify-editor.js +0 -1
- package/lib/performance/editor-report.js +0 -191
- package/lib/performance/editor-setup.js +0 -189
- package/lib/performance/editor-watch-supervisor.js +0 -104
- package/lib/performance/editor-watch.js +0 -193
- package/lib/performance/notify-editor.js +0 -1
- package/lib/performance/recursive-watch.js +0 -181
- /package/lib/{performance/types/editor-report.js → editor/types/comparison.js} +0 -0
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
// The workspace/executeCommand handlers. Arguments come back from the editor, so each one is checked
|
|
2
|
+
// again before it touches a file.
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { commands } from './actions.js';
|
|
6
|
+
import { bulkFixesFor, fixAllEdit, fixEdit, missingFolders } from './fix-edits.js';
|
|
7
|
+
import { isRealPathInside } from './workspace-paths.js';
|
|
8
|
+
import { errorCode, errorMessage } from '../shared/error-code.js';
|
|
9
|
+
import { isRecord } from '../shared/is-record.js';
|
|
10
|
+
// A message request shows one button per entry, so long lists offer Restore all and the first few.
|
|
11
|
+
const maxRestoreButtons = 10;
|
|
12
|
+
function changeArgument(context, value) {
|
|
13
|
+
if (!isRecord(value))
|
|
14
|
+
return;
|
|
15
|
+
const { file, filename, line, before, after, create } = value;
|
|
16
|
+
if (typeof file !== 'string' || typeof filename !== 'string' || !path.isAbsolute(filename))
|
|
17
|
+
return;
|
|
18
|
+
if (typeof before !== 'string' || typeof after !== 'string')
|
|
19
|
+
return;
|
|
20
|
+
if (typeof line !== 'number' || !Number.isSafeInteger(line) || line < 1)
|
|
21
|
+
return;
|
|
22
|
+
const folder = context.folderFor(filename);
|
|
23
|
+
if (!folder || !isRealPathInside(folder.root, filename))
|
|
24
|
+
return;
|
|
25
|
+
return { file, filename, line, before, after, ...(create === true ? { create: true } : {}) };
|
|
26
|
+
}
|
|
27
|
+
function fixArgument(context, value) {
|
|
28
|
+
if (!isRecord(value) || !Array.isArray(value.changes) || !value.changes.length)
|
|
29
|
+
return;
|
|
30
|
+
const changes = [];
|
|
31
|
+
for (const item of value.changes) {
|
|
32
|
+
const change = changeArgument(context, item);
|
|
33
|
+
if (!change)
|
|
34
|
+
return;
|
|
35
|
+
changes.push(change);
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
changes,
|
|
39
|
+
note: typeof value.note === 'string' ? value.note : undefined,
|
|
40
|
+
requiresReview: value.requiresReview === true,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function dismissalArgument(context, value) {
|
|
44
|
+
if (!isRecord(value) || typeof value.file !== 'string' || typeof value.ruleId !== 'string')
|
|
45
|
+
return;
|
|
46
|
+
if (!path.isAbsolute(value.file))
|
|
47
|
+
return;
|
|
48
|
+
const folder = context.folderFor(value.file);
|
|
49
|
+
if (!folder)
|
|
50
|
+
return;
|
|
51
|
+
const entry = { file: value.file, ruleId: value.ruleId };
|
|
52
|
+
if (typeof value.lineText === 'string')
|
|
53
|
+
entry.lineText = value.lineText;
|
|
54
|
+
return { folder, entry };
|
|
55
|
+
}
|
|
56
|
+
// Returns the folders it made, so a rejected edit leaves none behind.
|
|
57
|
+
function makeFolders(folders) {
|
|
58
|
+
const made = [];
|
|
59
|
+
try {
|
|
60
|
+
for (const folder of folders) {
|
|
61
|
+
try {
|
|
62
|
+
fs.mkdirSync(folder);
|
|
63
|
+
made.push(folder);
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
if (errorCode(error) !== 'EEXIST')
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
removeEmptyFolders(made);
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
75
|
+
return made;
|
|
76
|
+
}
|
|
77
|
+
function removeEmptyFolders(folders) {
|
|
78
|
+
for (const folder of folders.toReversed()) {
|
|
79
|
+
try {
|
|
80
|
+
fs.rmdirSync(folder);
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
// The editor wrote into it after all; the folder stays with its files.
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
// Only a transactional editor guarantees a rollback; `undo` is an attempt. A failure at the first
|
|
88
|
+
// operation ran nothing before it, while a missing index says nothing either way.
|
|
89
|
+
function mayBePartlyApplied(context, edit, failedChange) {
|
|
90
|
+
const operations = edit.documentChanges?.length ?? Object.keys(edit.changes ?? {}).length;
|
|
91
|
+
if (operations < 2 || failedChange === 0)
|
|
92
|
+
return false;
|
|
93
|
+
const createsFiles = edit.documentChanges?.some((change) => 'kind' in change) ?? false;
|
|
94
|
+
const { failureHandling } = context.fixWorkspace();
|
|
95
|
+
if (failureHandling === 'transactional')
|
|
96
|
+
return false;
|
|
97
|
+
return failureHandling !== 'textOnlyTransactional' || createsFiles;
|
|
98
|
+
}
|
|
99
|
+
async function applyEdit(context, { edit, createdFiles }, failure) {
|
|
100
|
+
const { window } = context.connection;
|
|
101
|
+
let made;
|
|
102
|
+
try {
|
|
103
|
+
made = makeFolders(missingFolders(createdFiles));
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
window.showWarningMessage(failure + ' ' + errorMessage(error));
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
let result = { applied: false };
|
|
110
|
+
try {
|
|
111
|
+
result = await context.connection.workspace.applyEdit({ label: 'Loadwise', edit });
|
|
112
|
+
}
|
|
113
|
+
finally {
|
|
114
|
+
if (!result.applied)
|
|
115
|
+
removeEmptyFolders(made);
|
|
116
|
+
}
|
|
117
|
+
if (result.applied)
|
|
118
|
+
return true;
|
|
119
|
+
const partial = mayBePartlyApplied(context, edit, result.failedChange)
|
|
120
|
+
? ' The editor may have kept changes made before the failure; undo them or check the files the fix names.'
|
|
121
|
+
: '';
|
|
122
|
+
window.showWarningMessage(failure + partial);
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
async function applyFix(context, value) {
|
|
126
|
+
const fix = fixArgument(context, value);
|
|
127
|
+
if (!fix)
|
|
128
|
+
return context.connection.window.showWarningMessage('Loadwise could not read this fix.');
|
|
129
|
+
const result = fixEdit(fix, context.fixWorkspace());
|
|
130
|
+
if (result.edit === undefined)
|
|
131
|
+
return context.connection.window.showWarningMessage(result.error);
|
|
132
|
+
await applyEdit(context, result, 'Loadwise could not apply the fix.');
|
|
133
|
+
}
|
|
134
|
+
async function applyAllFixes(context, value) {
|
|
135
|
+
const { window } = context.connection;
|
|
136
|
+
const { eligible, reviewCount } = bulkFixesFor(typeof value === 'string' ? context.entriesFor(value) : []);
|
|
137
|
+
if (!eligible.length && !reviewCount)
|
|
138
|
+
return window.showInformationMessage('Loadwise has no fixes for this file.');
|
|
139
|
+
const planned = fixAllEdit(eligible, context.fixWorkspace());
|
|
140
|
+
const { applied, skipped } = planned;
|
|
141
|
+
if (applied && !(await applyEdit(context, planned, 'Loadwise could not apply the selected fixes.')))
|
|
142
|
+
return;
|
|
143
|
+
const summary = 'Loadwise applied ' + applied + ' fix(es)';
|
|
144
|
+
const reviewNote = reviewCount ? ' ' + reviewCount + ' fix(es) require individual review.' : '';
|
|
145
|
+
if (!skipped)
|
|
146
|
+
window.showInformationMessage(summary + '.' + reviewNote);
|
|
147
|
+
else
|
|
148
|
+
window.showWarningMessage(summary + '; skipped ' + skipped + ' stale, overlapping or existing-file fix(es).' + reviewNote);
|
|
149
|
+
}
|
|
150
|
+
// A dismissal file that cannot be read or written is left alone, and the editor says why.
|
|
151
|
+
async function saveDismissals(context, save) {
|
|
152
|
+
try {
|
|
153
|
+
await save();
|
|
154
|
+
return true;
|
|
155
|
+
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
context.connection.window.showErrorMessage('Loadwise could not update the dismissed findings: ' + errorMessage(error));
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
async function dismiss(context, value) {
|
|
162
|
+
const target = dismissalArgument(context, value);
|
|
163
|
+
if (!target)
|
|
164
|
+
return;
|
|
165
|
+
if (await saveDismissals(context, () => target.folder.dismissals.add(target.entry)))
|
|
166
|
+
context.republish(target.folder);
|
|
167
|
+
}
|
|
168
|
+
function allDismissed(context) {
|
|
169
|
+
return [...context.folders()].flatMap((folder) => folder.dismissals.entries().map((entry) => ({ folder, entry })));
|
|
170
|
+
}
|
|
171
|
+
async function restore(context, restored) {
|
|
172
|
+
const byFolder = new Map();
|
|
173
|
+
for (const { folder, entry } of restored)
|
|
174
|
+
byFolder.set(folder, [...(byFolder.get(folder) ?? []), entry]);
|
|
175
|
+
for (const [folder, entries] of byFolder) {
|
|
176
|
+
if (await saveDismissals(context, () => folder.dismissals.remove(entries)))
|
|
177
|
+
context.republish(folder);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
function describe({ folder, entry }, index) {
|
|
181
|
+
const file = path.relative(folder.root, entry.file).split(path.sep).join('/');
|
|
182
|
+
const line = typeof entry.lineText === 'string' ? entry.lineText || '(blank line)' : 'Whole file';
|
|
183
|
+
return index + 1 + '. ' + entry.ruleId + ' — ' + file + ' — ' + line;
|
|
184
|
+
}
|
|
185
|
+
async function showDismissed(context) {
|
|
186
|
+
const { window } = context.connection;
|
|
187
|
+
const dismissed = allDismissed(context);
|
|
188
|
+
if (!dismissed.length)
|
|
189
|
+
return window.showInformationMessage('No Loadwise findings are dismissed.');
|
|
190
|
+
const restoreAll = { title: 'Restore all (' + dismissed.length + ')' };
|
|
191
|
+
const restoreOne = dismissed.slice(0, maxRestoreButtons).map((_item, index) => ({ title: 'Restore ' + (index + 1) }));
|
|
192
|
+
const message = ['Dismissed Loadwise findings:', ...dismissed.map(describe)].join('\n');
|
|
193
|
+
const picked = await window.showInformationMessage(message, restoreAll, ...restoreOne);
|
|
194
|
+
if (!picked)
|
|
195
|
+
return;
|
|
196
|
+
if (picked === restoreAll || picked.title === restoreAll.title)
|
|
197
|
+
return restore(context, dismissed);
|
|
198
|
+
const index = restoreOne.findIndex((action) => action.title === picked.title);
|
|
199
|
+
if (index !== -1)
|
|
200
|
+
await restore(context, [dismissed[index]]);
|
|
201
|
+
}
|
|
202
|
+
// With a dismissal entry it restores that one; without arguments it restores every dismissal.
|
|
203
|
+
async function restoreDismissed(context, value) {
|
|
204
|
+
if (value === undefined)
|
|
205
|
+
return restore(context, allDismissed(context));
|
|
206
|
+
const target = dismissalArgument(context, value);
|
|
207
|
+
if (target)
|
|
208
|
+
await restore(context, [target]);
|
|
209
|
+
}
|
|
210
|
+
async function scanAll(context) {
|
|
211
|
+
for (const folder of context.folders())
|
|
212
|
+
await folder.session.scanNow();
|
|
213
|
+
}
|
|
214
|
+
function runCommand(context, command, commandArguments) {
|
|
215
|
+
const [argument] = commandArguments;
|
|
216
|
+
switch (command) {
|
|
217
|
+
case commands.scan:
|
|
218
|
+
return scanAll(context);
|
|
219
|
+
case commands.applyFix:
|
|
220
|
+
return applyFix(context, argument);
|
|
221
|
+
case commands.applyAllFixes:
|
|
222
|
+
return applyAllFixes(context, argument);
|
|
223
|
+
case commands.dismiss:
|
|
224
|
+
return dismiss(context, argument);
|
|
225
|
+
case commands.showDismissed:
|
|
226
|
+
return showDismissed(context);
|
|
227
|
+
case commands.restoreDismissed:
|
|
228
|
+
return restoreDismissed(context, argument);
|
|
229
|
+
}
|
|
230
|
+
return Promise.reject(new Error('Unknown Loadwise command: ' + command));
|
|
231
|
+
}
|
|
232
|
+
export { runCommand };
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sourceExampleFor = sourceExampleFor;
|
|
4
|
-
const perf_site_comparison_cjs_1 = require("./perf-site-comparison.cjs");
|
|
1
|
+
import { perfSiteComparison } from './perf-site-comparison.js';
|
|
5
2
|
const scriptLanguages = new Set(['javascript', 'javascriptreact', 'typescript', 'typescriptreact']);
|
|
6
3
|
// An omitted semicolon can continue the expression on the next line.
|
|
7
4
|
const membershipExpression = /^\s*(return\s+)?(!?)\s*([$A-Z_a-z][$\w]*)\.(every|some)\(\s*(\()?([$A-Z_a-z][$\w]*)(\))?\s*=>\s*([$A-Z_a-z][$\w]*(?:\.[$A-Z_a-z][$\w]*)?)\.includes\(\s*([$A-Z_a-z][$\w]*)\s*\)\s*\);\s*$/;
|
|
@@ -13,7 +10,7 @@ function sourceExampleFor(document, diagnostic) {
|
|
|
13
10
|
return;
|
|
14
11
|
const line = document.lineAt(position.line).text;
|
|
15
12
|
if (diagnostic.code !== 'array-repeated-membership') {
|
|
16
|
-
const site =
|
|
13
|
+
const site = perfSiteComparison(document, line, diagnostic);
|
|
17
14
|
return site && { ...site, language: document.languageId.startsWith('typescript') ? 'typescript' : 'javascript' };
|
|
18
15
|
}
|
|
19
16
|
if (diagnostic.message?.startsWith('This array was copied from a Set'))
|
|
@@ -64,3 +61,4 @@ function sourceExampleFor(document, diagnostic) {
|
|
|
64
61
|
code: `let ${name} = ${alternative};\nif (!${name} && ${values}.length > 0) {\n ${build}\n ${name} = ${check}\n}`,
|
|
65
62
|
};
|
|
66
63
|
}
|
|
64
|
+
export { sourceExampleFor };
|