loadwise 0.6.2 → 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 +175 -115
- package/dist/bin/loadwise.js +132 -67
- 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/frontend-detect.js +6 -5
- 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/accessibility/usage.js +10 -2
- 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 +63 -0
- 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 +170 -0
- package/dist/lib/editor/fix-edits.js +19 -0
- package/dist/lib/editor/jetbrains-setup.js +53 -0
- package/dist/lib/editor/language-server.js +80 -24
- package/dist/lib/editor/managed-config.js +37 -0
- package/dist/lib/editor/native-setup.js +86 -0
- package/dist/lib/editor/perf-watch.js +8 -6
- package/dist/lib/editor/release-vsix.js +61 -0
- 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 +38 -9
- package/dist/lib/editor/setup-server.js +87 -0
- package/dist/lib/editor/setup-vim.js +63 -0
- package/dist/lib/editor/setup.js +131 -0
- package/dist/lib/editor/stdio-setup.js +6 -0
- 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 +12 -3
- package/dist/lib/maintainability/cli.js +18 -5
- 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/examples.js +4 -0
- 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/rule-ids.js +3 -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/site-fixes/unused-bindings.js +138 -3
- package/dist/lib/maintainability/unused/module-usage.js +43 -21
- package/dist/lib/maintainability/unused/unused-bindings.js +39 -4
- 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/changed-lines.js +8 -1
- package/dist/lib/performance/cli/cli-arguments.js +19 -8
- package/dist/lib/performance/cli/cli-output.js +4 -0
- package/dist/lib/performance/cli/cli-scan.js +21 -2
- package/dist/lib/performance/cli.js +16 -7
- 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 +68 -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 +62 -3
- 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-syntax.js +3 -0
- 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 +149 -74
- 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/bulk-listener-registration.js +111 -0
- package/dist/lib/performance/request/fastify-receivers.js +93 -0
- package/dist/lib/performance/request/fresh-loop-socket.js +103 -0
- package/dist/lib/performance/request/mongoose-lean.js +298 -46
- package/dist/lib/performance/request/node-event-listener-leak.js +99 -5
- package/dist/lib/performance/request/phase5-ast.js +6 -7
- package/dist/lib/performance/request/phase5-rules.js +204 -23
- package/dist/lib/performance/request/request-handlers.js +120 -23
- 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/collection-existence.js +2 -1
- package/dist/lib/performance/site-fixes/collections.js +1 -2
- package/dist/lib/performance/site-fixes/frontend-fixes.js +358 -14
- package/dist/lib/performance/site-fixes/helpers.js +3 -4
- package/dist/lib/performance/site-fixes/integrity.js +2 -4
- 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 +29 -7
- 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/usage.js +16 -5
- 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 +21 -6
- 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 +28 -5
- package/dist/lib/shared/agent/agent-prompt.js +74 -0
- package/dist/lib/shared/agent/agent-session.js +6 -1
- package/dist/lib/shared/agent/agent-verify.js +58 -11
- package/dist/lib/shared/agent/git-hook.js +17 -6
- package/dist/lib/shared/agent/review-delivery.js +1 -1
- 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 +99 -14
- package/dist/lib/shared/check.js +172 -20
- 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 +19 -31
- package/dist/lib/shared/fix/fix-handoff.js +16 -11
- package/dist/lib/shared/fix/fix-imports.js +4 -162
- package/dist/lib/shared/fix/fix-presentation-comments.js +23 -9
- package/dist/lib/shared/fix/fix-presentation-prettier.js +1 -46
- package/dist/lib/shared/fix/fix-presentation-rows.js +45 -1
- package/dist/lib/shared/fix/fix-presentation.js +9 -6
- package/dist/lib/shared/fix/fix-safety.js +32 -1
- package/dist/lib/shared/fix/fix-scope.js +82 -0
- package/dist/lib/shared/fix/fix-terminal.js +28 -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/project-file-access.js +17 -26
- package/dist/lib/shared/fix/read-fix-text.js +20 -0
- package/dist/lib/shared/fix.js +241 -104
- 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 +97 -0
- package/dist/lib/shared/reporting/automatic-fix-signal.js +10 -0
- package/dist/lib/shared/reporting/baseline.js +7 -5
- package/dist/lib/shared/reporting/check-text.js +50 -0
- package/dist/lib/shared/reporting/pillars.js +54 -19
- package/dist/lib/shared/reporting/source-report.js +3 -0
- package/dist/lib/shared/system/atomic-write.js +5 -2
- package/dist/lib/shared/system/glob.js +34 -8
- package/dist/lib/shared/system/sentry.js +222 -0
- package/dist/lib/shared/system/shell-argument.js +5 -1
- package/dist/lib/shared/system/terminal-safe.js +3 -2
- package/dist/lib/shared/system/terminal-style.js +131 -0
- package/dist/lib/shared/workspaces.js +15 -3
- package/docs/assets/cli-workflow.gif +0 -0
- package/integrations/sublime/plugin.py +22 -0
- package/integrations/zed/Cargo.lock +845 -0
- package/integrations/zed/Cargo.toml +11 -0
- package/integrations/zed/extension.toml +11 -0
- package/integrations/zed/src/lib.rs +25 -0
- package/package.json +15 -3
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/commands/loadwise.md +11 -6
- 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 +556 -76
- /package/polyglot/{performance/rules → shared-rules}/input.yml +0 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { access, mkdir, mkdtemp, rename, rm, stat } from 'node:fs/promises';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { promisify } from 'node:util';
|
|
6
|
+
import { packageManifest, packageRoot } from '../shared/package-root.js';
|
|
7
|
+
const execute = promisify(execFile);
|
|
8
|
+
export function editorDataDirectory() {
|
|
9
|
+
const home = os.homedir();
|
|
10
|
+
if (process.platform === 'win32')
|
|
11
|
+
return path.join(absoluteSetting(process.env.LOCALAPPDATA) ?? path.join(home, 'AppData', 'Local'), 'loadwise', 'editor');
|
|
12
|
+
if (process.platform === 'darwin')
|
|
13
|
+
return path.join(home, 'Library', 'Application Support', 'loadwise', 'editor');
|
|
14
|
+
return path.join(absoluteSetting(process.env.XDG_DATA_HOME) ?? path.join(home, '.local', 'share'), 'loadwise', 'editor');
|
|
15
|
+
}
|
|
16
|
+
export function absoluteSetting(value) {
|
|
17
|
+
return value && path.isAbsolute(value) ? value : undefined;
|
|
18
|
+
}
|
|
19
|
+
async function npmCommand() {
|
|
20
|
+
const currentNpm = absoluteSetting(process.env.npm_execpath);
|
|
21
|
+
if (currentNpm && path.basename(currentNpm) === 'npm-cli.js' && (await isFile(currentNpm)))
|
|
22
|
+
return [process.execPath, currentNpm];
|
|
23
|
+
if (process.platform !== 'win32')
|
|
24
|
+
return ['npm'];
|
|
25
|
+
// Launch the npm JavaScript entry directly so paths never need cmd.exe quoting.
|
|
26
|
+
const directories = [
|
|
27
|
+
path.dirname(process.execPath),
|
|
28
|
+
...(process.env.PATH || '').split(path.delimiter).filter(path.isAbsolute),
|
|
29
|
+
];
|
|
30
|
+
const candidates = directories.map((directory) => path.join(directory, 'node_modules', 'npm', 'bin', 'npm-cli.js'));
|
|
31
|
+
for (const candidate of candidates) {
|
|
32
|
+
if (await isFile(candidate))
|
|
33
|
+
return [process.execPath, candidate];
|
|
34
|
+
}
|
|
35
|
+
throw new Error('Loadwise editor setup needs npm to prepare the language server. Install npm alongside Node.js and rerun setup.');
|
|
36
|
+
}
|
|
37
|
+
async function isFile(filename) {
|
|
38
|
+
return stat(filename).then((entry) => entry.isFile(), () => false);
|
|
39
|
+
}
|
|
40
|
+
export async function ensureEditorServer() {
|
|
41
|
+
const versions = path.join(editorDataDirectory(), 'servers');
|
|
42
|
+
const destination = path.join(versions, [packageManifest.version, process.platform, process.arch].join('-'));
|
|
43
|
+
const cli = path.join('node_modules', 'loadwise', 'dist', 'bin', 'loadwise.js');
|
|
44
|
+
const command = {
|
|
45
|
+
command: process.execPath,
|
|
46
|
+
args: [path.join(destination, cli), 'lsp', '--stdio'],
|
|
47
|
+
};
|
|
48
|
+
if (await isFile(command.args[0]))
|
|
49
|
+
return command;
|
|
50
|
+
await mkdir(versions, { recursive: true });
|
|
51
|
+
const stage = await mkdtemp(path.join(versions, '.install-'));
|
|
52
|
+
try {
|
|
53
|
+
const [executable, ...prefix] = await npmCommand();
|
|
54
|
+
// install-links packs the running distribution, including an unreleased checkout or npx install,
|
|
55
|
+
// into the destination instead of linking back to an evictable package cache.
|
|
56
|
+
await execute(executable, [
|
|
57
|
+
...prefix,
|
|
58
|
+
'install',
|
|
59
|
+
'--prefix',
|
|
60
|
+
stage,
|
|
61
|
+
'--install-links',
|
|
62
|
+
'--global=false',
|
|
63
|
+
'--prefer-offline',
|
|
64
|
+
'--omit=dev',
|
|
65
|
+
'--include=optional',
|
|
66
|
+
'--ignore-scripts',
|
|
67
|
+
'--no-bin-links',
|
|
68
|
+
'--no-audit',
|
|
69
|
+
'--no-fund',
|
|
70
|
+
'--no-save',
|
|
71
|
+
packageRoot,
|
|
72
|
+
], { cwd: stage, windowsHide: true });
|
|
73
|
+
await access(path.join(stage, cli));
|
|
74
|
+
try {
|
|
75
|
+
await rename(stage, destination);
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
// Concurrent setups may finish the same immutable version while this one is preparing it.
|
|
79
|
+
if (!(await isFile(command.args[0])))
|
|
80
|
+
throw error;
|
|
81
|
+
}
|
|
82
|
+
return command;
|
|
83
|
+
}
|
|
84
|
+
finally {
|
|
85
|
+
await rm(stage, { recursive: true, force: true });
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { writeManagedConfig } from './managed-config.js';
|
|
6
|
+
import { absoluteSetting, ensureEditorServer } from './setup-server.js';
|
|
7
|
+
function unixVimOnWindows() {
|
|
8
|
+
const vim = (process.env.PATH ?? '')
|
|
9
|
+
.split(path.delimiter)
|
|
10
|
+
.filter((directory) => path.isAbsolute(directory))
|
|
11
|
+
.map((directory) => path.join(directory, 'vim.exe'))
|
|
12
|
+
.find((file) => fs.statSync(file, { throwIfNoEntry: false })?.isFile());
|
|
13
|
+
if (!vim)
|
|
14
|
+
return false;
|
|
15
|
+
// MSYS Vim uses ~/.vim just like Unix Vim. Native Windows Vim uses ~/vimfiles.
|
|
16
|
+
const version = spawnSync(vim, ['--version'], { encoding: 'utf8', windowsHide: true, timeout: 5_000 });
|
|
17
|
+
return version.status === 0 && version.stdout.includes('$HOME/.vimrc');
|
|
18
|
+
}
|
|
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.');
|
|
23
|
+
if (process.platform === 'win32' && !unixVimOnWindows())
|
|
24
|
+
return path.join(home, 'vimfiles');
|
|
25
|
+
const traditional = path.join(home, '.vim');
|
|
26
|
+
const xdg = path.join(absoluteSetting(process.env.XDG_CONFIG_HOME) || path.join(home, '.config'), 'vim');
|
|
27
|
+
if (fs.existsSync(path.join(home, '.vimrc')) || fs.existsSync(path.join(traditional, 'vimrc')))
|
|
28
|
+
return traditional;
|
|
29
|
+
return fs.existsSync(path.join(xdg, 'vimrc')) ? xdg : traditional;
|
|
30
|
+
}
|
|
31
|
+
export function writeVimPlugin(directory, server) {
|
|
32
|
+
const filename = path.join(directory, 'plugin', 'loadwise.vim');
|
|
33
|
+
const command = JSON.stringify([server.command, ...server.args]).replaceAll("'", "''");
|
|
34
|
+
const contents = [
|
|
35
|
+
'function! s:project_root(server_info) abort',
|
|
36
|
+
" let root = lsp#utils#find_nearest_parent_file_directory(lsp#utils#get_buffer_path(), ['loadwise.config.json', 'tsconfig.json', 'jsconfig.json', 'package.json', '.git/'])",
|
|
37
|
+
" return lsp#utils#path_to_uri(empty(root) ? expand('%:p:h') : root)",
|
|
38
|
+
'endfunction',
|
|
39
|
+
'',
|
|
40
|
+
'function! s:register() abort',
|
|
41
|
+
" if index(lsp#get_server_names(), 'loadwise') >= 0 | return | endif",
|
|
42
|
+
' call lsp#register_server({',
|
|
43
|
+
" \\ 'name': 'loadwise',",
|
|
44
|
+
` \\ 'cmd': json_decode('${command}'),`,
|
|
45
|
+
" \\ 'root_uri': function('s:project_root'),",
|
|
46
|
+
" \\ 'allowlist': ['javascript', 'javascriptreact', 'typescript', 'typescriptreact', 'html', 'vue', 'svelte', 'python', 'go', 'java', 'cs', 'rust', 'ruby', 'php', 'kotlin', 'c', 'cpp'],",
|
|
47
|
+
' \\ })',
|
|
48
|
+
'endfunction',
|
|
49
|
+
'',
|
|
50
|
+
'augroup loadwise_vim_lsp',
|
|
51
|
+
' autocmd!',
|
|
52
|
+
' autocmd User lsp_setup call s:register()',
|
|
53
|
+
'augroup END',
|
|
54
|
+
'',
|
|
55
|
+
].join('\n');
|
|
56
|
+
if (writeManagedConfig(filename, '"', contents) === 'conflict')
|
|
57
|
+
throw new Error('Existing Vim plugin is user-managed: ' + filename);
|
|
58
|
+
return filename;
|
|
59
|
+
}
|
|
60
|
+
export async function setupVim() {
|
|
61
|
+
const filename = writeVimPlugin(vimDirectory(), await ensureEditorServer());
|
|
62
|
+
return `Installed ${filename}\nVim uses prabirshrestha/vim-lsp. Install it with your Vim plugin manager if needed, then restart Vim and open a source file. Run :LspStatus to check Loadwise.`;
|
|
63
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { spawnSync } from 'node:child_process';
|
|
5
|
+
import { parseArgs } from 'node:util';
|
|
6
|
+
import { packageManifest } from '../shared/package-root.js';
|
|
7
|
+
import { setupNativeEditor } from './native-setup.js';
|
|
8
|
+
import { setupJetBrains } from './jetbrains-setup.js';
|
|
9
|
+
import { setupVim } from './setup-vim.js';
|
|
10
|
+
import { setupConfiguredEditor } from './configured-setup.js';
|
|
11
|
+
import { printStdioSetup } from './stdio-setup.js';
|
|
12
|
+
import { ensureEditorServer } from './setup-server.js';
|
|
13
|
+
import { currentTarget, downloadVsix } from './release-vsix.js';
|
|
14
|
+
import { detectEditor, editorLauncher, isProduct } from './editor-launcher.js';
|
|
15
|
+
const usage = `Usage: loadwise editor setup [--editor <name>] [--vsix <file>]
|
|
16
|
+
|
|
17
|
+
Choose the integration for your editor:
|
|
18
|
+
code, codium, cursor, windsurf Install the Loadwise VSIX
|
|
19
|
+
antigravity-ide Install the VSIX in Antigravity IDE
|
|
20
|
+
nvim, helix, emacs, vim Set up an editor language client
|
|
21
|
+
jetbrains Prepare the JetBrains LSP integration
|
|
22
|
+
zed Prepare a Zed development extension
|
|
23
|
+
sublime Install the Sublime Text LSP client package
|
|
24
|
+
stdio Get the command for another LSP client
|
|
25
|
+
|
|
26
|
+
Setup recognizes supported editor terminals and installed editor launchers.
|
|
27
|
+
If several editors are available, choose one in the terminal or pass --editor.
|
|
28
|
+
It verifies the matching release download against GitHub's SHA-256 digest.
|
|
29
|
+
Use --vsix with a trusted local package to install without downloading.`;
|
|
30
|
+
function editorEnvironment() {
|
|
31
|
+
const env = { ...process.env };
|
|
32
|
+
if (process.platform === 'win32') {
|
|
33
|
+
env.ELECTRON_RUN_AS_NODE = '1';
|
|
34
|
+
delete env.VSCODE_DEV;
|
|
35
|
+
}
|
|
36
|
+
return env;
|
|
37
|
+
}
|
|
38
|
+
export function editorReleaseTarget(launcher) {
|
|
39
|
+
const version = spawnSync(launcher.executable, [...launcher.args, '--version'], {
|
|
40
|
+
encoding: 'utf8',
|
|
41
|
+
env: editorEnvironment(),
|
|
42
|
+
windowsHide: true,
|
|
43
|
+
timeout: 15_000,
|
|
44
|
+
});
|
|
45
|
+
const arch = version.stdout?.trim().split(/\r?\n/).at(-1)?.trim();
|
|
46
|
+
if (version.status !== 0 || (arch !== 'x64' && arch !== 'arm64'))
|
|
47
|
+
throw new Error(`Cannot determine a supported architecture from "${launcher.product} --version". Use --vsix <file> with a package matching your editor.`);
|
|
48
|
+
return currentTarget(arch);
|
|
49
|
+
}
|
|
50
|
+
function install(launcher, vsix) {
|
|
51
|
+
const result = spawnSync(launcher.executable, [...launcher.args, '--install-extension', vsix], {
|
|
52
|
+
env: editorEnvironment(),
|
|
53
|
+
stdio: 'inherit',
|
|
54
|
+
windowsHide: true,
|
|
55
|
+
});
|
|
56
|
+
if (result.error)
|
|
57
|
+
throw result.error;
|
|
58
|
+
if (result.status !== 0)
|
|
59
|
+
throw new Error(`${launcher.product} extension installation failed (${result.signal ?? result.status}).`);
|
|
60
|
+
}
|
|
61
|
+
export async function runEditor(args) {
|
|
62
|
+
if (!args.length || (args.length === 1 && ['--help', '-h'].includes(args[0]))) {
|
|
63
|
+
console.log(usage);
|
|
64
|
+
return 0;
|
|
65
|
+
}
|
|
66
|
+
if (args[0] !== 'setup')
|
|
67
|
+
throw new Error(usage);
|
|
68
|
+
const { values } = parseArgs({
|
|
69
|
+
args: args.slice(1),
|
|
70
|
+
options: {
|
|
71
|
+
editor: { type: 'string' },
|
|
72
|
+
vsix: { type: 'string' },
|
|
73
|
+
help: { type: 'boolean', short: 'h' },
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
if (values.help) {
|
|
77
|
+
console.log(usage);
|
|
78
|
+
return 0;
|
|
79
|
+
}
|
|
80
|
+
const editor = values.editor ?? (await detectEditor(values.vsix !== undefined));
|
|
81
|
+
if (!isProduct(editor)) {
|
|
82
|
+
if (values.vsix !== undefined)
|
|
83
|
+
throw new Error('--vsix is available for code, codium, cursor, windsurf and antigravity-ide.');
|
|
84
|
+
await configureLanguageClient(editor);
|
|
85
|
+
return 0;
|
|
86
|
+
}
|
|
87
|
+
const launcher = editorLauncher(editor);
|
|
88
|
+
if (values.vsix !== undefined) {
|
|
89
|
+
const local = path.resolve(values.vsix);
|
|
90
|
+
if (path.extname(local).toLowerCase() !== '.vsix' || !fs.statSync(local, { throwIfNoEntry: false })?.isFile())
|
|
91
|
+
throw new Error('--vsix must be an existing VSIX file.');
|
|
92
|
+
install(launcher, local);
|
|
93
|
+
return 0;
|
|
94
|
+
}
|
|
95
|
+
const target = editorReleaseTarget(launcher);
|
|
96
|
+
const directory = fs.mkdtempSync(path.join(os.tmpdir(), 'loadwise-editor-'));
|
|
97
|
+
const vsix = path.join(directory, 'loadwise.vsix');
|
|
98
|
+
try {
|
|
99
|
+
await downloadVsix(vsix, packageManifest.version, target);
|
|
100
|
+
install(launcher, vsix);
|
|
101
|
+
}
|
|
102
|
+
finally {
|
|
103
|
+
fs.rmSync(vsix, { force: true });
|
|
104
|
+
fs.rmdirSync(directory);
|
|
105
|
+
}
|
|
106
|
+
return 0;
|
|
107
|
+
}
|
|
108
|
+
async function configureLanguageClient(editor) {
|
|
109
|
+
switch (editor) {
|
|
110
|
+
case 'nvim':
|
|
111
|
+
case 'helix':
|
|
112
|
+
case 'emacs':
|
|
113
|
+
console.log(setupNativeEditor(editor, await ensureEditorServer()));
|
|
114
|
+
return;
|
|
115
|
+
case 'jetbrains':
|
|
116
|
+
console.log(await setupJetBrains());
|
|
117
|
+
return;
|
|
118
|
+
case 'vim':
|
|
119
|
+
console.log(await setupVim());
|
|
120
|
+
return;
|
|
121
|
+
case 'zed':
|
|
122
|
+
case 'sublime':
|
|
123
|
+
console.log(await setupConfiguredEditor(editor));
|
|
124
|
+
return;
|
|
125
|
+
case 'stdio':
|
|
126
|
+
await printStdioSetup();
|
|
127
|
+
return;
|
|
128
|
+
default:
|
|
129
|
+
throw new Error(`Invalid editor "${editor}". See loadwise editor --help.`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ensureEditorServer } from './setup-server.js';
|
|
2
|
+
/** Emit only the launch details so a client configuration tool can consume stdout. */
|
|
3
|
+
export async function printStdioSetup() {
|
|
4
|
+
const { command, args } = await ensureEditorServer();
|
|
5
|
+
console.log(JSON.stringify({ command, args }, null, 2));
|
|
6
|
+
}
|
|
@@ -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 ?? {}),
|
|
@@ -322,7 +322,7 @@ function collectEdges(sourceFile, file, resolve, compilerOptions = {}) {
|
|
|
322
322
|
}
|
|
323
323
|
if (ts.isExportDeclaration(node))
|
|
324
324
|
return;
|
|
325
|
-
collectDecoratorMetadataUses(compilerOptions, node, metadataUsed);
|
|
325
|
+
collectDecoratorMetadataUses(compilerOptions, node, deferred ? deferredUsed : metadataUsed);
|
|
326
326
|
if (isClassBase(node)) {
|
|
327
327
|
pushNode(node.expression, deferred);
|
|
328
328
|
return;
|
|
@@ -363,15 +363,15 @@ function collectEdges(sourceFile, file, resolve, compilerOptions = {}) {
|
|
|
363
363
|
if (!memberRead(node))
|
|
364
364
|
nonMemberReads.add(node.text);
|
|
365
365
|
}
|
|
366
|
-
const read = (binding) => used.has(binding) || deferredUsed.has(binding);
|
|
366
|
+
const read = (binding) => used.has(binding) || deferredUsed.has(binding) || metadataUsed.has(binding);
|
|
367
367
|
// A binding read only inside function bodies (for example a TypeORM entity callback) is not
|
|
368
368
|
// evaluated while the module loads, so it cannot close a load-time cycle.
|
|
369
369
|
for (const item of imports) {
|
|
370
370
|
let kind;
|
|
371
|
-
if (item.bindings.some((binding) => used.has(binding)))
|
|
371
|
+
if (item.bindings.some((binding) => used.has(binding) || metadataUsed.has(binding)))
|
|
372
372
|
kind = 'eager';
|
|
373
373
|
else if (item.bindings.some((binding) => deferredUsed.has(binding)))
|
|
374
|
-
kind =
|
|
374
|
+
kind = 'deferred';
|
|
375
375
|
else
|
|
376
376
|
continue;
|
|
377
377
|
const constEnumNames = constEnumCandidates(item, read, nonMemberReads, compilerOptions);
|
|
@@ -4,7 +4,13 @@ import { spawnSync } from 'node:child_process';
|
|
|
4
4
|
import { nonJsLanguages } from '../../../polyglot/maintainability/rules.js';
|
|
5
5
|
import { unquoteGitPath } from '../../shared/system/git-paths.js';
|
|
6
6
|
const sourceExtensions = ['.js', '.jsx', '.ts', '.tsx', '.mjs', '.cjs', '.mts', '.cts', ...Object.keys(nonJsLanguages)];
|
|
7
|
-
const sourcePathspecs =
|
|
7
|
+
const sourcePathspecs = [
|
|
8
|
+
...sourceExtensions.map((extension) => `:(icase)*${extension}`),
|
|
9
|
+
':(icase)tsconfig*.json',
|
|
10
|
+
':(icase)**/tsconfig*.json',
|
|
11
|
+
':(icase)jsconfig*.json',
|
|
12
|
+
':(icase)**/jsconfig*.json',
|
|
13
|
+
];
|
|
8
14
|
const declarationFile = /\.d\.[cm]?ts$/i;
|
|
9
15
|
const hunkHeader = /^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@/;
|
|
10
16
|
const wholeFile = [[1, Infinity]];
|
|
@@ -43,7 +49,7 @@ function parseChangedRanges(diffText) {
|
|
|
43
49
|
let inHeader = false;
|
|
44
50
|
let addedFile = false;
|
|
45
51
|
let currentFile;
|
|
46
|
-
for (const line of diffText.split(
|
|
52
|
+
for (const line of diffText.split(/\r?\n/)) {
|
|
47
53
|
if (line.startsWith('diff --git ')) {
|
|
48
54
|
inHeader = true;
|
|
49
55
|
addedFile = false;
|
|
@@ -52,6 +58,12 @@ function parseChangedRanges(diffText) {
|
|
|
52
58
|
else if (inHeader && line === '--- /dev/null') {
|
|
53
59
|
addedFile = true;
|
|
54
60
|
}
|
|
61
|
+
else if (inHeader && line.startsWith('rename to ')) {
|
|
62
|
+
// A pure rename has no new-side hunk. Preserve the path for file-level checks only.
|
|
63
|
+
const destination = unquoteGitPath(line.slice('rename to '.length));
|
|
64
|
+
if (destination && !changes.has(destination))
|
|
65
|
+
changes.set(destination, []);
|
|
66
|
+
}
|
|
55
67
|
else if (inHeader && line.startsWith('+++ ')) {
|
|
56
68
|
currentFile = newSidePath(line);
|
|
57
69
|
if (currentFile && addedFile)
|
|
@@ -86,10 +98,16 @@ function readChangedRanges(root, { staged, since }) {
|
|
|
86
98
|
const diffText = runGit(root, [
|
|
87
99
|
'-c',
|
|
88
100
|
'core.quotepath=false',
|
|
101
|
+
'-c',
|
|
102
|
+
'diff.noprefix=false',
|
|
103
|
+
'-c',
|
|
104
|
+
'diff.mnemonicPrefix=false',
|
|
89
105
|
'diff',
|
|
90
106
|
'-U0',
|
|
91
107
|
'--no-color',
|
|
92
108
|
'--no-ext-diff',
|
|
109
|
+
'--src-prefix=a/',
|
|
110
|
+
'--dst-prefix=b/',
|
|
93
111
|
'--diff-filter=ACMR',
|
|
94
112
|
'--relative',
|
|
95
113
|
...target,
|
|
@@ -174,10 +174,11 @@ function createResolver(root, fileSet, declarationFiles = []) {
|
|
|
174
174
|
allowJs: true,
|
|
175
175
|
};
|
|
176
176
|
if (config) {
|
|
177
|
-
const
|
|
177
|
+
const configFile = slash(config);
|
|
178
|
+
const loaded = ts.readConfigFile(configFile, configHost.readFile);
|
|
178
179
|
const parsed = loaded.error
|
|
179
180
|
? undefined
|
|
180
|
-
: ts.parseJsonConfigFileContent(loaded.config, configHost, path.dirname(config), undefined,
|
|
181
|
+
: ts.parseJsonConfigFileContent(loaded.config, configHost, slash(path.dirname(config)), undefined, configFile, undefined, undefined, extendedConfigs);
|
|
181
182
|
// A base config from a package is missing until dependencies are installed; its workspace
|
|
182
183
|
// imports would not resolve either, so scan with the local settings instead of failing.
|
|
183
184
|
const configErrors = parsed ? parsed.errors : loaded.error ? [loaded.error] : [];
|
|
@@ -218,7 +219,15 @@ function createResolver(root, fileSet, declarationFiles = []) {
|
|
|
218
219
|
}
|
|
219
220
|
const resolved = ts.resolveModuleName(specifier, filename, options, host, cache, undefined, mode).resolvedModule;
|
|
220
221
|
if (resolved) {
|
|
221
|
-
|
|
222
|
+
let local = indexed.get(canonical(path.resolve(resolved.resolvedFileName)));
|
|
223
|
+
if (!local) {
|
|
224
|
+
try {
|
|
225
|
+
local = indexed.get(canonical(fs.realpathSync.native(resolved.resolvedFileName)));
|
|
226
|
+
}
|
|
227
|
+
catch {
|
|
228
|
+
// Missing symlink target stays unindexed.
|
|
229
|
+
}
|
|
230
|
+
}
|
|
222
231
|
if (!local && /(?:^|[\\/])node_modules[\\/]/.test(resolved.resolvedFileName))
|
|
223
232
|
outsideProject?.();
|
|
224
233
|
return local;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
+
import { configuredLimits } from './quality/limits.js';
|
|
3
4
|
import { parseArgs } from 'node:util';
|
|
4
5
|
import { exampleFor } from './examples.js';
|
|
5
6
|
import { impactByRule } from './rule-ids.js';
|
|
@@ -8,6 +9,7 @@ import { fixLines } from './cli/fix-text.js';
|
|
|
8
9
|
import { loadSettings } from '../shared/config.js';
|
|
9
10
|
import { extractBaselineFlags } from '../shared/reporting/baseline-flags.js';
|
|
10
11
|
import { resolveFormat, renderReports } from '../shared/formats/index.js';
|
|
12
|
+
import { reportAutomaticFixes } from '../shared/reporting/automatic-fix-signal.js';
|
|
11
13
|
import { contractRules } from '../shared/formats/contract-rules.js';
|
|
12
14
|
import { quoteArgument } from '../shared/system/shell-argument.js';
|
|
13
15
|
import { exitCodeWithSkips } from '../performance/cli/scan-outcome.js';
|
|
@@ -18,11 +20,17 @@ import { findingReason, groupByReason } from '../shared/reporting/reason-groups.
|
|
|
18
20
|
import { notifyEditor } from '../shared/agent/notify-editor.js';
|
|
19
21
|
import { printTerminalLine } from '../shared/system/terminal-safe.js';
|
|
20
22
|
const help = `Usage:
|
|
21
|
-
loadwise maint [directory] [
|
|
22
|
-
loadwise maint [directory]
|
|
23
|
-
loadwise maint agent init [
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
loadwise maint [directory] [options]
|
|
24
|
+
loadwise maint [directory] --graph <modules.json> [options]
|
|
25
|
+
loadwise maint agent init [options]
|
|
26
|
+
|
|
27
|
+
Scan options
|
|
28
|
+
--workspace <name|path> --config <policy-file> --loadwise-config <file>
|
|
29
|
+
--staged | --changed-since <git-ref> --ignore <rule-id>
|
|
30
|
+
--json | --format <text|json|sarif|github> --include-contextual
|
|
31
|
+
--min-impact <low|medium|high|critical> --fail-on <all|contract>
|
|
32
|
+
--baseline [file] | --write-baseline [file]
|
|
33
|
+
--fix [--yes | --only <ids>] [--no-comments] [--no-format]
|
|
26
34
|
|
|
27
35
|
A loadwise.config.json in the directory also applies: its "maintainability" section holds the policy (--config names a policy file instead), and its ignore, rules and overrides filter the findings; --loadwise-config names another file. --ignore drops a rule's findings.
|
|
28
36
|
The default directory is the current folder. Source mode discovers supported files.
|
|
@@ -178,6 +186,8 @@ async function scanProject(root, values, { changes, inScope }) {
|
|
|
178
186
|
const { loadPolicy, checkImportedGraph } = await import('./project.js');
|
|
179
187
|
const settings = loadSettings({ directory: root, explicit: values['loadwise-config'], ignore: values.ignore });
|
|
180
188
|
const policy = loadPolicy(values.config, settings.maintainability);
|
|
189
|
+
if (settings.filename)
|
|
190
|
+
policy.limitsFor = configuredLimits(settings, root, policy.limits);
|
|
181
191
|
// Ignored files leave file discovery, so duplicates, cycles and boundaries never see them.
|
|
182
192
|
const { isIgnored } = settings;
|
|
183
193
|
if (isIgnored)
|
|
@@ -229,6 +239,7 @@ async function processBaseline(report, { baselineOptions, root, values, format,
|
|
|
229
239
|
options: baselineForScan(baselineOptions, values, values.graph === undefined ? [root] : []),
|
|
230
240
|
pillar: 'maintainability',
|
|
231
241
|
findings: report.findings,
|
|
242
|
+
skippedFiles: report.skippedFiles,
|
|
232
243
|
projectRoot: root,
|
|
233
244
|
absoluteFileOf: (finding) => path.resolve(root, finding.file ?? ''),
|
|
234
245
|
idRoot: root,
|
|
@@ -349,6 +360,8 @@ async function printScanReport(report, options) {
|
|
|
349
360
|
}
|
|
350
361
|
else
|
|
351
362
|
await printTextReport(report, options);
|
|
363
|
+
if (format === 'text')
|
|
364
|
+
reportAutomaticFixes(report.findings);
|
|
352
365
|
}
|
|
353
366
|
async function main(args) {
|
|
354
367
|
if (args[0] === 'agent')
|