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
|
@@ -77,7 +77,7 @@ function isUnshadowedGlobal(node, name, checker) {
|
|
|
77
77
|
return declarations.every((declaration) => declaration.getSourceFile().isDeclarationFile);
|
|
78
78
|
}
|
|
79
79
|
function constInitializer(identifier, checker) {
|
|
80
|
-
const declaration =
|
|
80
|
+
const declaration = symbolOf(identifier, checker)?.declarations?.[0];
|
|
81
81
|
if (declaration &&
|
|
82
82
|
ts.isVariableDeclaration(declaration) &&
|
|
83
83
|
declaration.parent.flags & ts.NodeFlags.Const &&
|
|
@@ -450,4 +450,4 @@ function isEffectivelySet(object, key, checker) {
|
|
|
450
450
|
}
|
|
451
451
|
return true;
|
|
452
452
|
}
|
|
453
|
-
export { constInitializer, effectiveProperty, forEachExecutedNode, immediateInvocation, isEffectivelySet, isUnshadowedGlobal, literalKey, neverEvaluatesRight, resolveImportedBinding, resolveRequiredModule, staticFalsy, staticMemberName, staticPropertyName, symbolOf, unwrapExpression, };
|
|
453
|
+
export { constInitializer, effectiveProperty, forEachExecutedNode, immediateInvocation, isEffectivelySet, isUnshadowedGlobal, literalKey, neverEvaluatesRight, resolveImportedBinding, resolveRequiredModule, staticFalsy, staticMemberName, staticNullish, staticPropertyName, symbolOf, unwrapExpression, };
|
|
@@ -4,6 +4,7 @@ import crypto from 'node:crypto';
|
|
|
4
4
|
import fs from 'node:fs';
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
import { spawnSync } from 'node:child_process';
|
|
7
|
+
import * as ts from 'typescript';
|
|
7
8
|
import { writeFileAtomic } from '../system/atomic-write.js';
|
|
8
9
|
import { packageManifest, packagePath, packageRoot } from '../package-root.js';
|
|
9
10
|
import { defaultCacheDirectory } from '../../security/deps/osv.js';
|
|
@@ -106,6 +107,7 @@ const installMarkers = [
|
|
|
106
107
|
];
|
|
107
108
|
// Checkers read these from disk to select sources, so their contents count even when Git ignores them.
|
|
108
109
|
const projectConfigNames = ['tsconfig.json', 'jsconfig.json', 'pnpm-workspace.yaml', 'lerna.json'];
|
|
110
|
+
const loadwiseConfigNames = ['loadwise-baseline.json', 'loadwise.config.json'];
|
|
109
111
|
const projectInputs = /(?:^|\/)(?:package|[jt]sconfig)\.json$|\.[cm]?[jt]sx?$/i;
|
|
110
112
|
function addConfigDirectories(directories, directory) {
|
|
111
113
|
for (let folder = directory; !directories.has(folder); folder = path.posix.dirname(folder)) {
|
|
@@ -213,7 +215,7 @@ function inputFingerprint(cwd) {
|
|
|
213
215
|
hashIgnoredProjectConfigs(hash, topLevel, relativeCwd.split(path.sep).join('/'), names);
|
|
214
216
|
const unindexedConfigs = new Set();
|
|
215
217
|
for (const directory of new Set([topLevel, path.resolve(cwd)])) {
|
|
216
|
-
for (const configName of
|
|
218
|
+
for (const configName of loadwiseConfigNames) {
|
|
217
219
|
const candidate = path.join(directory, configName);
|
|
218
220
|
if (fs.statSync(candidate, { throwIfNoEntry: false })?.isFile())
|
|
219
221
|
unindexedConfigs.add(candidate);
|
|
@@ -230,9 +232,26 @@ function inputFingerprint(cwd) {
|
|
|
230
232
|
return { fingerprint: hash.digest('hex'), coversWorkspaces: workspaceCoverage(topLevel, names) };
|
|
231
233
|
}
|
|
232
234
|
const maxHashedFileBytes = 16 * 1024 * 1024;
|
|
233
|
-
|
|
235
|
+
// Use TypeScript's resolver for JSONC, arrays of bases and package-based inheritance. The
|
|
236
|
+
// repository snapshot covers source files already, so resolving configs must not glob the project.
|
|
237
|
+
function projectFingerprint(absolute) {
|
|
238
|
+
const hash = crypto.createHash('sha256');
|
|
239
|
+
const readFile = (filename) => {
|
|
240
|
+
const text = ts.sys.readFile(filename);
|
|
241
|
+
hash.update(JSON.stringify([filename, text ?? null]));
|
|
242
|
+
return text;
|
|
243
|
+
};
|
|
244
|
+
const config = ts.readJsonConfigFile(absolute, readFile);
|
|
245
|
+
ts.parseJsonSourceFileConfigFileContent(config, { ...ts.sys, readFile, readDirectory: () => [] }, path.dirname(absolute), {}, absolute);
|
|
246
|
+
return hash.digest('hex');
|
|
247
|
+
}
|
|
248
|
+
function fileHash(absolute, existingStat, namedConfig = false) {
|
|
234
249
|
try {
|
|
235
250
|
const stat = existingStat ?? fs.lstatSync(absolute);
|
|
251
|
+
if ((namedConfig || /^[jt]sconfig(?:\..+)?\.json$/i.test(path.basename(absolute))) &&
|
|
252
|
+
(stat.isFile() || stat.isSymbolicLink())) {
|
|
253
|
+
return projectFingerprint(absolute);
|
|
254
|
+
}
|
|
236
255
|
if (stat.isSymbolicLink())
|
|
237
256
|
return `symlink:${sha1(fs.readlinkSync(absolute))}`;
|
|
238
257
|
if (stat.isDirectory())
|
|
@@ -249,6 +268,77 @@ function fileHash(absolute, existingStat) {
|
|
|
249
268
|
return 'missing';
|
|
250
269
|
}
|
|
251
270
|
}
|
|
271
|
+
function configFileEntry(candidate) {
|
|
272
|
+
let stat;
|
|
273
|
+
try {
|
|
274
|
+
stat = fs.statSync(candidate, { throwIfNoEntry: false });
|
|
275
|
+
}
|
|
276
|
+
catch {
|
|
277
|
+
// An inaccessible config cannot be fingerprinted, so bypass the cache.
|
|
278
|
+
return { unfingerprintable: true };
|
|
279
|
+
}
|
|
280
|
+
if (!stat?.isFile())
|
|
281
|
+
return {};
|
|
282
|
+
// Pass the statSync result (which follows symlinks) so symlinked configs hash target contents.
|
|
283
|
+
const hash = fileHash(candidate, stat);
|
|
284
|
+
if (!hash || hash === 'missing')
|
|
285
|
+
return { unfingerprintable: true };
|
|
286
|
+
return { entry: `${candidate}${hash}` };
|
|
287
|
+
}
|
|
288
|
+
function directoryConfigFingerprint(directory, stopAt) {
|
|
289
|
+
const entries = [];
|
|
290
|
+
let current = path.resolve(directory);
|
|
291
|
+
const boundary = path.resolve(stopAt);
|
|
292
|
+
while (true) {
|
|
293
|
+
for (const configName of ['loadwise-baseline.json', 'loadwise.config.json']) {
|
|
294
|
+
const result = configFileEntry(path.join(current, configName));
|
|
295
|
+
if (result.unfingerprintable)
|
|
296
|
+
return undefined;
|
|
297
|
+
if (result.entry)
|
|
298
|
+
entries.push(result.entry);
|
|
299
|
+
}
|
|
300
|
+
if (current === boundary)
|
|
301
|
+
break;
|
|
302
|
+
const parent = path.dirname(current);
|
|
303
|
+
if (parent === current)
|
|
304
|
+
break;
|
|
305
|
+
current = parent;
|
|
306
|
+
}
|
|
307
|
+
return entries.join('');
|
|
308
|
+
}
|
|
309
|
+
// Returns the fingerprint entries for one argument, or undefined when the cache must be bypassed.
|
|
310
|
+
function namedArgumentEntries(args, index, cwd, directory, inputs) {
|
|
311
|
+
const arg = args[index];
|
|
312
|
+
const candidate = arg.startsWith('-') && arg.includes('=') ? arg.slice(arg.indexOf('=') + 1) : arg;
|
|
313
|
+
if (!candidate)
|
|
314
|
+
return [''];
|
|
315
|
+
const absolute = path.resolve(cwd, candidate);
|
|
316
|
+
// The checker opens the named input and reads its target when it is a symlink.
|
|
317
|
+
let stat;
|
|
318
|
+
try {
|
|
319
|
+
stat = fs.statSync(absolute, { throwIfNoEntry: false });
|
|
320
|
+
}
|
|
321
|
+
catch {
|
|
322
|
+
return undefined;
|
|
323
|
+
}
|
|
324
|
+
if (stat?.isDirectory() && !inputs.coversWorkspaces(absolute))
|
|
325
|
+
return undefined;
|
|
326
|
+
if (stat?.isDirectory()) {
|
|
327
|
+
const fingerprint = directoryConfigFingerprint(absolute, directory);
|
|
328
|
+
return fingerprint === undefined ? undefined : [fingerprint];
|
|
329
|
+
}
|
|
330
|
+
const flag = candidate === arg ? args[index - 1] : arg.split('=')[0];
|
|
331
|
+
const namedProject = flag === '-p' || flag === '--project';
|
|
332
|
+
if (!stat?.isFile() && !(namedProject && stat?.isSymbolicLink()))
|
|
333
|
+
return [''];
|
|
334
|
+
const entries = [fileHash(absolute, stat, namedProject) ?? ''];
|
|
335
|
+
// A selected subproject may read an ignored config or baseline beside its tsconfig.
|
|
336
|
+
const projectDirectory = path.dirname(absolute);
|
|
337
|
+
if (!stat?.isFile() || projectDirectory === directory)
|
|
338
|
+
return entries;
|
|
339
|
+
const fingerprint = directoryConfigFingerprint(projectDirectory, directory);
|
|
340
|
+
return fingerprint === undefined ? undefined : [...entries, fingerprint];
|
|
341
|
+
}
|
|
252
342
|
function cacheKey(args, cwd) {
|
|
253
343
|
const directory = path.resolve(cwd);
|
|
254
344
|
if (launchFingerprints && !launchFingerprints.has(directory)) {
|
|
@@ -263,17 +353,11 @@ function cacheKey(args, cwd) {
|
|
|
263
353
|
.map((name) => `${name}=${process.env[name]}`);
|
|
264
354
|
// A config file named in the args may live outside the repository.
|
|
265
355
|
const namedFiles = [];
|
|
266
|
-
for (const
|
|
267
|
-
const
|
|
268
|
-
if (!
|
|
269
|
-
namedFiles.push('');
|
|
270
|
-
continue;
|
|
271
|
-
}
|
|
272
|
-
const absolute = path.resolve(cwd, candidate);
|
|
273
|
-
const stat = fs.lstatSync(absolute, { throwIfNoEntry: false });
|
|
274
|
-
if (stat?.isDirectory() && !inputs.coversWorkspaces(absolute))
|
|
356
|
+
for (const index of args.keys()) {
|
|
357
|
+
const entries = namedArgumentEntries(args, index, cwd, directory, inputs);
|
|
358
|
+
if (!entries)
|
|
275
359
|
return undefined;
|
|
276
|
-
namedFiles.push(
|
|
360
|
+
namedFiles.push(...entries);
|
|
277
361
|
}
|
|
278
362
|
const parts = [formatVersion, loadwiseFingerprint(), directory, args, namedFiles, environment, inputs.fingerprint];
|
|
279
363
|
return crypto.createHash('sha256').update(JSON.stringify(parts)).digest('hex');
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Load checker dependencies only after the CLI has handled usage and version requests.
|
|
2
|
+
export async function dispatch(args, checkUsage) {
|
|
3
|
+
const [command, ...rest] = args;
|
|
4
|
+
if (command === 'perf')
|
|
5
|
+
return (await import('../performance/cli.js')).main(rest);
|
|
6
|
+
if (command === 'rel')
|
|
7
|
+
return (await import('../reliability/cli.js')).main(rest);
|
|
8
|
+
if (command === 'maint')
|
|
9
|
+
return (await import('../maintainability/cli.js')).main(rest);
|
|
10
|
+
if (command === 'sec')
|
|
11
|
+
return (await import('../security/cli.js')).main(rest);
|
|
12
|
+
if (command === 'a11y')
|
|
13
|
+
return (await import('../accessibility/cli.js')).main(rest);
|
|
14
|
+
if (command === 'fix')
|
|
15
|
+
return (await import('./fix.js')).runFix(rest);
|
|
16
|
+
return (await import('./check.js')).runCheck(command === 'check' ? rest : args, checkUsage);
|
|
17
|
+
}
|
|
@@ -186,12 +186,33 @@ function loadConfig({ directory, explicit }) {
|
|
|
186
186
|
validateConfig(config, filename);
|
|
187
187
|
return { filename, directory: path.dirname(filename), config };
|
|
188
188
|
}
|
|
189
|
+
// Keeps the spelling the scanner passed (so a pattern naming a symlinked subdirectory matches);
|
|
190
|
+
// only when the file is not under the base as spelled (a symlinked temp root such as macOS /var)
|
|
191
|
+
// does it compare real locations.
|
|
192
|
+
function relativeToBase(base, file) {
|
|
193
|
+
let relativeFile = path.relative(base, file);
|
|
194
|
+
if (relativeFile.startsWith('..') || path.isAbsolute(relativeFile))
|
|
195
|
+
relativeFile = path.relative(realDirectory(base), realParent(file));
|
|
196
|
+
return relativeFile.split(path.sep).join('/');
|
|
197
|
+
}
|
|
189
198
|
function levelOf(setting) {
|
|
190
199
|
return typeof setting === 'object' ? setting.level : setting;
|
|
191
200
|
}
|
|
192
201
|
function optionsOf(setting) {
|
|
193
202
|
return typeof setting === 'object' ? setting.options : undefined;
|
|
194
203
|
}
|
|
204
|
+
function realDirectory(directory) {
|
|
205
|
+
try {
|
|
206
|
+
return fs.realpathSync.native(directory);
|
|
207
|
+
}
|
|
208
|
+
catch {
|
|
209
|
+
return directory;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
// Resolves symlinks in the parent only, so a symlinked file keeps its own name.
|
|
213
|
+
function realParent(file) {
|
|
214
|
+
return path.join(realDirectory(path.dirname(file)), path.basename(file));
|
|
215
|
+
}
|
|
195
216
|
// What a checker needs from the config: its policy section, plus the filters that apply to its
|
|
196
217
|
// findings.
|
|
197
218
|
function createSettings(loaded, cliIgnore) {
|
|
@@ -229,14 +250,13 @@ function createSettings(loaded, cliIgnore) {
|
|
|
229
250
|
return merged;
|
|
230
251
|
}
|
|
231
252
|
function isIgnoredIn(fileBase, file) {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
.join('/');
|
|
236
|
-
return isIgnored(relativeFile);
|
|
253
|
+
// The config directory and the scanned file can reach the same place through different
|
|
254
|
+
// spellings (a symlinked temp root such as macOS /var), so compare their real locations.
|
|
255
|
+
return isIgnored(relativeToBase(loaded?.directory ?? fileBase, path.resolve(fileBase, file)));
|
|
237
256
|
}
|
|
238
257
|
return {
|
|
239
258
|
filename: loaded?.filename,
|
|
259
|
+
directory: loaded?.directory,
|
|
240
260
|
// Lets a checker leave ignored files out of its scan; undefined when the config ignores
|
|
241
261
|
// nothing.
|
|
242
262
|
isIgnored: config.ignore?.length ? isIgnoredIn : undefined,
|
|
@@ -249,10 +269,7 @@ function createSettings(loaded, cliIgnore) {
|
|
|
249
269
|
apply(findings, fileBase) {
|
|
250
270
|
const base = loaded?.directory ?? fileBase;
|
|
251
271
|
return findings.filter((finding) => {
|
|
252
|
-
const relativeFile = path
|
|
253
|
-
.relative(base, path.resolve(fileBase, finding.file ?? ''))
|
|
254
|
-
.split(path.sep)
|
|
255
|
-
.join('/');
|
|
272
|
+
const relativeFile = relativeToBase(base, path.resolve(fileBase, finding.file ?? ''));
|
|
256
273
|
if (isIgnored(relativeFile))
|
|
257
274
|
return false;
|
|
258
275
|
const level = levelFor(finding.ruleId, relativeFile);
|
|
@@ -283,4 +300,4 @@ function loadSettings({ directory, explicit, ignore = [], }) {
|
|
|
283
300
|
throw new Error('Unknown rule id: ' + unknown.join(', '));
|
|
284
301
|
return createSettings(loaded, ignore);
|
|
285
302
|
}
|
|
286
|
-
export { loadConfig, loadSettings };
|
|
303
|
+
export { loadConfig, loadSettings, ruleOptionSchemas };
|
|
@@ -17,7 +17,7 @@ function explainRule(ruleId) {
|
|
|
17
17
|
throw new Error(`Unknown rule "${ruleId}". Use the rule name shown before the #finding-id.`);
|
|
18
18
|
const { name, exampleFor: pillarExample } = explainedPillars[pillar];
|
|
19
19
|
const { impactByRule, descriptionByRule } = rulesByPillar[pillar];
|
|
20
|
-
const language = /^(python|csharp|java|go|rust)-/.exec(ruleId)?.[1] ?? 'typescript';
|
|
20
|
+
const language = pillar === 'accessibility' ? 'html' : (/^(python|csharp|java|go|rust)-/.exec(ruleId)?.[1] ?? 'typescript');
|
|
21
21
|
const example = pillarExample(ruleId, language, '');
|
|
22
22
|
const lines = [`${ruleId} (${name}, default impact ${impactByRule[ruleId]})`, descriptionByRule[ruleId]];
|
|
23
23
|
if (example)
|
|
@@ -2,7 +2,7 @@ import fs from 'node:fs';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { applyFix } from '../../editor/apply-fix.js';
|
|
4
4
|
import { realTarget } from '../system/real-target.js';
|
|
5
|
-
import { introducedSyntaxError, refusalReason, validateSource } from './fix-safety.js';
|
|
5
|
+
import { explainPassLimit, introducedSyntaxError, refusalReason, validateSource } from './fix-safety.js';
|
|
6
6
|
import { errorCode, errorMessage } from '../system/error-code.js';
|
|
7
7
|
import { formatUpdates } from './fix-presentation.js';
|
|
8
8
|
import { coalesceImportChanges, isPureImportChange } from './fix-imports.js';
|
|
@@ -504,8 +504,10 @@ export function writeFixes(findings, directory, { format, verifyTypes = true, dr
|
|
|
504
504
|
});
|
|
505
505
|
allApplied.push(...passResult.applied);
|
|
506
506
|
allRefused.push(...passResult.refused);
|
|
507
|
-
if (!passResult.deferred.length
|
|
508
|
-
|
|
507
|
+
if (!passResult.deferred.length)
|
|
508
|
+
break;
|
|
509
|
+
if (pass === MAX_FIX_PASSES) {
|
|
510
|
+
allRefused.push(...explainPassLimit(passResult.deferred, MAX_FIX_PASSES));
|
|
509
511
|
break;
|
|
510
512
|
}
|
|
511
513
|
const { retryable, unresolvable } = relocateDeferred(passResult.deferred, directory, virtualFiles, passResult.priorEdits);
|
|
@@ -1,160 +1,6 @@
|
|
|
1
1
|
import * as ts from 'typescript';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
return;
|
|
5
|
-
const moduleSpecifier = statement.moduleSpecifier.text;
|
|
6
|
-
const clause = statement.importClause;
|
|
7
|
-
// Leave declarations with attributes, comments, or a nonstandard phase intact. Only declarations represented losslessly
|
|
8
|
-
// below may be formatted again.
|
|
9
|
-
if (!clause || statement.attributes || statement.modifiers?.length || /\/[/*]/.test(statement.getText()))
|
|
10
|
-
return;
|
|
11
|
-
if (clause.phaseModifier !== undefined && clause.phaseModifier !== ts.SyntaxKind.TypeKeyword)
|
|
12
|
-
return;
|
|
13
|
-
const isTypeOnly = Boolean(clause.isTypeOnly);
|
|
14
|
-
const defaultName = clause.name?.text;
|
|
15
|
-
const named = [];
|
|
16
|
-
let namespaceName;
|
|
17
|
-
if (clause.namedBindings) {
|
|
18
|
-
if (ts.isNamespaceImport(clause.namedBindings)) {
|
|
19
|
-
namespaceName = clause.namedBindings.name.text;
|
|
20
|
-
}
|
|
21
|
-
else if (ts.isNamedImports(clause.namedBindings)) {
|
|
22
|
-
for (const element of clause.namedBindings.elements) {
|
|
23
|
-
const imported = element.propertyName
|
|
24
|
-
? `${element.propertyName.getText()} as ${element.name.text}`
|
|
25
|
-
: element.name.text;
|
|
26
|
-
named.push((element.isTypeOnly ? 'type ' : '') + imported);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return { moduleSpecifier, named, defaultName, namespaceName, isTypeOnly };
|
|
31
|
-
}
|
|
32
|
-
function formatImport(entry) {
|
|
33
|
-
const prefix = entry.isTypeOnly ? 'import type ' : 'import ';
|
|
34
|
-
const literal = /^[\w@./#:-]+$/.test(entry.moduleSpecifier)
|
|
35
|
-
? `'${entry.moduleSpecifier}'`
|
|
36
|
-
: JSON.stringify(entry.moduleSpecifier);
|
|
37
|
-
const parts = [];
|
|
38
|
-
if (entry.defaultName)
|
|
39
|
-
parts.push(entry.defaultName);
|
|
40
|
-
if (entry.namespaceName)
|
|
41
|
-
parts.push(`* as ${entry.namespaceName}`);
|
|
42
|
-
if (entry.named.length)
|
|
43
|
-
parts.push(`{ ${[...new Set(entry.named)].join(', ')} }`);
|
|
44
|
-
if (!parts.length)
|
|
45
|
-
return `${prefix}${literal};`;
|
|
46
|
-
return `${prefix}${parts.join(', ')} from ${literal};`;
|
|
47
|
-
}
|
|
48
|
-
function acceptsImportEdit(target, edit) {
|
|
49
|
-
if (target.moduleSpecifier !== edit.moduleSpecifier || target.isTypeOnly !== Boolean(edit.isTypeOnly))
|
|
50
|
-
return false;
|
|
51
|
-
if (target.defaultName && edit.defaultName && target.defaultName !== edit.defaultName)
|
|
52
|
-
return false;
|
|
53
|
-
if (target.namespaceName && edit.namespaceName && target.namespaceName !== edit.namespaceName)
|
|
54
|
-
return false;
|
|
55
|
-
const hasNamed = target.named.length || edit.named?.length;
|
|
56
|
-
const hasNamespace = target.namespaceName || edit.namespaceName;
|
|
57
|
-
if (hasNamed && hasNamespace)
|
|
58
|
-
return false;
|
|
59
|
-
return !(target.isTypeOnly && (target.defaultName || edit.defaultName) && (hasNamed || hasNamespace));
|
|
60
|
-
}
|
|
61
|
-
function mergeEditIntoParsed(target, edit) {
|
|
62
|
-
if (edit.defaultName && !target.defaultName)
|
|
63
|
-
target.defaultName = edit.defaultName;
|
|
64
|
-
if (edit.namespaceName && !target.namespaceName)
|
|
65
|
-
target.namespaceName = edit.namespaceName;
|
|
66
|
-
if (edit.named?.length)
|
|
67
|
-
target.named.push(...edit.named);
|
|
68
|
-
}
|
|
69
|
-
function newImportInsertion(text, source, existingImports, lines) {
|
|
70
|
-
const joined = lines.join('\n');
|
|
71
|
-
if (existingImports.length) {
|
|
72
|
-
const last = existingImports[existingImports.length - 1];
|
|
73
|
-
return { start: last.getEnd(), text: `\n${joined}` };
|
|
74
|
-
}
|
|
75
|
-
let lastDirective;
|
|
76
|
-
for (const stmt of source.statements) {
|
|
77
|
-
if (!ts.isExpressionStatement(stmt) || !ts.isStringLiteralLike(stmt.expression))
|
|
78
|
-
break;
|
|
79
|
-
lastDirective = stmt;
|
|
80
|
-
}
|
|
81
|
-
if (lastDirective) {
|
|
82
|
-
return { start: lastDirective.getEnd(), text: `\n${joined}` };
|
|
83
|
-
}
|
|
84
|
-
const shebang = /^#![^\n]*\r?\n/.exec(text);
|
|
85
|
-
if (shebang) {
|
|
86
|
-
return { start: shebang[0].length, text: `${joined}\n` };
|
|
87
|
-
}
|
|
88
|
-
return { start: 0, text: `${joined}\n` };
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Merges structured `ImportEdit`s into existing import declarations in `text` (or inserts a single
|
|
92
|
-
* import per module specifier after any leading shebang, directive prologues, or existing imports)
|
|
93
|
-
* without creating duplicate imports.
|
|
94
|
-
*/
|
|
95
|
-
export function applyImportEdits(text, edits, fileName = 'file.ts') {
|
|
96
|
-
if (!edits.length)
|
|
97
|
-
return text;
|
|
98
|
-
const source = ts.createSourceFile(fileName, text, ts.ScriptTarget.Latest, true);
|
|
99
|
-
const existingImports = source.statements.filter(ts.isImportDeclaration);
|
|
100
|
-
const matchedReplacements = new Map();
|
|
101
|
-
const parsedImports = existingImports.map((declaration) => ({
|
|
102
|
-
declaration,
|
|
103
|
-
parsed: parseImportStatement(declaration),
|
|
104
|
-
}));
|
|
105
|
-
const newImports = [];
|
|
106
|
-
for (const edit of edits) {
|
|
107
|
-
const match = parsedImports.find(({ parsed }) => parsed && acceptsImportEdit(parsed, edit));
|
|
108
|
-
if (match?.parsed) {
|
|
109
|
-
mergeEditIntoParsed(match.parsed, edit);
|
|
110
|
-
matchedReplacements.set(match.declaration, match.parsed);
|
|
111
|
-
continue;
|
|
112
|
-
}
|
|
113
|
-
// Import attributes affect module loading. A plain requested import cannot safely inherit or omit them.
|
|
114
|
-
if (existingImports.some((declaration) => declaration.attributes &&
|
|
115
|
-
ts.isStringLiteral(declaration.moduleSpecifier) &&
|
|
116
|
-
declaration.moduleSpecifier.text === edit.moduleSpecifier))
|
|
117
|
-
throw new Error(`Cannot combine a generated import with import attributes for ${edit.moduleSpecifier}. No fixes applied.`);
|
|
118
|
-
let current = newImports.find((entry) => acceptsImportEdit(entry, edit));
|
|
119
|
-
if (!current) {
|
|
120
|
-
current = { moduleSpecifier: edit.moduleSpecifier, named: [], isTypeOnly: Boolean(edit.isTypeOnly) };
|
|
121
|
-
newImports.push(current);
|
|
122
|
-
}
|
|
123
|
-
mergeEditIntoParsed(current, edit);
|
|
124
|
-
}
|
|
125
|
-
const textEdits = [...matchedReplacements.entries()].map(([decl, parsed]) => ({
|
|
126
|
-
start: decl.getStart(source),
|
|
127
|
-
end: decl.getEnd(),
|
|
128
|
-
text: formatImport(parsed),
|
|
129
|
-
}));
|
|
130
|
-
if (newImports.length) {
|
|
131
|
-
const insertion = newImportInsertion(text, source, existingImports, newImports.map(formatImport));
|
|
132
|
-
textEdits.push({ start: insertion.start, end: insertion.start, text: insertion.text });
|
|
133
|
-
}
|
|
134
|
-
let result = text;
|
|
135
|
-
for (const rep of textEdits.sort((a, b) => b.start - a.start)) {
|
|
136
|
-
result = result.slice(0, rep.start) + rep.text + result.slice(rep.end);
|
|
137
|
-
}
|
|
138
|
-
return result;
|
|
139
|
-
}
|
|
140
|
-
function parsePureImportBlock(text) {
|
|
141
|
-
const trimmed = text.trim();
|
|
142
|
-
if (!trimmed)
|
|
143
|
-
return undefined;
|
|
144
|
-
const source = ts.createSourceFile('import-edit.ts', trimmed, ts.ScriptTarget.Latest, true);
|
|
145
|
-
if (source.parseDiagnostics?.length || !source.statements.length)
|
|
146
|
-
return undefined;
|
|
147
|
-
const edits = [];
|
|
148
|
-
for (const statement of source.statements) {
|
|
149
|
-
if (!ts.isImportDeclaration(statement))
|
|
150
|
-
return undefined;
|
|
151
|
-
const parsed = parseImportStatement(statement);
|
|
152
|
-
if (!parsed)
|
|
153
|
-
return undefined;
|
|
154
|
-
edits.push(parsed);
|
|
155
|
-
}
|
|
156
|
-
return edits;
|
|
157
|
-
}
|
|
2
|
+
import { hunksFor, lineStartsOf } from './fix-hunks.js';
|
|
3
|
+
import { importTextEdits, parsePureImportBlock } from './import-text-edits.js';
|
|
158
4
|
function importBindingKeys(edits) {
|
|
159
5
|
const keys = new Set();
|
|
160
6
|
for (const edit of edits) {
|
|
@@ -221,21 +67,8 @@ export function coalesceImportChanges(changes, readText) {
|
|
|
221
67
|
continue;
|
|
222
68
|
}
|
|
223
69
|
}
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
continue;
|
|
227
|
-
const existingLines = existingText.replaceAll('\r\n', '\n').split('\n');
|
|
228
|
-
const updatedLines = updated.replaceAll('\r\n', '\n').split('\n');
|
|
229
|
-
// Compute minimal line-1 prefix/suffix diff for applyFix.
|
|
230
|
-
let suffix = 0;
|
|
231
|
-
while (suffix < existingLines.length &&
|
|
232
|
-
suffix < updatedLines.length &&
|
|
233
|
-
existingLines[existingLines.length - 1 - suffix] === updatedLines[updatedLines.length - 1 - suffix]) {
|
|
234
|
-
suffix++;
|
|
235
|
-
}
|
|
236
|
-
const beforeSlice = existingLines.slice(0, existingLines.length - suffix).join('\n');
|
|
237
|
-
const afterSlice = updatedLines.slice(0, updatedLines.length - suffix).join('\n');
|
|
238
|
-
coalesced.push({ file, line: 1, before: beforeSlice, after: afterSlice });
|
|
70
|
+
const textEdits = importTextEdits(existingText, edits, file);
|
|
71
|
+
coalesced.push(...hunksFor({ filename: file, text: existingText, lineStarts: lineStartsOf(existingText) }, textEdits, 0));
|
|
239
72
|
}
|
|
240
73
|
return coalesced;
|
|
241
74
|
}
|
|
@@ -183,7 +183,9 @@ function createWhyCommentTools({ checkerFor, loadTs, }) {
|
|
|
183
183
|
return { edits };
|
|
184
184
|
}
|
|
185
185
|
function rememberCommentRow(fix, file, row) {
|
|
186
|
-
commentAnchors.
|
|
186
|
+
const anchors = commentAnchors.get(fix) ?? [];
|
|
187
|
+
anchors.push({ file, row });
|
|
188
|
+
commentAnchors.set(fix, anchors);
|
|
187
189
|
}
|
|
188
190
|
function withoutWhyComment(fix, ruleId) {
|
|
189
191
|
const comment = fix?.comment ?? whyComment(ruleId);
|
|
@@ -225,21 +227,33 @@ function createWhyCommentTools({ checkerFor, loadTs, }) {
|
|
|
225
227
|
const commentedChanges = new Map();
|
|
226
228
|
for (const finding of findings) {
|
|
227
229
|
const { fix } = finding;
|
|
228
|
-
const
|
|
229
|
-
if (!fix || !
|
|
230
|
+
const anchors = fix && commentAnchors.get(fix);
|
|
231
|
+
if (!fix || !anchors?.length)
|
|
230
232
|
continue;
|
|
231
233
|
const comment = fix.comment ?? whyComment(finding.ruleId);
|
|
232
234
|
const withComment = fix.changes
|
|
233
235
|
.filter((change) => withoutComment(change.after, comment) !== change.after)
|
|
234
236
|
.map((change) => JSON.stringify(change));
|
|
235
237
|
const own = new Set(withoutWhyComment(fix, finding.ruleId).changes.map((change) => JSON.stringify(change)));
|
|
236
|
-
|
|
237
|
-
const
|
|
238
|
-
|
|
239
|
-
|
|
238
|
+
let conflict = false;
|
|
239
|
+
for (const anchor of anchors) {
|
|
240
|
+
const overlapsOther = (changedRows.get(anchor.file) ?? []).some((range) => range.finding !== finding && !own.has(range.key) && range.start <= anchor.row && anchor.row < range.end);
|
|
241
|
+
const anchorKey = anchor.file + '\0' + anchor.row;
|
|
242
|
+
const earlier = commentedChanges.get(anchorKey);
|
|
243
|
+
if (overlapsOther || (earlier && !withComment.every((change) => earlier.has(change)))) {
|
|
244
|
+
conflict = true;
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
if (conflict) {
|
|
240
249
|
finding.fix = withoutWhyComment(fix, finding.ruleId);
|
|
241
|
-
|
|
242
|
-
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
for (const anchor of anchors) {
|
|
253
|
+
const anchorKey = anchor.file + '\0' + anchor.row;
|
|
254
|
+
if (!commentedChanges.has(anchorKey))
|
|
255
|
+
commentedChanges.set(anchorKey, new Set(withComment));
|
|
256
|
+
}
|
|
243
257
|
}
|
|
244
258
|
}
|
|
245
259
|
return {
|
|
@@ -5,6 +5,7 @@ import { existsSync, readFileSync } from 'node:fs';
|
|
|
5
5
|
import { createRequire } from 'node:module';
|
|
6
6
|
import path from 'node:path';
|
|
7
7
|
import * as ts from 'typescript';
|
|
8
|
+
import { packagePath } from '../package-root.js';
|
|
8
9
|
import { pillarOfRule, rulesByPillar } from '../rule-registry.js';
|
|
9
10
|
import { readFixText } from './read-fix-text.js';
|
|
10
11
|
import { writeFileAtomic } from '../system/atomic-write.js';
|
|
@@ -12,6 +13,7 @@ import { createWhyCommentTools, formatComment, withoutComment } from './fix-pres
|
|
|
12
13
|
import { formatInChild, formatRanges, missingPrettierNote, scriptFile } from './fix-presentation-prettier.js';
|
|
13
14
|
import { bottomFirst, followSteps, ownedHunks, rangesOf, replaceRows, segmentsOf, splitRows, styleRegions, } from './fix-presentation-rows.js';
|
|
14
15
|
import { matchFileStyle } from './fix-presentation-style.js';
|
|
16
|
+
const presentationScript = packagePath('dist/lib/shared/fix/fix-presentation.js');
|
|
15
17
|
function checkerFor(ruleId) {
|
|
16
18
|
const pillar = pillarOfRule(ruleId);
|
|
17
19
|
return pillar && rulesByPillar[pillar];
|
|
@@ -65,7 +67,7 @@ function formatUpdates(root, updates) {
|
|
|
65
67
|
ranges: ranges.map(({ start, end }) => [start, end]),
|
|
66
68
|
});
|
|
67
69
|
}
|
|
68
|
-
const stepsByFile = formatRanges(
|
|
70
|
+
const stepsByFile = formatRanges(presentationScript, root, files);
|
|
69
71
|
const texts = new Map();
|
|
70
72
|
const hunks = new Map();
|
|
71
73
|
for (const update of updates) {
|
|
@@ -151,7 +153,7 @@ function createWriteTracker() {
|
|
|
151
153
|
text: readFixText(file),
|
|
152
154
|
ranges: bottomFirst(rangesOf(segments)).map(({ start, end }) => [start, end]),
|
|
153
155
|
}));
|
|
154
|
-
const stepsByFile = formatRanges(
|
|
156
|
+
const stepsByFile = formatRanges(presentationScript, root, files.map(({ file, text, ranges }) => ({ file, text, ranges })));
|
|
155
157
|
for (const { file, segments, text } of files) {
|
|
156
158
|
const steps = stepsByFile?.get(file);
|
|
157
159
|
const beforeRowsOf = (segment) => [...(segment.owners ?? [])].flatMap((owner) => beforeRowsByOwner.get(owner) ?? []);
|
|
@@ -171,7 +173,7 @@ function createWriteTracker() {
|
|
|
171
173
|
},
|
|
172
174
|
};
|
|
173
175
|
}
|
|
174
|
-
if (process.argv[1] && path.resolve(process.argv[1]) ===
|
|
176
|
+
if (process.argv[1] && path.resolve(process.argv[1]) === presentationScript) {
|
|
175
177
|
const input = JSON.parse(readFileSync(0, 'utf8'));
|
|
176
178
|
formatInChild(input, { projectPrettier, loadTs }).then((output) => process.stdout.write(JSON.stringify(output)));
|
|
177
179
|
}
|
|
@@ -59,6 +59,12 @@ function validateSource(file, text) {
|
|
|
59
59
|
function refusalReason(file, syntaxError) {
|
|
60
60
|
return `${file}: the fix would introduce a syntax error (${syntaxError}), so the file was not changed`;
|
|
61
61
|
}
|
|
62
|
+
function explainPassLimit(deferred, passLimit) {
|
|
63
|
+
return deferred.map((refused) => ({
|
|
64
|
+
...refused,
|
|
65
|
+
reason: `${refused.reason} (stopped after reaching the ${passLimit}-pass fix convergence limit; rerun fix to continue)`,
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
62
68
|
// Runs `applyFix` but holds its writes back until every file has passed the syntax check, so a
|
|
63
69
|
// refused fix writes nothing. `readFile`/`writeFile` are the accessors the checker's applyFix
|
|
64
70
|
// takes.
|
|
@@ -86,4 +92,4 @@ function applyFixSafely(applyFix, fix, { readFile, writeFile }, ...options) {
|
|
|
86
92
|
writeFile(file, text);
|
|
87
93
|
return result;
|
|
88
94
|
}
|
|
89
|
-
export { applyFixSafely, introducedSyntaxError, refusalReason, validateSource };
|
|
95
|
+
export { applyFixSafely, explainPassLimit, introducedSyntaxError, refusalReason, validateSource };
|
|
@@ -8,13 +8,16 @@ function findTsConfig(directory) {
|
|
|
8
8
|
let current = path.resolve(directory);
|
|
9
9
|
for (;;) {
|
|
10
10
|
if (isTempRoot(current))
|
|
11
|
-
return
|
|
11
|
+
return { hitGitRoot: false };
|
|
12
12
|
const candidate = path.join(current, 'tsconfig.json');
|
|
13
13
|
if (safeExists(candidate))
|
|
14
|
-
return candidate;
|
|
14
|
+
return { path: candidate, hitGitRoot: false };
|
|
15
|
+
// Stop at the enclosing Git repository root so an unrelated parent tsconfig never claims an independent repo.
|
|
16
|
+
if (safeExists(path.join(current, '.git')))
|
|
17
|
+
return { hitGitRoot: true };
|
|
15
18
|
const parent = path.dirname(current);
|
|
16
19
|
if (parent === current)
|
|
17
|
-
return
|
|
20
|
+
return { hitGitRoot: false };
|
|
18
21
|
current = parent;
|
|
19
22
|
}
|
|
20
23
|
}
|
|
@@ -160,7 +163,8 @@ export function introducedTypeErrors(directory, originals, updates, describeRefu
|
|
|
160
163
|
return refusals;
|
|
161
164
|
const byTsConfig = new Map();
|
|
162
165
|
for (const file of tsFiles) {
|
|
163
|
-
const
|
|
166
|
+
const fileConfig = findTsConfig(path.dirname(file));
|
|
167
|
+
const tsconfigPath = fileConfig.path ?? (fileConfig.hitGitRoot ? undefined : findTsConfig(directory).path);
|
|
164
168
|
if (!tsconfigPath)
|
|
165
169
|
continue;
|
|
166
170
|
const list = byTsConfig.get(tsconfigPath) ?? [];
|