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
|
@@ -41,6 +41,14 @@ function toNumber(value) {
|
|
|
41
41
|
function tableKey(schema, name) {
|
|
42
42
|
return `${schema}.${name}`;
|
|
43
43
|
}
|
|
44
|
+
function quoteDottedPart(name) {
|
|
45
|
+
return /[."]/.test(name) ? quoteIdent(name) : name;
|
|
46
|
+
}
|
|
47
|
+
// Keep ordinary catalog keys stable. Quote a component when it could otherwise be read as
|
|
48
|
+
// multiple components or be mistaken for an already quoted name.
|
|
49
|
+
function postgresTableKey(schema, name) {
|
|
50
|
+
return `${quoteDottedPart(schema)}.${quoteDottedPart(name)}`;
|
|
51
|
+
}
|
|
44
52
|
function qualified(schema, name) {
|
|
45
53
|
return `${quoteIdent(schema)}.${quoteIdent(name)}`;
|
|
46
54
|
}
|
|
@@ -91,7 +99,7 @@ function rowEstimateOf(row) {
|
|
|
91
99
|
function buildPostgresModel({ tables = [], columns = [], indexes = [], foreignKeys = [], }) {
|
|
92
100
|
const model = new Map();
|
|
93
101
|
for (const row of tables) {
|
|
94
|
-
model.set(
|
|
102
|
+
model.set(postgresTableKey(row.schema_name, row.table_name), {
|
|
95
103
|
schema: row.schema_name,
|
|
96
104
|
name: row.table_name,
|
|
97
105
|
rowEstimate: rowEstimateOf(row),
|
|
@@ -105,7 +113,7 @@ function buildPostgresModel({ tables = [], columns = [], indexes = [], foreignKe
|
|
|
105
113
|
foreignKeys: [],
|
|
106
114
|
});
|
|
107
115
|
}
|
|
108
|
-
const tableOf = (row) => model.get(
|
|
116
|
+
const tableOf = (row) => model.get(postgresTableKey(row.schema_name, row.table_name));
|
|
109
117
|
for (const row of columns)
|
|
110
118
|
tableOf(row)?.columns.push(row.column_name);
|
|
111
119
|
for (const row of indexes)
|
|
@@ -114,7 +122,10 @@ function buildPostgresModel({ tables = [], columns = [], indexes = [], foreignKe
|
|
|
114
122
|
tableOf(row)?.foreignKeys.push({
|
|
115
123
|
name: row.constraint_name,
|
|
116
124
|
columns: row.columns,
|
|
117
|
-
references: {
|
|
125
|
+
references: {
|
|
126
|
+
table: postgresTableKey(row.referenced_schema, row.referenced_table),
|
|
127
|
+
columns: row.referenced_columns,
|
|
128
|
+
},
|
|
118
129
|
});
|
|
119
130
|
}
|
|
120
131
|
return model;
|
|
@@ -150,7 +161,7 @@ function unindexedForeignKeys(model) {
|
|
|
150
161
|
const fix = createIndexSql(table, foreignKey.columns);
|
|
151
162
|
const columnList = foreignKey.columns.map((column) => `\`${column}\``).join(', ');
|
|
152
163
|
findings.push({
|
|
153
|
-
target:
|
|
164
|
+
target: postgresTableKey(table.schema, table.name),
|
|
154
165
|
ruleId: 'db-unindexed-foreign-key',
|
|
155
166
|
message: `Foreign key \`${foreignKey.name}\` (${columnList}) references \`${foreignKey.references.table}\` and no ` +
|
|
156
167
|
`index starts with it, so joins on it scan \`${table.name}\` and every delete or key update on the ` +
|
|
@@ -178,7 +189,7 @@ function unusedIndexes(model, statsAgeDays) {
|
|
|
178
189
|
const size = index.sizeBytes === undefined ? '' : ` It takes ${formatBytes(index.sizeBytes)} (measured) and`;
|
|
179
190
|
const age = sinceEvent(statsAgeDays, 'statistics were reset');
|
|
180
191
|
const finding = {
|
|
181
|
-
target:
|
|
192
|
+
target: postgresTableKey(table.schema, table.name),
|
|
182
193
|
ruleId: 'db-unused-index',
|
|
183
194
|
message: `Index \`${index.name}\` on \`${table.name}\` was scanned 0 times (measured) ${age} on this server; ` +
|
|
184
195
|
`replicas keep their own counters and are not counted.${size || ' It'} slows every write to the table. ` +
|
|
@@ -243,7 +254,7 @@ function tableDuplicateIndexes(table) {
|
|
|
243
254
|
const fix = dropIndexSql(table, redundant);
|
|
244
255
|
const relation = redundant.keys.length === kept.keys.length ? 'has the same keys as' : 'is a leading prefix of';
|
|
245
256
|
findings.push({
|
|
246
|
-
target:
|
|
257
|
+
target: postgresTableKey(table.schema, table.name),
|
|
247
258
|
ruleId: 'db-duplicate-index',
|
|
248
259
|
message: `Index \`${redundant.name}\` (${describeKeys(redundant)}) ${relation} \`${kept.name}\` ` +
|
|
249
260
|
`(${describeKeys(kept)}), which serves the same lookups, so it only slows writes. Drop it: \`${fix}\``,
|
|
@@ -268,7 +279,7 @@ function seqScanHeavyTables(model, statsAgeDays) {
|
|
|
268
279
|
continue;
|
|
269
280
|
const period = sinceEvent(statsAgeDays, 'statistics were reset');
|
|
270
281
|
findings.push({
|
|
271
|
-
target:
|
|
282
|
+
target: postgresTableKey(table.schema, table.name),
|
|
272
283
|
ruleId: 'db-seq-scan-heavy-table',
|
|
273
284
|
message: `\`${table.name}\` had ${formatCount(seqScan)} sequential scans reading ${formatCount(seqTupRead)} rows ` +
|
|
274
285
|
`against ${formatCount(idxScan ?? 0)} index scans ${period} (measured counters), and holds about ` +
|
|
@@ -395,4 +406,4 @@ function mysqlRedundantIndexes(model, rows) {
|
|
|
395
406
|
function mysqlCatalogFindings(model, { unusedIndexes: unusedRows = [], redundantIndexes = [], uptimeDays } = {}) {
|
|
396
407
|
return [...mysqlUnusedIndexes(model, unusedRows, uptimeDays), ...mysqlRedundantIndexes(model, redundantIndexes)];
|
|
397
408
|
}
|
|
398
|
-
export { buildMysqlModel, mysqlCatalogFindings, sizeGateRows, minimumStatsAgeDays, formatCount, sinceEvent, formatBytes, tableKey, generatedIndexName, createIndexSql, buildPostgresModel, redundantPair, sizeGate, sizeNote, postgresCatalogFindings, };
|
|
409
|
+
export { buildMysqlModel, mysqlCatalogFindings, sizeGateRows, minimumStatsAgeDays, formatCount, sinceEvent, formatBytes, tableKey, postgresTableKey, generatedIndexName, createIndexSql, buildPostgresModel, redundantPair, sizeGate, sizeNote, postgresCatalogFindings, };
|
|
@@ -79,7 +79,9 @@ function createGateway(adapter, options = {}) {
|
|
|
79
79
|
interrupted = true;
|
|
80
80
|
rollbackOrDestroy(rollbackStatement)
|
|
81
81
|
.then(() => destroy())
|
|
82
|
-
.catch(() => {
|
|
82
|
+
.catch(() => {
|
|
83
|
+
// The session is being torn down on interrupt, so a failed destroy has nowhere to be reported.
|
|
84
|
+
})
|
|
83
85
|
.finally(() => exit(interruptExitCode));
|
|
84
86
|
};
|
|
85
87
|
signals.on('SIGINT', onInterrupt);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { sizeGateRows } from './checks.js';
|
|
1
|
+
import { postgresTableKey, sizeGateRows } from './checks.js';
|
|
2
2
|
// Estimate-only pass over EXPLAIN without ANALYZE: lib/plans.cjs needs actual row counts, which a
|
|
3
3
|
// generic plan lacks.
|
|
4
4
|
const maxQueryTextLength = 300;
|
|
@@ -45,7 +45,7 @@ function resolveTable(model, node) {
|
|
|
45
45
|
if (!name)
|
|
46
46
|
return;
|
|
47
47
|
if (node.Schema)
|
|
48
|
-
return model.get(
|
|
48
|
+
return model.get(postgresTableKey(node.Schema, name));
|
|
49
49
|
const matches = [...model.values()].filter((table) => table.name === name);
|
|
50
50
|
if (matches.length === 1)
|
|
51
51
|
return matches[0];
|
|
@@ -113,7 +113,7 @@ function hypotheticalImpact(hypothetical) {
|
|
|
113
113
|
function planFinding({ subject, location, candidate, fix, hypothetical, measured }) {
|
|
114
114
|
const { table } = candidate;
|
|
115
115
|
const columns = candidate.columns.map((column) => `\`${column}\``).join(', ');
|
|
116
|
-
const scan = `${subject} plans a sequential scan of \`${table.schema
|
|
116
|
+
const scan = `${subject} plans a sequential scan of \`${postgresTableKey(table.schema, table.name)}\` (about ` +
|
|
117
117
|
`${Math.round(table.rowEstimate).toLocaleString('en-US')} rows, estimated) filtering on ${columns}.`;
|
|
118
118
|
const validated = Boolean(measured) || Boolean(hypothetical?.used);
|
|
119
119
|
let advice;
|
|
@@ -132,7 +132,7 @@ function planFinding({ subject, location, candidate, fix, hypothetical, measured
|
|
|
132
132
|
advice = ` Add \`${fix}\`, then confirm the plan change with HypoPG or \`--measure\` on staging.`;
|
|
133
133
|
}
|
|
134
134
|
const finding = {
|
|
135
|
-
...(location ?? { target:
|
|
135
|
+
...(location ?? { target: postgresTableKey(table.schema, table.name) }),
|
|
136
136
|
ruleId: validated ? 'db-missing-index' : 'db-slow-query-plan',
|
|
137
137
|
message: scan + advice,
|
|
138
138
|
suggestion: fix,
|
|
@@ -109,6 +109,9 @@ const nativeSyntax = {
|
|
|
109
109
|
SymbolFlags,
|
|
110
110
|
TypeFlags,
|
|
111
111
|
getCombinedModifierFlags,
|
|
112
|
+
// A skipped array binding slot is a nameless BindingElement in the native tree.
|
|
113
|
+
isOmittedExpression: (node) => guards.isOmittedExpression(node) || (guards.isBindingElement(node) && !node.name),
|
|
114
|
+
isBindingElement: (node) => guards.isBindingElement(node) && Boolean(node.name),
|
|
112
115
|
isFunctionLike: guards.isFunctionLikeDeclaration,
|
|
113
116
|
isClassLike: guards.isClassLikeDeclaration,
|
|
114
117
|
isParameter: guards.isParameterDeclaration,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import { compareFindings, isInScope, isSourceInput, mergeFinding, scanEntries, relativeToWorkingDirectory, resolveConfig, } from '../analysis/source-inputs.js';
|
|
3
|
+
import { compareFindings, isInScope, isSourceInput, scopedProjectRoots, mergeFinding, scanEntries, relativeToWorkingDirectory, resolveConfig, } from '../analysis/source-inputs.js';
|
|
4
4
|
import { withoutEmitOptions } from '../cli/emit-options.js';
|
|
5
5
|
import { selectNativeSyntax } from './compiler.js';
|
|
6
6
|
import { requireNative, executable } from './native-runtime.js';
|
|
@@ -115,7 +115,7 @@ function withoutRemovedOptions(options, { ModuleKind, ModuleResolutionKind }) {
|
|
|
115
115
|
}
|
|
116
116
|
// With fallback, an unavailable compiler or a rejected config returns { fallback: true, reason }
|
|
117
117
|
// before the native syntax is selected, so the caller can run the JS engine in this process.
|
|
118
|
-
// `project` is one config or an array of them. `onlyFiles` limits
|
|
118
|
+
// `project` is one config or an array of them. `onlyFiles` limits reportable roots while retaining configured declarations;
|
|
119
119
|
// imports still resolve through the config. `analyzers` defaults to the performance rules; each
|
|
120
120
|
// one's
|
|
121
121
|
// `analyzeFile` must load its rules lazily, after the native syntax is selected.
|
|
@@ -138,6 +138,8 @@ function scanNative({ project, files = [], standaloneFiles = [], standaloneScope
|
|
|
138
138
|
// Chosen once the native syntax is selected, because the default analyzer loads its rules lazily.
|
|
139
139
|
let selectedAnalyzers = [];
|
|
140
140
|
const visitedConfigs = new Set();
|
|
141
|
+
let usesReferences = false;
|
|
142
|
+
const multipleProjects = [project].flat().length > 1;
|
|
141
143
|
const notedRootFiles = new Set();
|
|
142
144
|
// Folders scanned with a config that leaves JavaScript out.
|
|
143
145
|
const scopesWithoutJs = new Map();
|
|
@@ -196,13 +198,13 @@ function scanNative({ project, files = [], standaloneFiles = [], standaloneScope
|
|
|
196
198
|
const inputs = roots.filter((filename) => isSourceInput(filename) && analyzes(filename));
|
|
197
199
|
if (!inputs.length)
|
|
198
200
|
return;
|
|
199
|
-
const program = api.createProgram(roots, { ...options, noEmit: true });
|
|
201
|
+
const program = api.createProgram(roots, { ...withoutRemovedOptions(options, binding), noEmit: true });
|
|
200
202
|
try {
|
|
201
203
|
checkErrors(program.getProgramDiagnostics());
|
|
202
204
|
// The native service accepts an array, saving a round-trip per input.
|
|
203
205
|
const syntaxErrorsByFile = Map.groupBy(program.getSyntacticDiagnostics(inputs), (diagnostic) => canonical(diagnostic.fileName));
|
|
204
206
|
const adapter = adaptProgram(program, options);
|
|
205
|
-
if (!files.length && !onlyFiles && visitedConfigs.size
|
|
207
|
+
if (!files.length && !onlyFiles && visitedConfigs.size > 0 && !usesReferences && !multipleProjects)
|
|
206
208
|
enableSchemaTooling(adapter);
|
|
207
209
|
const localFiles = new Set();
|
|
208
210
|
for (const filename of inputs) {
|
|
@@ -275,7 +277,9 @@ function scanNative({ project, files = [], standaloneFiles = [], standaloneScope
|
|
|
275
277
|
// leaves the JavaScript out still has that JavaScript checked, so TS18003 waits for the final source count.
|
|
276
278
|
const allowsJs = parsed.options.allowJs ?? parsed.options.checkJs;
|
|
277
279
|
checkConfig(parsed.errors?.filter((diagnostic) => !isIgnorableUnknownOption(diagnostic) && !(diagnostic.code === noInputsCode && !allowsJs && !explicit)));
|
|
278
|
-
const options = withWorkspaceSources(
|
|
280
|
+
const options = withWorkspaceSources(withoutBaseUrl(withoutEmitOptions(parsed.options)), path.dirname(filename));
|
|
281
|
+
if (parsed.projectReferences?.length)
|
|
282
|
+
usesReferences = true;
|
|
279
283
|
for (const reference of parsed.projectReferences ?? []) {
|
|
280
284
|
visitConfig(resolveConfig(reference.path), projects, scope, false, explicit);
|
|
281
285
|
}
|
|
@@ -294,11 +298,11 @@ function scanNative({ project, files = [], standaloneFiles = [], standaloneScope
|
|
|
294
298
|
standaloneRoots.add(folder);
|
|
295
299
|
}
|
|
296
300
|
}
|
|
297
|
-
const rootFiles =
|
|
301
|
+
const rootFiles = scopedProjectRoots(existing, onlyFiles);
|
|
298
302
|
if (!rootFiles.some((filename) => isSourceInput(filename) && isInScope(scope, filename)))
|
|
299
303
|
return;
|
|
300
304
|
// Option diagnostics do not depend on root files, so an empty program reports them cheaply.
|
|
301
|
-
const optionsProgram = api.createProgram([], { ...options, noEmit: true });
|
|
305
|
+
const optionsProgram = api.createProgram([], { ...withoutRemovedOptions(options, binding), noEmit: true });
|
|
302
306
|
try {
|
|
303
307
|
checkConfig(optionsProgram.getProgramDiagnostics());
|
|
304
308
|
}
|
|
@@ -115,13 +115,15 @@ function inspectPostgres(root) {
|
|
|
115
115
|
});
|
|
116
116
|
}
|
|
117
117
|
const plans = children(node.Plans ?? []);
|
|
118
|
-
const
|
|
119
|
-
|
|
118
|
+
const primaryChildren = plans.filter((child) => {
|
|
119
|
+
const relationship = member(child, 'Parent Relationship');
|
|
120
|
+
return !(typeof relationship === 'string' && ['InitPlan', 'SubPlan'].includes(relationship));
|
|
121
|
+
});
|
|
122
|
+
const [onlyChild] = primaryChildren;
|
|
120
123
|
if (node['Node Type'] === 'Limit' &&
|
|
121
|
-
|
|
124
|
+
primaryChildren.length === 1 &&
|
|
122
125
|
object(onlyChild) &&
|
|
123
|
-
onlyChild['Actual Loops'] === loops
|
|
124
|
-
!(typeof relationship === 'string' && ['InitPlan', 'SubPlan'].includes(relationship))) {
|
|
126
|
+
onlyChild['Actual Loops'] === loops) {
|
|
125
127
|
const childAverage = count(onlyChild['Actual Rows'], 'limit child Actual Rows', true);
|
|
126
128
|
const walked = count(Math.round(childAverage * loops), 'limit child total rows');
|
|
127
129
|
const returned = count(Math.round(averageRows * loops), 'limit total rows');
|
|
@@ -35,6 +35,8 @@ function isRecord(value) {
|
|
|
35
35
|
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
36
36
|
}
|
|
37
37
|
function records(value, field) {
|
|
38
|
+
if (value === undefined)
|
|
39
|
+
return [];
|
|
38
40
|
if (!Array.isArray(value) || !value.every(isRecord)) {
|
|
39
41
|
throw new TypeError(`Expected an OTLP array of objects at ${field}.`);
|
|
40
42
|
}
|
|
@@ -116,11 +118,29 @@ function spanAttributes(list = [], state) {
|
|
|
116
118
|
function digest(value) {
|
|
117
119
|
return createHash('sha256').update(value).digest('hex');
|
|
118
120
|
}
|
|
121
|
+
function canonicalizeAttributeValue(value) {
|
|
122
|
+
if ('arrayValue' in value && isRecord(value.arrayValue)) {
|
|
123
|
+
const values = Array.isArray(value.arrayValue.values) ? value.arrayValue.values : [];
|
|
124
|
+
return { arrayValue: { values: values.map((entry) => canonicalizeAttributeValue(entry)) } };
|
|
125
|
+
}
|
|
126
|
+
if ('kvlistValue' in value && isRecord(value.kvlistValue)) {
|
|
127
|
+
const entries = Array.isArray(value.kvlistValue.values) ? [...value.kvlistValue.values] : [];
|
|
128
|
+
entries.sort((left, right) => (left.key < right.key ? -1 : left.key > right.key ? 1 : 0));
|
|
129
|
+
return {
|
|
130
|
+
kvlistValue: {
|
|
131
|
+
values: entries.map((entry) => ({ key: entry.key, value: canonicalizeAttributeValue(entry.value) })),
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
return value;
|
|
136
|
+
}
|
|
119
137
|
function resourceIdentity(resource) {
|
|
120
138
|
if (resource !== undefined && !isRecord(resource))
|
|
121
139
|
throw new TypeError('Invalid OTLP resource.');
|
|
122
140
|
const attributes = readAttributes(isRecord(resource) ? resource.attributes : undefined, 'resource.attributes');
|
|
123
|
-
const ordered = [...attributes.keys()]
|
|
141
|
+
const ordered = [...attributes.keys()]
|
|
142
|
+
.sort()
|
|
143
|
+
.map((key) => [key, canonicalizeAttributeValue(attributes.get(key) ?? {})]);
|
|
124
144
|
return digest(JSON.stringify(ordered));
|
|
125
145
|
}
|
|
126
146
|
function id(value, pattern, field) {
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { ts } from '../engine/compiler.js';
|
|
2
|
+
import { propertyName } from '../schema/ts-helpers.js';
|
|
3
|
+
import { importedName, walkSkippingFunctions } from './frontend-helpers.js';
|
|
4
|
+
import { mayExit } from './effect-cleanup.js';
|
|
5
|
+
export function thisField(expression) {
|
|
6
|
+
return expression &&
|
|
7
|
+
ts.isPropertyAccessExpression(expression) &&
|
|
8
|
+
expression.expression.kind === ts.SyntaxKind.ThisKeyword
|
|
9
|
+
? expression.name.text
|
|
10
|
+
: undefined;
|
|
11
|
+
}
|
|
12
|
+
export function subscriptionField(call, teardown) {
|
|
13
|
+
const parent = call.parent;
|
|
14
|
+
if (ts.isCallExpression(parent) &&
|
|
15
|
+
parent.arguments[0] === call &&
|
|
16
|
+
ts.isPropertyAccessExpression(parent.expression) &&
|
|
17
|
+
parent.expression.name.text === 'add') {
|
|
18
|
+
const composite = thisField(parent.expression.expression);
|
|
19
|
+
if (composite && teardown.composites.has(composite))
|
|
20
|
+
return composite;
|
|
21
|
+
}
|
|
22
|
+
if (ts.isPropertyDeclaration(parent) && parent.initializer === call)
|
|
23
|
+
return propertyName(parent);
|
|
24
|
+
if (ts.isBinaryExpression(parent) && parent.right === call && parent.operatorToken.kind === ts.SyntaxKind.EqualsToken)
|
|
25
|
+
return thisField(parent.left);
|
|
26
|
+
}
|
|
27
|
+
function releasedOnPath(statement, field, method, continuation) {
|
|
28
|
+
if (ts.isBlock(statement))
|
|
29
|
+
return statement.statements.reduceRight((next, child) => releasedOnPath(child, field, method, next), continuation);
|
|
30
|
+
if (ts.isIfStatement(statement)) {
|
|
31
|
+
const condition = ts.skipOuterExpressions(statement.expression);
|
|
32
|
+
if (thisField(condition) === field)
|
|
33
|
+
return releasedOnPath(statement.thenStatement, field, method, continuation);
|
|
34
|
+
const otherwise = !statement.elseStatement
|
|
35
|
+
? continuation
|
|
36
|
+
: releasedOnPath(statement.elseStatement, field, method, continuation);
|
|
37
|
+
if (ts.isPrefixUnaryExpression(condition) &&
|
|
38
|
+
condition.operator === ts.SyntaxKind.ExclamationToken &&
|
|
39
|
+
thisField(condition.operand) === field)
|
|
40
|
+
return otherwise;
|
|
41
|
+
return otherwise && releasedOnPath(statement.thenStatement, field, method, continuation);
|
|
42
|
+
}
|
|
43
|
+
const expression = ts.isExpressionStatement(statement) || ts.isReturnStatement(statement) ? statement.expression : undefined;
|
|
44
|
+
return ((expression !== undefined && releasesField(expression, field, method)) || (continuation && !mayExit(statement)));
|
|
45
|
+
}
|
|
46
|
+
function releasesField(expression, field, method) {
|
|
47
|
+
const value = ts.skipOuterExpressions(expression);
|
|
48
|
+
if (ts.isBinaryExpression(value) && value.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken)
|
|
49
|
+
return thisField(ts.skipOuterExpressions(value.left)) === field && releasesField(value.right, field, method);
|
|
50
|
+
if (!ts.isCallExpression(value) || !ts.isPropertyAccessExpression(value.expression))
|
|
51
|
+
return false;
|
|
52
|
+
return value.expression.name.text === method && thisField(value.expression.expression) === field;
|
|
53
|
+
}
|
|
54
|
+
function collectReleases(body, teardown) {
|
|
55
|
+
const candidates = new Map();
|
|
56
|
+
walkSkippingFunctions(body, (node) => {
|
|
57
|
+
if (!ts.isCallExpression(node) || !ts.isPropertyAccessExpression(node.expression))
|
|
58
|
+
return;
|
|
59
|
+
const method = node.expression.name.text;
|
|
60
|
+
const field = thisField(node.expression.expression);
|
|
61
|
+
if (!field || (method !== 'unsubscribe' && method !== 'next'))
|
|
62
|
+
return;
|
|
63
|
+
const fields = candidates.get(method) ?? new Set();
|
|
64
|
+
fields.add(field);
|
|
65
|
+
candidates.set(method, fields);
|
|
66
|
+
});
|
|
67
|
+
for (const [method, fields] of candidates) {
|
|
68
|
+
const released = method === 'unsubscribe' ? teardown.subscriptions : teardown.notifiers;
|
|
69
|
+
for (const field of fields)
|
|
70
|
+
if (releasedOnPath(body, field, method, false))
|
|
71
|
+
released.add(field);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
export function angularTeardown(classNode, checker) {
|
|
75
|
+
const teardown = {
|
|
76
|
+
subscriptions: new Set(),
|
|
77
|
+
composites: new Set(),
|
|
78
|
+
notifiers: new Set(),
|
|
79
|
+
ownedNotifiers: new Set(),
|
|
80
|
+
};
|
|
81
|
+
for (const member of classNode.members) {
|
|
82
|
+
if (ts.isMethodDeclaration(member) && propertyName(member) === 'ngOnDestroy' && member.body)
|
|
83
|
+
collectReleases(member.body, teardown);
|
|
84
|
+
if (!ts.isPropertyDeclaration(member) || !member.initializer || !ts.isNewExpression(member.initializer))
|
|
85
|
+
continue;
|
|
86
|
+
const field = propertyName(member);
|
|
87
|
+
if (!field)
|
|
88
|
+
continue;
|
|
89
|
+
const type = importedName(member.initializer.expression, checker, ['rxjs']);
|
|
90
|
+
if (type === 'Subscription')
|
|
91
|
+
teardown.composites.add(field);
|
|
92
|
+
if (type === 'Subject' || type === 'ReplaySubject' || type === 'AsyncSubject')
|
|
93
|
+
teardown.ownedNotifiers.add(field);
|
|
94
|
+
}
|
|
95
|
+
return teardown;
|
|
96
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { ts } from '../engine/compiler.js';
|
|
2
|
+
import { isBrowserGlobal, walkSkippingFunctions } from './frontend-helpers.js';
|
|
3
|
+
// Unknown options can run getters or change between registration and removal.
|
|
4
|
+
export function listenerCapture(options) {
|
|
5
|
+
if (!options || options.kind === ts.SyntaxKind.FalseKeyword)
|
|
6
|
+
return false;
|
|
7
|
+
if (options.kind === ts.SyntaxKind.TrueKeyword)
|
|
8
|
+
return true;
|
|
9
|
+
if (!ts.isObjectLiteralExpression(options))
|
|
10
|
+
return;
|
|
11
|
+
let capture = false;
|
|
12
|
+
for (const property of options.properties) {
|
|
13
|
+
if (!ts.isPropertyAssignment(property) || ts.isComputedPropertyName(property.name))
|
|
14
|
+
return;
|
|
15
|
+
if (property.name.text !== 'capture')
|
|
16
|
+
continue;
|
|
17
|
+
if (property.initializer.kind === ts.SyntaxKind.TrueKeyword)
|
|
18
|
+
capture = true;
|
|
19
|
+
else if (property.initializer.kind === ts.SyntaxKind.FalseKeyword)
|
|
20
|
+
capture = false;
|
|
21
|
+
else
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
return capture;
|
|
25
|
+
}
|
|
26
|
+
function sameValue(left, right, checker) {
|
|
27
|
+
if (!left || !right)
|
|
28
|
+
return false;
|
|
29
|
+
if (ts.isStringLiteralLike(left) && ts.isStringLiteralLike(right))
|
|
30
|
+
return left.text === right.text;
|
|
31
|
+
if (ts.isIdentifier(left) && ts.isIdentifier(right)) {
|
|
32
|
+
const symbol = checker.getSymbolAtLocation(left);
|
|
33
|
+
return !!symbol && symbol === checker.getSymbolAtLocation(right);
|
|
34
|
+
}
|
|
35
|
+
return (ts.isPropertyAccessExpression(left) &&
|
|
36
|
+
ts.isPropertyAccessExpression(right) &&
|
|
37
|
+
left.name.text === right.name.text &&
|
|
38
|
+
sameValue(left.expression, right.expression, checker));
|
|
39
|
+
}
|
|
40
|
+
export function releases(acquisition, method, release, checker) {
|
|
41
|
+
if (!ts.isCallExpression(release))
|
|
42
|
+
return false;
|
|
43
|
+
if (method === 'removeEventListener') {
|
|
44
|
+
if (!ts.isCallExpression(acquisition) ||
|
|
45
|
+
!ts.isPropertyAccessExpression(acquisition.expression) ||
|
|
46
|
+
!ts.isPropertyAccessExpression(release.expression) ||
|
|
47
|
+
release.expression.name.text !== method)
|
|
48
|
+
return false;
|
|
49
|
+
const capture = listenerCapture(acquisition.arguments[2]);
|
|
50
|
+
return (capture !== undefined &&
|
|
51
|
+
capture === listenerCapture(release.arguments[2]) &&
|
|
52
|
+
sameValue(acquisition.expression.expression, release.expression.expression, checker) &&
|
|
53
|
+
sameValue(acquisition.arguments[0], release.arguments[0], checker) &&
|
|
54
|
+
sameValue(acquisition.arguments[1], release.arguments[1], checker));
|
|
55
|
+
}
|
|
56
|
+
const owner = acquisition.parent;
|
|
57
|
+
if (!ts.isVariableDeclaration(owner) || !ts.isIdentifier(owner.name))
|
|
58
|
+
return false;
|
|
59
|
+
if (method === 'clearInterval')
|
|
60
|
+
return (((ts.isIdentifier(release.expression) && release.expression.text === method) ||
|
|
61
|
+
(ts.isPropertyAccessExpression(release.expression) && release.expression.name.text === method)) &&
|
|
62
|
+
isBrowserGlobal(release.expression, checker) &&
|
|
63
|
+
sameValue(owner.name, release.arguments[0], checker));
|
|
64
|
+
return (ts.isPropertyAccessExpression(release.expression) &&
|
|
65
|
+
release.expression.name.text === method &&
|
|
66
|
+
sameValue(owner.name, release.expression.expression, checker));
|
|
67
|
+
}
|
|
68
|
+
export function mayExit(node) {
|
|
69
|
+
if (ts.isFunctionLike(node))
|
|
70
|
+
return false;
|
|
71
|
+
return (ts.isReturnStatement(node) ||
|
|
72
|
+
ts.isThrowStatement(node) ||
|
|
73
|
+
(ts.forEachChild(node, (child) => mayExit(child) || undefined) ?? false));
|
|
74
|
+
}
|
|
75
|
+
function alwaysReturns(node) {
|
|
76
|
+
if (ts.isReturnStatement(node))
|
|
77
|
+
return true;
|
|
78
|
+
if (ts.isIfStatement(node))
|
|
79
|
+
return !!node.elseStatement && alwaysReturns(node.thenStatement) && alwaysReturns(node.elseStatement);
|
|
80
|
+
return ts.isBlock(node) && node.statements.some(alwaysReturns);
|
|
81
|
+
}
|
|
82
|
+
// Work backwards so both arms of an if share the same continuation without enumerating paths.
|
|
83
|
+
function disposesOnEveryPath(statement, continuation, matches) {
|
|
84
|
+
if (ts.isBlock(statement))
|
|
85
|
+
return statement.statements.reduceRight((next, child) => disposesOnEveryPath(child, next, matches), continuation);
|
|
86
|
+
if (ts.isIfStatement(statement))
|
|
87
|
+
return (disposesOnEveryPath(statement.thenStatement, continuation, matches) &&
|
|
88
|
+
(statement.elseStatement ? disposesOnEveryPath(statement.elseStatement, continuation, matches) : continuation));
|
|
89
|
+
if (ts.isReturnStatement(statement))
|
|
90
|
+
return !!statement.expression && matches(statement.expression);
|
|
91
|
+
if (ts.isExpressionStatement(statement))
|
|
92
|
+
return continuation || matches(statement.expression);
|
|
93
|
+
return continuation && !mayExit(statement);
|
|
94
|
+
}
|
|
95
|
+
function returnedDisposes(expression, matches) {
|
|
96
|
+
if (!expression)
|
|
97
|
+
return false;
|
|
98
|
+
const disposer = ts.skipOuterExpressions(expression);
|
|
99
|
+
if (ts.isConditionalExpression(disposer))
|
|
100
|
+
return returnedDisposes(disposer.whenTrue, matches) && returnedDisposes(disposer.whenFalse, matches);
|
|
101
|
+
if (!ts.isArrowFunction(disposer) && !ts.isFunctionExpression(disposer)) {
|
|
102
|
+
// A helper can own the resource even if its implementation is outside this callback.
|
|
103
|
+
return ((ts.isIdentifier(disposer) && disposer.text !== 'undefined') ||
|
|
104
|
+
ts.isCallExpression(disposer) ||
|
|
105
|
+
ts.isPropertyAccessExpression(disposer));
|
|
106
|
+
}
|
|
107
|
+
return ts.isBlock(disposer.body) ? disposesOnEveryPath(disposer.body, false, matches) : matches(disposer.body);
|
|
108
|
+
}
|
|
109
|
+
export function effectCleanup(body) {
|
|
110
|
+
const cleanup = { alwaysReturns: alwaysReturns(body), returns: [] };
|
|
111
|
+
if (cleanup.alwaysReturns)
|
|
112
|
+
walkSkippingFunctions(body, (node) => {
|
|
113
|
+
if (ts.isReturnStatement(node))
|
|
114
|
+
cleanup.returns.push(node);
|
|
115
|
+
});
|
|
116
|
+
return cleanup;
|
|
117
|
+
}
|
|
118
|
+
export function effectDisposes(cleanup, site, checker, matches) {
|
|
119
|
+
if (!cleanup.alwaysReturns)
|
|
120
|
+
return false;
|
|
121
|
+
const activeHelpers = new Set();
|
|
122
|
+
function matchesCleanup(expression) {
|
|
123
|
+
if (matches(expression))
|
|
124
|
+
return true;
|
|
125
|
+
if (!ts.isCallExpression(expression) || expression.arguments.length || !ts.isIdentifier(expression.expression))
|
|
126
|
+
return false;
|
|
127
|
+
const declaration = checker.getSymbolAtLocation(expression.expression)?.valueDeclaration;
|
|
128
|
+
if (!declaration || declaration.getSourceFile() !== site.getSourceFile())
|
|
129
|
+
return false;
|
|
130
|
+
const helper = ts.isVariableDeclaration(declaration) && declaration.parent.flags & ts.NodeFlags.Const && declaration.initializer
|
|
131
|
+
? ts.skipOuterExpressions(declaration.initializer)
|
|
132
|
+
: declaration;
|
|
133
|
+
if ((!ts.isArrowFunction(helper) && !ts.isFunctionExpression(helper) && !ts.isFunctionDeclaration(helper)) ||
|
|
134
|
+
!helper.body ||
|
|
135
|
+
helper.asteriskToken ||
|
|
136
|
+
helper.parameters.length ||
|
|
137
|
+
activeHelpers.has(helper))
|
|
138
|
+
return false;
|
|
139
|
+
activeHelpers.add(helper);
|
|
140
|
+
const result = ts.isBlock(helper.body)
|
|
141
|
+
? disposesOnEveryPath(helper.body, false, matchesCleanup)
|
|
142
|
+
: matchesCleanup(helper.body);
|
|
143
|
+
activeHelpers.delete(helper);
|
|
144
|
+
return result;
|
|
145
|
+
}
|
|
146
|
+
const exits = cleanup.returns.filter((exit) => exit.end > site.end);
|
|
147
|
+
return exits.length > 0 && exits.every((exit) => returnedDisposes(exit.expression, matchesCleanup));
|
|
148
|
+
}
|
|
@@ -293,15 +293,27 @@ function heavyBarrelOf(moduleName, clause) {
|
|
|
293
293
|
return isNamespace ? { advice: FONTAWESOME_NAMESPACE_ADVICE } : undefined;
|
|
294
294
|
}
|
|
295
295
|
if (moduleName === MUI_ICONS_ROOT) {
|
|
296
|
-
|
|
296
|
+
if (isNamedOnly)
|
|
297
|
+
return { advice: MUI_ICONS_ADVICE, reason: MUI_ICONS_NAMED_REASON };
|
|
298
|
+
return clause.namedBindings && ts.isNamespaceImport(clause.namedBindings)
|
|
299
|
+
? { advice: MUI_ICONS_ADVICE }
|
|
300
|
+
: undefined;
|
|
297
301
|
}
|
|
298
302
|
const advice = HEAVY_CLIENT_BARRELS.get(moduleName);
|
|
299
|
-
return advice === undefined
|
|
303
|
+
return advice === undefined
|
|
304
|
+
? undefined
|
|
305
|
+
: { advice, reason: moduleName === 'lodash' && isNamedOnly ? LODASH_NAMED_REASON : undefined };
|
|
300
306
|
}
|
|
301
307
|
function checkHeavyBarrelImport(node, context) {
|
|
302
308
|
const clause = node.importClause;
|
|
303
309
|
if (!clause || clause.isTypeOnly || !ts.isStringLiteralLike(node.moduleSpecifier))
|
|
304
310
|
return;
|
|
311
|
+
if (clause.namedBindings &&
|
|
312
|
+
ts.isNamedImports(clause.namedBindings) &&
|
|
313
|
+
clause.namedBindings.elements.length &&
|
|
314
|
+
!clause.name &&
|
|
315
|
+
clause.namedBindings.elements.every((specifier) => specifier.isTypeOnly))
|
|
316
|
+
return;
|
|
305
317
|
const barrel = heavyBarrelOf(node.moduleSpecifier.text, clause);
|
|
306
318
|
if (!barrel || !isClientModule(node.getSourceFile()))
|
|
307
319
|
return;
|
|
@@ -69,14 +69,6 @@ function walkAll(root, visit) {
|
|
|
69
69
|
ts.forEachChild(node, walk);
|
|
70
70
|
})(root);
|
|
71
71
|
}
|
|
72
|
-
function containsReturnValue(body) {
|
|
73
|
-
let found = false;
|
|
74
|
-
walkSkippingFunctions(body, (node) => {
|
|
75
|
-
if (ts.isReturnStatement(node) && node.expression)
|
|
76
|
-
found = true;
|
|
77
|
-
});
|
|
78
|
-
return found;
|
|
79
|
-
}
|
|
80
72
|
function effectCallback(call, checker) {
|
|
81
73
|
const callback = call.arguments[0] && ts.skipOuterExpressions(call.arguments[0]);
|
|
82
74
|
const isFunction = callback && (ts.isArrowFunction(callback) || ts.isFunctionExpression(callback));
|
|
@@ -90,4 +82,4 @@ function effectCallback(call, checker) {
|
|
|
90
82
|
function isVueImport(expression, checker, exportName) {
|
|
91
83
|
return importedName(expression, checker, VUE_MODULES) === exportName;
|
|
92
84
|
}
|
|
93
|
-
export { ANGULAR_MODULES, REACT_EFFECTS, REACT_MODULES, VUE_MODULES, calleeName,
|
|
85
|
+
export { ANGULAR_MODULES, REACT_EFFECTS, REACT_MODULES, VUE_MODULES, calleeName, declaredInDomLibrary, domSymbolOf, effectCallback, importedName, isBrowserGlobal, isGlobalEventTarget, isVueImport, ownerNameOf, walkAll, walkSkippingFunctions, };
|