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
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// lenses over the Language Server Protocol on stdin and stdout.
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
6
|
-
import { packageManifest } from '../shared/package-root.js';
|
|
6
|
+
import { packageManifest, packagePath } from '../shared/package-root.js';
|
|
7
7
|
import { CodeActionKind, CodeLensRefreshRequest, DidChangeConfigurationNotification, DidChangeWatchedFilesNotification, FileChangeType, TextDocumentSyncKind, TextDocuments, createConnection, } from 'vscode-languageserver/node';
|
|
8
8
|
import { TextDocument } from 'vscode-languageserver-textdocument';
|
|
9
9
|
import { codeActions, codeLenses, commands, fixAllKind } from './actions.js';
|
|
@@ -13,10 +13,10 @@ import { createEditorDocument, readDiskDocument } from './editor-document.js';
|
|
|
13
13
|
import { createScanSession } from './scan-session.js';
|
|
14
14
|
import { classifyChange, watchedGlobs } from './workspace-files.js';
|
|
15
15
|
import { runCommand } from './server-commands.js';
|
|
16
|
-
import { isInside } from './workspace-paths.js';
|
|
16
|
+
import { isInside, isRealPathInside } from './workspace-paths.js';
|
|
17
17
|
import { isRecord } from '../shared/system/is-record.js';
|
|
18
18
|
const usage = 'Usage: loadwise lsp [--stdio]';
|
|
19
|
-
const defaultCli =
|
|
19
|
+
const defaultCli = packagePath('dist/bin/loadwise.js');
|
|
20
20
|
const severities = new Set(['default', 'error', 'warning', 'information', 'hint']);
|
|
21
21
|
const defaultSettings = { enabled: true, project: '', cli: '', severity: 'default', codeLens: true };
|
|
22
22
|
// Only these change what the checkers report; severity and code lenses only change how it is shown.
|
|
@@ -88,6 +88,7 @@ function serverCapabilities() {
|
|
|
88
88
|
}
|
|
89
89
|
function startServer(connection) {
|
|
90
90
|
const documents = new TextDocuments(TextDocument);
|
|
91
|
+
let openSnapshots = new WeakMap();
|
|
91
92
|
const openUris = new Map();
|
|
92
93
|
const savedVersions = new Map();
|
|
93
94
|
const pendingDiskChecks = new Map();
|
|
@@ -106,26 +107,35 @@ function startServer(connection) {
|
|
|
106
107
|
}
|
|
107
108
|
function documentFor(filename) {
|
|
108
109
|
const key = fileKey(filename);
|
|
109
|
-
const uri = openUris.get(key);
|
|
110
|
+
const uri = openUris.get(key)?.at(-1);
|
|
110
111
|
const open = uri === undefined ? undefined : documents.get(uri);
|
|
111
112
|
if (!open)
|
|
112
113
|
return readDiskDocument(filename);
|
|
114
|
+
const previous = openSnapshots.get(open);
|
|
115
|
+
const dirty = savedVersions.get(open.uri) !== open.version;
|
|
116
|
+
if (previous?.version === open.version && previous.isDirty === dirty)
|
|
117
|
+
return previous;
|
|
113
118
|
const text = open.getText();
|
|
114
|
-
const initialVersion = pendingDiskChecks.get(
|
|
119
|
+
const initialVersion = pendingDiskChecks.get(open.uri);
|
|
115
120
|
if (initialVersion !== undefined) {
|
|
116
|
-
pendingDiskChecks.delete(
|
|
117
|
-
if (initialVersion === open.version
|
|
118
|
-
|
|
121
|
+
pendingDiskChecks.delete(open.uri);
|
|
122
|
+
if (initialVersion === open.version) {
|
|
123
|
+
const owner = folderFor(filename);
|
|
124
|
+
const saved = owner && isRealPathInside(owner.root, filename) ? readDiskDocument(filename) : undefined;
|
|
125
|
+
if (saved?.getText() === text)
|
|
126
|
+
savedVersions.set(open.uri, initialVersion);
|
|
119
127
|
}
|
|
120
128
|
}
|
|
121
|
-
|
|
129
|
+
const snapshot = createEditorDocument(filename, text, {
|
|
122
130
|
languageId: open.languageId,
|
|
123
131
|
version: open.version,
|
|
124
|
-
isDirty: savedVersions.get(
|
|
132
|
+
isDirty: savedVersions.get(open.uri) !== open.version,
|
|
125
133
|
});
|
|
134
|
+
openSnapshots.set(open, snapshot);
|
|
135
|
+
return snapshot;
|
|
126
136
|
}
|
|
127
137
|
function uriFor(filename) {
|
|
128
|
-
return openUris.get(fileKey(filename)) ?? pathToFileURL(filename).href;
|
|
138
|
+
return openUris.get(fileKey(filename))?.at(-1) ?? pathToFileURL(filename).href;
|
|
129
139
|
}
|
|
130
140
|
function deepestFirst() {
|
|
131
141
|
return [...folders.values()].sort((left, right) => right.root.length - left.root.length);
|
|
@@ -193,6 +203,7 @@ function startServer(connection) {
|
|
|
193
203
|
}
|
|
194
204
|
refreshCodeLenses();
|
|
195
205
|
}
|
|
206
|
+
const maxDirtySnapshotBytes = 4 * 1024 * 1024;
|
|
196
207
|
function republish(folder) {
|
|
197
208
|
const settings = settingsFor(folder);
|
|
198
209
|
// One read per file for the whole report, however many findings it has.
|
|
@@ -203,11 +214,20 @@ function startServer(connection) {
|
|
|
203
214
|
read.set(key, documentFor(filename));
|
|
204
215
|
return read.get(key);
|
|
205
216
|
};
|
|
217
|
+
const saved = new Map();
|
|
218
|
+
const savedDocumentFor = (filename) => {
|
|
219
|
+
const key = fileKey(filename);
|
|
220
|
+
if (!saved.has(key))
|
|
221
|
+
saved.set(key, readDiskDocument(filename, maxDirtySnapshotBytes));
|
|
222
|
+
return saved.get(key);
|
|
223
|
+
};
|
|
206
224
|
folder.entries = [...folder.session.reports()].flatMap(({ source, findings }) => buildDiagnostics(folder.root, source, findings, {
|
|
207
225
|
// A nested folder's own dismissal file decides for its files.
|
|
208
226
|
isDismissed: (entry) => (folderFor(entry.file) ?? folder).dismissals.has(entry),
|
|
209
227
|
severity: settings.severity,
|
|
228
|
+
severityFor: (filename) => settingsFor(folderFor(filename) ?? folder).severity,
|
|
210
229
|
documentFor: cachedDocumentFor,
|
|
230
|
+
savedDocumentFor,
|
|
211
231
|
uriFor,
|
|
212
232
|
}));
|
|
213
233
|
sendDiagnostics();
|
|
@@ -266,7 +286,10 @@ function startServer(connection) {
|
|
|
266
286
|
settings: () => settingsFor(folder),
|
|
267
287
|
log: (text) => connection.console.info(text),
|
|
268
288
|
logError: (text) => connection.console.error(text),
|
|
269
|
-
onReports: () =>
|
|
289
|
+
onReports: () => {
|
|
290
|
+
openSnapshots = new WeakMap();
|
|
291
|
+
republish(folder);
|
|
292
|
+
},
|
|
270
293
|
onStatus: updateProgress,
|
|
271
294
|
}),
|
|
272
295
|
};
|
|
@@ -303,7 +326,7 @@ function startServer(connection) {
|
|
|
303
326
|
let dismissalsChanged = false;
|
|
304
327
|
for (const { filename, type } of changes) {
|
|
305
328
|
for (const folder of foldersFor(filename)) {
|
|
306
|
-
const kind = classifyChange(folder.root, filename, settingsFor(folder).project);
|
|
329
|
+
const kind = classifyChange(folder.root, filename, settingsFor(folder).project, type === FileChangeType.Deleted);
|
|
307
330
|
if (kind === 'ignored')
|
|
308
331
|
continue;
|
|
309
332
|
if (kind === 'dismissals') {
|
|
@@ -336,9 +359,10 @@ function startServer(connection) {
|
|
|
336
359
|
if (filename === undefined)
|
|
337
360
|
return;
|
|
338
361
|
const key = fileKey(filename);
|
|
339
|
-
openUris.
|
|
340
|
-
|
|
341
|
-
|
|
362
|
+
const aliases = openUris.get(key) ?? [];
|
|
363
|
+
openUris.set(key, [...aliases.filter((uri) => uri !== document.uri), document.uri]);
|
|
364
|
+
pendingDiskChecks.set(document.uri, document.version);
|
|
365
|
+
savedVersions.delete(document.uri);
|
|
342
366
|
foldersFor(filename).forEach(republish);
|
|
343
367
|
}
|
|
344
368
|
function documentClosed(uri) {
|
|
@@ -346,10 +370,16 @@ function startServer(connection) {
|
|
|
346
370
|
if (filename === undefined)
|
|
347
371
|
return;
|
|
348
372
|
const key = fileKey(filename);
|
|
349
|
-
openUris.
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
373
|
+
const aliases = openUris.get(key) ?? [];
|
|
374
|
+
const remaining = aliases.filter((open) => open !== uri);
|
|
375
|
+
if (remaining.length)
|
|
376
|
+
openUris.set(key, remaining);
|
|
377
|
+
else
|
|
378
|
+
openUris.delete(key);
|
|
379
|
+
pendingDiskChecks.delete(uri);
|
|
380
|
+
savedVersions.delete(uri);
|
|
381
|
+
if (aliases.at(-1) === uri)
|
|
382
|
+
foldersFor(filename).forEach(republish);
|
|
353
383
|
}
|
|
354
384
|
const context = {
|
|
355
385
|
connection,
|
|
@@ -399,9 +429,15 @@ function startServer(connection) {
|
|
|
399
429
|
const filename = filenameOf(document.uri);
|
|
400
430
|
if (filename === undefined)
|
|
401
431
|
return;
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
432
|
+
// Another alias of the file may hold different text, so its saved record no longer matches disk.
|
|
433
|
+
for (const alias of openUris.get(fileKey(filename)) ?? []) {
|
|
434
|
+
if (alias === document.uri)
|
|
435
|
+
continue;
|
|
436
|
+
pendingDiskChecks.delete(alias);
|
|
437
|
+
savedVersions.delete(alias);
|
|
438
|
+
}
|
|
439
|
+
pendingDiskChecks.delete(document.uri);
|
|
440
|
+
savedVersions.set(document.uri, document.version);
|
|
405
441
|
filesChanged([{ filename, type: FileChangeType.Changed }]);
|
|
406
442
|
});
|
|
407
443
|
connection.onDidChangeWatchedFiles(({ changes }) => filesChanged(watchedFileEvents(changes)));
|
|
@@ -427,10 +463,13 @@ function startServer(connection) {
|
|
|
427
463
|
const document = filename === undefined ? undefined : documentFor(filename);
|
|
428
464
|
if (!document)
|
|
429
465
|
return null;
|
|
430
|
-
const
|
|
466
|
+
const folder = folderFor(document.filename);
|
|
467
|
+
if (!folder)
|
|
468
|
+
return null;
|
|
469
|
+
const hover = hoverFor(document, findings, position, folder.root);
|
|
431
470
|
return hover ? { contents: { kind: 'markdown', value: hover.markdown }, range: hover.range } : null;
|
|
432
471
|
});
|
|
433
|
-
connection.onCodeAction((
|
|
472
|
+
connection.onCodeAction((params) => codeActions(entriesFor(params.textDocument.uri), params, fixWorkspace()));
|
|
434
473
|
connection.onCodeLens(({ textDocument }) => {
|
|
435
474
|
const filename = filenameOf(textDocument.uri);
|
|
436
475
|
const folder = filename === undefined ? undefined : folderFor(filename);
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import os from 'node:os';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { writeManagedConfig } from './managed-config.js';
|
|
4
|
+
import { absoluteSetting } from './setup-server.js';
|
|
4
5
|
function configDirectory(editor) {
|
|
5
6
|
const windows = process.platform === 'win32';
|
|
6
7
|
if (editor === 'nvim') {
|
|
7
|
-
const base = process.env.XDG_CONFIG_HOME || (windows ? process.env.LOCALAPPDATA : undefined);
|
|
8
|
+
const base = absoluteSetting(process.env.XDG_CONFIG_HOME) || (windows ? absoluteSetting(process.env.LOCALAPPDATA) : undefined);
|
|
8
9
|
return path.join(base || path.join(os.homedir(), windows ? 'AppData/Local' : '.config'), process.env.NVIM_APPNAME || 'nvim');
|
|
9
10
|
}
|
|
10
|
-
const base = windows ? process.env.APPDATA : process.env.XDG_CONFIG_HOME;
|
|
11
|
+
const base = windows ? absoluteSetting(process.env.APPDATA) : absoluteSetting(process.env.XDG_CONFIG_HOME);
|
|
11
12
|
return path.join(base || path.join(os.homedir(), windows ? 'AppData/Roaming' : '.config'), editor === 'helix' ? 'helix' : 'loadwise');
|
|
12
13
|
}
|
|
13
14
|
function luaString(value) {
|
|
@@ -5,7 +5,7 @@ import { spawn } from 'node:child_process';
|
|
|
5
5
|
function startPerfWatch({ script, project, cwd, env, onFindings, onError, onExit }) {
|
|
6
6
|
const child = spawn(process.execPath, [script, 'perf', '-p', project, '--watch', '--json'], {
|
|
7
7
|
cwd,
|
|
8
|
-
env,
|
|
8
|
+
env: { ...env, LOADWISE_EDITOR_WATCH_EVENTS: '1' },
|
|
9
9
|
windowsHide: true,
|
|
10
10
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
11
11
|
});
|
|
@@ -18,13 +18,15 @@ function startPerfWatch({ script, project, cwd, env, onFindings, onError, onExit
|
|
|
18
18
|
report = JSON.parse(line);
|
|
19
19
|
}
|
|
20
20
|
catch (error) {
|
|
21
|
-
onError(new Error('Watch mode printed an unreadable report: ' + (error instanceof Error ? error.message : String(error))));
|
|
21
|
+
onError(new Error('Watch mode printed an unreadable report: ' + (error instanceof Error ? error.message : String(error))), true);
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
|
-
if (report
|
|
24
|
+
if (typeof report?.watchError === 'string')
|
|
25
|
+
onError(new Error(report.watchError), true);
|
|
26
|
+
else if (report && Array.isArray(report.findings))
|
|
25
27
|
onFindings(report.findings);
|
|
26
28
|
else
|
|
27
|
-
onError(new Error('Watch mode returned an invalid findings report.'));
|
|
29
|
+
onError(new Error('Watch mode returned an invalid findings report.'), true);
|
|
28
30
|
}
|
|
29
31
|
child.stdout.setEncoding('utf8');
|
|
30
32
|
child.stdout.on('data', (chunk) => {
|
|
@@ -32,7 +34,7 @@ function startPerfWatch({ script, project, cwd, env, onFindings, onError, onExit
|
|
|
32
34
|
return;
|
|
33
35
|
if (pending.length + chunk.length > maxPendingBytes) {
|
|
34
36
|
pending = '';
|
|
35
|
-
onError(new Error('Watch mode output exceeded maximum buffer size.'));
|
|
37
|
+
onError(new Error('Watch mode output exceeded maximum buffer size.'), true);
|
|
36
38
|
child.kill('SIGKILL');
|
|
37
39
|
return;
|
|
38
40
|
}
|
|
@@ -50,7 +52,7 @@ function startPerfWatch({ script, project, cwd, env, onFindings, onError, onExit
|
|
|
50
52
|
if (child.killed)
|
|
51
53
|
return;
|
|
52
54
|
if (text.trim())
|
|
53
|
-
onError(new Error(text.trim()));
|
|
55
|
+
onError(new Error(text.trim()), false);
|
|
54
56
|
});
|
|
55
57
|
function finish(error) {
|
|
56
58
|
if (stopped)
|
|
@@ -23,6 +23,11 @@ const examples = {
|
|
|
23
23
|
code: "const lines = fs.readFileSync(path, 'utf8').split(/\\r?\\n/);\nconst start = lines.indexOf('## [Unreleased]');",
|
|
24
24
|
note: "With CRLF line endings terminated lines keep a trailing '\\r', so the exact match never finds the heading.",
|
|
25
25
|
},
|
|
26
|
+
'db-pool-client-not-released': {
|
|
27
|
+
before: 'const client = await pool.connect();\nawait readOrders(client);\nclient.release();',
|
|
28
|
+
code: 'const client = await pool.connect();\ntry {\n await readOrders(client);\n} finally {\n client.release();\n}',
|
|
29
|
+
note: 'A failure before release can leave one of the pool connections checked out.',
|
|
30
|
+
},
|
|
26
31
|
'error-logged-without-stack': {
|
|
27
32
|
before: 'try {\n await sync();\n} catch (error) {\n logger.error(error.message);\n}',
|
|
28
33
|
code: "try {\n await sync();\n} catch (error) {\n logger.error({ err: error }, 'sync failed');\n}",
|
|
@@ -68,6 +73,16 @@ const examples = {
|
|
|
68
73
|
code: "let entries = [];\ntry {\n entries = JSON.parse(fs.readFileSync(file, 'utf8'));\n} catch (error) {\n if (error.code !== 'ENOENT') throw error; }\nfs.writeFileSync(file, JSON.stringify([...entries, entry]));",
|
|
69
74
|
note: 'A file that fails to parse would be overwritten with the default, losing everything it held.',
|
|
70
75
|
},
|
|
76
|
+
'pg-advisory-lock-session': {
|
|
77
|
+
before: "await pool.query('SELECT pg_advisory_lock($1)', [key]);\nawait updateOrders();",
|
|
78
|
+
code: "const client = await pool.connect();\ntry { await client.query('SELECT pg_advisory_lock($1)', [key]); await updateOrders(); }\nfinally {\n try { await client.query('SELECT pg_advisory_unlock($1)', [key]); }\n catch (error) { client.release(true); throw error; }\n client.release(); }",
|
|
79
|
+
note: 'Use the same PostgreSQL connection for the lock and its cleanup.',
|
|
80
|
+
},
|
|
81
|
+
'pg-listen-session': {
|
|
82
|
+
before: "await pool.query('LISTEN jobs');",
|
|
83
|
+
code: "const client = await pool.connect();\ntry { await client.query('LISTEN jobs'); await listenUntilStopped(client); }\nfinally {\n try { await client.query('UNLISTEN jobs'); }\n catch (error) { client.release(true); throw error; }\n client.release(); }",
|
|
84
|
+
note: 'Retain the client until the listener stops, then unsubscribe before returning it.',
|
|
85
|
+
},
|
|
71
86
|
'pool-without-connection-timeout': {
|
|
72
87
|
before: 'const pool = new Pool({ connectionString });',
|
|
73
88
|
code: 'const pool = new Pool({ connectionString, connectionTimeoutMillis: 5000 });',
|
|
@@ -13,6 +13,7 @@ import { isMarkupFile } from '../accessibility/markup-files.js';
|
|
|
13
13
|
import { listenForEditorRefresh } from '../performance/cli/editor-signal.js';
|
|
14
14
|
import { hasInfrastructureFiles } from '../security/files/index.js';
|
|
15
15
|
import { configlessSources, coveringConfig, hasWorkspaceSources } from '../shared/workspaces.js';
|
|
16
|
+
import { isRecord } from '../shared/system/is-record.js';
|
|
16
17
|
const run = promisify(execFile);
|
|
17
18
|
const debounceMs = 650;
|
|
18
19
|
const maxReportBytes = 64 * 1024 * 1024;
|
|
@@ -42,6 +43,13 @@ async function firstExisting(root, names) {
|
|
|
42
43
|
if (await exists(path.join(root, name)))
|
|
43
44
|
return name;
|
|
44
45
|
}
|
|
46
|
+
function parseFindings(stdout) {
|
|
47
|
+
const report = JSON.parse(stdout);
|
|
48
|
+
if (!Array.isArray(report?.findings) ||
|
|
49
|
+
!report.findings.every((item) => isRecord(item) && typeof item.ruleId === 'string' && typeof item.message === 'string'))
|
|
50
|
+
throw new Error('Checker returned an invalid findings report.');
|
|
51
|
+
return report.findings;
|
|
52
|
+
}
|
|
45
53
|
async function readFindings(script, args, cwd, signal) {
|
|
46
54
|
const options = {
|
|
47
55
|
cwd,
|
|
@@ -57,15 +65,24 @@ async function readFindings(script, args, cwd, signal) {
|
|
|
57
65
|
}
|
|
58
66
|
catch (error) {
|
|
59
67
|
const failure = execFailureOf(error);
|
|
60
|
-
|
|
68
|
+
if (failure.code === 2) {
|
|
69
|
+
// Exit 2 can mean partial coverage or a failed invocation. Only a valid report is usable.
|
|
70
|
+
try {
|
|
71
|
+
return {
|
|
72
|
+
findings: parseFindings(failure.stdout ?? ''),
|
|
73
|
+
coverageNote: failure.stderr?.trim() || 'The checker reported incomplete coverage.',
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
catch (parseError) {
|
|
77
|
+
throw new Error(failure.stderr?.trim() || messageOf(parseError), { cause: error });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// Exit 1 means findings met the exit threshold; the report is complete.
|
|
61
81
|
if (failure.code !== 1)
|
|
62
82
|
throw new Error(failure.stderr?.trim() || failure.message, { cause: error });
|
|
63
83
|
stdout = failure.stdout ?? '';
|
|
64
84
|
}
|
|
65
|
-
|
|
66
|
-
if (!Array.isArray(report.findings))
|
|
67
|
-
throw new Error('Checker returned an invalid findings report.');
|
|
68
|
-
return report.findings;
|
|
85
|
+
return { findings: parseFindings(stdout) };
|
|
69
86
|
}
|
|
70
87
|
// A project setting is used only when it stays inside the folder and cannot be read as a flag.
|
|
71
88
|
function explicitProject(root, setting) {
|
|
@@ -182,10 +199,11 @@ function createScanSession(options) {
|
|
|
182
199
|
current.pending = false;
|
|
183
200
|
show(perf, perf, findings);
|
|
184
201
|
},
|
|
185
|
-
onError(error) {
|
|
202
|
+
onError(error, reportUnavailable) {
|
|
186
203
|
if (perfWatch !== current)
|
|
187
204
|
return;
|
|
188
|
-
|
|
205
|
+
if (reportUnavailable)
|
|
206
|
+
clear(perf);
|
|
189
207
|
current.pending = false;
|
|
190
208
|
logError(perf, error.message);
|
|
191
209
|
options.onStatus();
|
|
@@ -195,6 +213,7 @@ function createScanSession(options) {
|
|
|
195
213
|
return;
|
|
196
214
|
perfWatch = undefined;
|
|
197
215
|
watchUnavailable = true;
|
|
216
|
+
clear(perf);
|
|
198
217
|
logError(perf, error.message + ' Falling back to full rescans after each change.');
|
|
199
218
|
schedule();
|
|
200
219
|
},
|
|
@@ -225,9 +244,11 @@ function createScanSession(options) {
|
|
|
225
244
|
throw new Error('The loadwise.cli setting must be an absolute path.');
|
|
226
245
|
if (task.watchProject !== undefined)
|
|
227
246
|
return ensureWatch(script, task.watchProject, restart);
|
|
228
|
-
const findings = await readFindings(script, task.args, root, scanSignal);
|
|
247
|
+
const { findings, coverageNote } = await readFindings(script, task.args, root, scanSignal);
|
|
229
248
|
if (scanSignal.aborted || disposed.signal.aborted)
|
|
230
249
|
return;
|
|
250
|
+
if (coverageNote)
|
|
251
|
+
logError(task.id, coverageNote);
|
|
231
252
|
show(task.id, task.source, task.markupOnly ? findings.filter(({ file }) => file !== undefined && isMarkupFile(file)) : findings);
|
|
232
253
|
}
|
|
233
254
|
async function scan(version, scanSignal) {
|
|
@@ -51,6 +51,8 @@ function dismissalArgument(context, value) {
|
|
|
51
51
|
const entry = { file: value.file, ruleId: value.ruleId };
|
|
52
52
|
if (typeof value.lineText === 'string')
|
|
53
53
|
entry.lineText = value.lineText;
|
|
54
|
+
if (typeof value.occurrence === 'string' && typeof value.lineText === 'string')
|
|
55
|
+
entry.occurrence = value.occurrence;
|
|
54
56
|
return { folder, entry };
|
|
55
57
|
}
|
|
56
58
|
// Returns the folders it made, so a rejected edit leaves none behind.
|
|
@@ -182,7 +184,15 @@ async function restore(context, restored) {
|
|
|
182
184
|
function describe({ folder, entry }, index) {
|
|
183
185
|
const file = path.relative(folder.root, entry.file).split(path.sep).join('/');
|
|
184
186
|
const line = typeof entry.lineText === 'string' ? entry.lineText || '(blank line)' : 'Whole file';
|
|
185
|
-
return index +
|
|
187
|
+
return (index +
|
|
188
|
+
1 +
|
|
189
|
+
'. ' +
|
|
190
|
+
entry.ruleId +
|
|
191
|
+
' — ' +
|
|
192
|
+
file +
|
|
193
|
+
' — ' +
|
|
194
|
+
line +
|
|
195
|
+
(entry.occurrence && entry.occurrence !== '1/1' ? ' (' + entry.occurrence.split('#')[0] + ')' : ''));
|
|
186
196
|
}
|
|
187
197
|
async function showDismissed(context) {
|
|
188
198
|
const { window } = context.connection;
|
|
@@ -190,16 +200,33 @@ async function showDismissed(context) {
|
|
|
190
200
|
if (!dismissed.length)
|
|
191
201
|
return window.showInformationMessage('No Loadwise findings are dismissed.');
|
|
192
202
|
const restoreAll = { title: 'Restore all (' + dismissed.length + ')' };
|
|
193
|
-
const restoreOne = dismissed.slice(0, maxRestoreButtons).map((_item, index) => ({ title: 'Restore ' + (index + 1) }));
|
|
194
203
|
const message = ['Dismissed Loadwise findings:', ...dismissed.map(describe)].join('\n');
|
|
195
|
-
|
|
196
|
-
|
|
204
|
+
let offset = 0;
|
|
205
|
+
for (;;) {
|
|
206
|
+
const page = dismissed.slice(offset, offset + maxRestoreButtons);
|
|
207
|
+
const restoreOne = page.map((_item, index) => ({ title: 'Restore ' + (offset + index + 1) }));
|
|
208
|
+
const navButtons = [
|
|
209
|
+
...(offset > 0 ? [{ title: 'Previous' }] : []),
|
|
210
|
+
...(offset + maxRestoreButtons < dismissed.length ? [{ title: 'Next' }] : []),
|
|
211
|
+
];
|
|
212
|
+
const picked = await window.showInformationMessage(message, restoreAll, ...restoreOne, ...navButtons);
|
|
213
|
+
if (!picked)
|
|
214
|
+
return;
|
|
215
|
+
if (picked === restoreAll || picked.title === restoreAll.title)
|
|
216
|
+
return restore(context, dismissed);
|
|
217
|
+
if (picked.title === 'Next') {
|
|
218
|
+
offset += maxRestoreButtons;
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
if (picked.title === 'Previous') {
|
|
222
|
+
offset = Math.max(0, offset - maxRestoreButtons);
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
const index = restoreOne.findIndex((action) => action.title === picked.title);
|
|
226
|
+
if (index !== -1)
|
|
227
|
+
return restore(context, [dismissed[offset + index]]);
|
|
197
228
|
return;
|
|
198
|
-
|
|
199
|
-
return restore(context, dismissed);
|
|
200
|
-
const index = restoreOne.findIndex((action) => action.title === picked.title);
|
|
201
|
-
if (index !== -1)
|
|
202
|
-
await restore(context, [dismissed[index]]);
|
|
229
|
+
}
|
|
203
230
|
}
|
|
204
231
|
// With a dismissal entry it restores that one; without arguments it restores every dismissal.
|
|
205
232
|
async function restoreDismissed(context, value) {
|
|
@@ -13,7 +13,7 @@ export function editorDataDirectory() {
|
|
|
13
13
|
return path.join(home, 'Library', 'Application Support', 'loadwise', 'editor');
|
|
14
14
|
return path.join(absoluteSetting(process.env.XDG_DATA_HOME) ?? path.join(home, '.local', 'share'), 'loadwise', 'editor');
|
|
15
15
|
}
|
|
16
|
-
function absoluteSetting(value) {
|
|
16
|
+
export function absoluteSetting(value) {
|
|
17
17
|
return value && path.isAbsolute(value) ? value : undefined;
|
|
18
18
|
}
|
|
19
19
|
async function npmCommand() {
|
|
@@ -3,7 +3,7 @@ import fs from 'node:fs';
|
|
|
3
3
|
import os from 'node:os';
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import { writeManagedConfig } from './managed-config.js';
|
|
6
|
-
import { ensureEditorServer } from './setup-server.js';
|
|
6
|
+
import { absoluteSetting, ensureEditorServer } from './setup-server.js';
|
|
7
7
|
function unixVimOnWindows() {
|
|
8
8
|
const vim = (process.env.PATH ?? '')
|
|
9
9
|
.split(path.delimiter)
|
|
@@ -16,12 +16,14 @@ function unixVimOnWindows() {
|
|
|
16
16
|
const version = spawnSync(vim, ['--version'], { encoding: 'utf8', windowsHide: true, timeout: 5_000 });
|
|
17
17
|
return version.status === 0 && version.stdout.includes('$HOME/.vimrc');
|
|
18
18
|
}
|
|
19
|
-
function vimDirectory() {
|
|
20
|
-
const home = process.env.HOME || os.homedir();
|
|
19
|
+
export function vimDirectory() {
|
|
20
|
+
const home = absoluteSetting(process.env.HOME) || absoluteSetting(os.homedir());
|
|
21
|
+
if (!home)
|
|
22
|
+
throw new Error('HOME must be an absolute path to install the Vim plugin.');
|
|
21
23
|
if (process.platform === 'win32' && !unixVimOnWindows())
|
|
22
24
|
return path.join(home, 'vimfiles');
|
|
23
25
|
const traditional = path.join(home, '.vim');
|
|
24
|
-
const xdg = path.join(process.env.XDG_CONFIG_HOME || path.join(home, '.config'), 'vim');
|
|
26
|
+
const xdg = path.join(absoluteSetting(process.env.XDG_CONFIG_HOME) || path.join(home, '.config'), 'vim');
|
|
25
27
|
if (fs.existsSync(path.join(home, '.vimrc')) || fs.existsSync(path.join(traditional, 'vimrc')))
|
|
26
28
|
return traditional;
|
|
27
29
|
return fs.existsSync(path.join(xdg, 'vimrc')) ? xdg : traditional;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// Which files of a workspace folder feed the checkers, and so which changes trigger a rescan.
|
|
2
2
|
import fs from 'node:fs/promises';
|
|
3
|
+
import { existsSync, readdirSync } from 'node:fs';
|
|
3
4
|
import path from 'node:path';
|
|
4
5
|
import { dismissalsPath } from './dismissals.js';
|
|
6
|
+
import { samePathSpelling } from './workspace-paths.js';
|
|
5
7
|
import { isNamedConfigFile } from '../security/files/index.js';
|
|
6
8
|
const sourceSuffixes = new Set('js jsx ts tsx mjs mts cjs cts py go java cs rs rb php kt kts c h cc cpp cxx hpp hh hxx'.split(' '));
|
|
7
9
|
const polyglotSuffixes = new Set(['py', 'go', 'java', 'cs', 'rs']);
|
|
@@ -37,19 +39,71 @@ const watchedGlobs = [
|
|
|
37
39
|
function suffixOf(filename) {
|
|
38
40
|
return path.extname(filename).slice(1).toLowerCase();
|
|
39
41
|
}
|
|
42
|
+
// An entry inside the directory with letters in its name shows whether lookups there fold case. A
|
|
43
|
+
// case-sensitive directory can sit inside a case-insensitive parent, so the parent proves nothing.
|
|
44
|
+
function foldsCase(directory) {
|
|
45
|
+
let names;
|
|
46
|
+
try {
|
|
47
|
+
names = readdirSync(directory);
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
const listed = new Set(names);
|
|
53
|
+
for (const base of names) {
|
|
54
|
+
const swapped = base === base.toLowerCase() ? base.toUpperCase() : base.toLowerCase();
|
|
55
|
+
// Both spellings listed means two separate entries (an alias symlink), not one folded name.
|
|
56
|
+
if (swapped !== base && !listed.has(swapped))
|
|
57
|
+
return samePathSpelling(path.join(directory, base), path.join(directory, swapped));
|
|
58
|
+
}
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
function matchesPathName(parent, name, matches) {
|
|
62
|
+
if (matches(name))
|
|
63
|
+
return true;
|
|
64
|
+
const lower = name.toLowerCase();
|
|
65
|
+
return name !== lower && matches(lower) && samePathSpelling(path.join(parent, name), path.join(parent, lower));
|
|
66
|
+
}
|
|
67
|
+
function configName(name) {
|
|
68
|
+
return configPatterns.some((pattern) => pattern.test(name));
|
|
69
|
+
}
|
|
40
70
|
// `project` is the folder's loadwise.project setting, which can name a config of any file name.
|
|
41
|
-
function classifyChange(root, filename, project = '') {
|
|
71
|
+
function classifyChange(root, filename, project = '', deleted = false) {
|
|
42
72
|
const relative = path.relative(root, filename);
|
|
43
|
-
|
|
73
|
+
const isDismissalsSpelling = relative.toLowerCase() === dismissalsPath;
|
|
74
|
+
const store = path.join(root, dismissalsPath);
|
|
75
|
+
if (isDismissalsSpelling && samePathSpelling(store, filename))
|
|
76
|
+
return 'dismissals';
|
|
77
|
+
if (project.trim()) {
|
|
78
|
+
const configured = path.resolve(root, project.trim());
|
|
79
|
+
if (samePathSpelling(configured, filename))
|
|
80
|
+
return 'config';
|
|
81
|
+
if (deleted && configured.toLowerCase() === filename.toLowerCase() && !existsSync(configured))
|
|
82
|
+
return 'config';
|
|
83
|
+
}
|
|
84
|
+
// After deletion neither spelling exists to compare. Reloading the absent store clears stale decisions.
|
|
85
|
+
if (isDismissalsSpelling && !existsSync(filename) && !existsSync(store))
|
|
44
86
|
return 'dismissals';
|
|
45
|
-
if (project.trim() && path.relative(path.resolve(root, project.trim()), filename) === '')
|
|
46
|
-
return 'config';
|
|
47
87
|
const segments = relative.split(path.sep);
|
|
48
|
-
|
|
49
|
-
|
|
88
|
+
let parent = root;
|
|
89
|
+
let migration = false;
|
|
90
|
+
for (const segment of segments.slice(0, -1)) {
|
|
91
|
+
if (matchesPathName(parent, segment, (name) => ignoredFolders.has(name)))
|
|
92
|
+
return 'ignored';
|
|
93
|
+
migration ||= matchesPathName(parent, segment, (name) => name === 'migrations');
|
|
94
|
+
parent = path.join(parent, segment);
|
|
95
|
+
}
|
|
50
96
|
const name = path.basename(filename);
|
|
51
|
-
if (
|
|
97
|
+
if (matchesPathName(parent, name, configName) || migration)
|
|
98
|
+
return 'config';
|
|
99
|
+
// A removed file can no longer establish its identity. On a case-folding filesystem a missing
|
|
100
|
+
// lower-case config is the same path; a surviving one is distinct.
|
|
101
|
+
if (deleted &&
|
|
102
|
+
configName(name.toLowerCase()) &&
|
|
103
|
+
foldsCase(parent) &&
|
|
104
|
+
!existsSync(path.join(parent, name.toLowerCase()))) {
|
|
52
105
|
return 'config';
|
|
106
|
+
}
|
|
53
107
|
const suffix = suffixOf(filename);
|
|
54
108
|
if (sourceSuffixes.has(suffix) || markupSuffixes.has(suffix))
|
|
55
109
|
return 'source';
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// server writes, or asks the editor to write, also resolves symbolic links, so a link inside the
|
|
3
3
|
// folder cannot send the write elsewhere.
|
|
4
4
|
import path from 'node:path';
|
|
5
|
+
import fs from 'node:fs';
|
|
5
6
|
import { realTarget } from '../shared/system/real-target.js';
|
|
6
7
|
function isInside(root, filename) {
|
|
7
8
|
const relative = path.relative(root, filename);
|
|
@@ -19,4 +20,43 @@ function isRealPathInside(root, filename) {
|
|
|
19
20
|
return false;
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
|
-
|
|
23
|
+
function hasSeparatelyListedComponent(left, right) {
|
|
24
|
+
let leftPart = left;
|
|
25
|
+
let rightPart = right;
|
|
26
|
+
while (true) {
|
|
27
|
+
const leftParent = path.dirname(leftPart);
|
|
28
|
+
const rightParent = path.dirname(rightPart);
|
|
29
|
+
const leftName = path.basename(leftPart);
|
|
30
|
+
const rightName = path.basename(rightPart);
|
|
31
|
+
if (leftName !== rightName) {
|
|
32
|
+
const leftListed = fs.readdirSync(leftParent);
|
|
33
|
+
const rightListed = leftParent === rightParent ? leftListed : fs.readdirSync(rightParent);
|
|
34
|
+
if (leftListed.includes(leftName) && rightListed.includes(rightName))
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
if (leftParent === leftPart || rightParent === rightPart)
|
|
38
|
+
return false;
|
|
39
|
+
leftPart = leftParent;
|
|
40
|
+
rightPart = rightParent;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/** Compare alternate case spellings only when both names refer to the same native file. */
|
|
44
|
+
function samePathSpelling(left, right) {
|
|
45
|
+
if (left === right)
|
|
46
|
+
return true;
|
|
47
|
+
if (left.toLowerCase() !== right.toLowerCase())
|
|
48
|
+
return false;
|
|
49
|
+
try {
|
|
50
|
+
// A component spelled two ways and listed under each spelling is a separate entry (an alias
|
|
51
|
+
// symlink or a distinct folder), not one folded name, wherever it sits in the path.
|
|
52
|
+
if (hasSeparatelyListedComponent(left, right))
|
|
53
|
+
return false;
|
|
54
|
+
const first = fs.statSync(left, { bigint: true });
|
|
55
|
+
const second = fs.statSync(right, { bigint: true });
|
|
56
|
+
return first.ino !== 0n && first.ino === second.ino && first.dev === second.dev;
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
export { isInside, isRealPathInside, samePathSpelling };
|
|
@@ -75,7 +75,7 @@ function analyzeSource(root, file, text, resolve, options = {}) {
|
|
|
75
75
|
generated,
|
|
76
76
|
duplicates: extractImplementations(source, file, generated),
|
|
77
77
|
findings: [
|
|
78
|
-
...analyzeFunctions(source, file),
|
|
78
|
+
...analyzeFunctions(source, file, limits),
|
|
79
79
|
...accessFindings,
|
|
80
80
|
...checkSizeLimits(source, file, limits, generated),
|
|
81
81
|
...checkUnusedBindings(source, file, compilerOptions ?? {}),
|