loadwise 0.0.0-stage → 0.5.1
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/LICENSE +201 -0
- package/PERFORMANCE.md +110 -0
- package/README.md +1429 -2
- package/bin/github-action.js +58 -0
- package/bin/loadwise.js +98 -0
- package/editor/README.md +47 -0
- package/editor/accessibility-examples.cjs +90 -0
- package/editor/apply-fix.cjs +187 -0
- package/editor/control-flow-comparison.cjs +133 -0
- package/editor/finding-comparison.cjs +77 -0
- package/editor/maintainability-examples.cjs +229 -0
- package/editor/perf-site-comparison.cjs +85 -0
- package/editor/performance-examples.cjs +438 -0
- package/editor/reliability-examples.cjs +77 -0
- package/editor/security-examples.cjs +59 -0
- package/editor/source-example.cjs +66 -0
- package/editor/standalone-performance-examples.cjs +487 -0
- package/examples/indexed.ts +19 -0
- package/examples/labels.py +6 -0
- package/examples/mongo-plan.json +8 -0
- package/examples/postgres-plan.json +10 -0
- package/examples/query-policy.json +24 -0
- package/examples/redis-keys.otlp.json +22 -0
- package/examples/repeated-db.otlp.json +73 -0
- package/examples/slow.ts +10 -0
- package/examples/tsconfig.json +4 -0
- package/lib/accessibility/analyze.js +26 -0
- package/lib/accessibility/angular-inline.js +43 -0
- package/lib/accessibility/aria-tables.js +231 -0
- package/lib/accessibility/cli.js +11 -0
- package/lib/accessibility/frontend-detect.js +98 -0
- package/lib/accessibility/jsx-elements.js +110 -0
- package/lib/accessibility/markup-files.js +41 -0
- package/lib/accessibility/markup.js +24 -0
- package/lib/accessibility/rule-ids.js +36 -0
- package/lib/accessibility/rules.js +293 -0
- package/lib/accessibility/site-fixes/buttons.js +35 -0
- package/lib/accessibility/template-attributes.js +137 -0
- package/lib/accessibility/template-elements.js +434 -0
- package/lib/accessibility/template-file.js +183 -0
- package/lib/accessibility/usage.js +12 -0
- package/lib/maintainability/advisory-context.js +182 -0
- package/lib/maintainability/analyze-source.js +93 -0
- package/lib/maintainability/ancestor-aliases.js +35 -0
- package/lib/maintainability/apply-fix.js +85 -0
- package/lib/maintainability/architecture-nest.js +103 -0
- package/lib/maintainability/architecture.js +482 -0
- package/lib/maintainability/branch-advice.js +135 -0
- package/lib/maintainability/changed-lines.js +135 -0
- package/lib/maintainability/changed-output.js +21 -0
- package/lib/maintainability/checklist-context.js +74 -0
- package/lib/maintainability/child-buffer.js +20 -0
- package/lib/maintainability/cli.js +410 -0
- package/lib/maintainability/config-entry-points.js +86 -0
- package/lib/maintainability/data-access.js +153 -0
- package/lib/maintainability/deprecated-apis.js +170 -0
- package/lib/maintainability/docker-entry-points.js +98 -0
- package/lib/maintainability/duplicates.js +326 -0
- package/lib/maintainability/entry-points.js +603 -0
- package/lib/maintainability/examples.js +122 -0
- package/lib/maintainability/finding-ids.js +46 -0
- package/lib/maintainability/fix-cli.js +235 -0
- package/lib/maintainability/fix-text.js +11 -0
- package/lib/maintainability/functions.js +315 -0
- package/lib/maintainability/graph.js +186 -0
- package/lib/maintainability/html-entry-points.js +75 -0
- package/lib/maintainability/inputs.js +231 -0
- package/lib/maintainability/layout.js +56 -0
- package/lib/maintainability/limits.js +3 -0
- package/lib/maintainability/mocha-entry-points.js +88 -0
- package/lib/maintainability/modifiers.js +6 -0
- package/lib/maintainability/module-usage-dynamic.js +175 -0
- package/lib/maintainability/module-usage.js +574 -0
- package/lib/maintainability/notify-editor.js +1 -0
- package/lib/maintainability/operator-references.js +84 -0
- package/lib/maintainability/polyglot-duplicates.js +121 -0
- package/lib/maintainability/polyglot.js +173 -0
- package/lib/maintainability/project.js +116 -0
- package/lib/maintainability/review-directive.js +91 -0
- package/lib/maintainability/rule-ids.js +67 -0
- package/lib/maintainability/runtime-directories.js +22 -0
- package/lib/maintainability/scan-changed.js +67 -0
- package/lib/maintainability/scan-worker.js +38 -0
- package/lib/maintainability/scan.js +238 -0
- package/lib/maintainability/site-fix.js +221 -0
- package/lib/maintainability/site-fixes/boolean-returns.js +79 -0
- package/lib/maintainability/site-fixes/branches.js +418 -0
- package/lib/maintainability/site-fixes/control-flow.js +67 -0
- package/lib/maintainability/site-fixes/cycles.js +101 -0
- package/lib/maintainability/site-fixes/deprecated-apis.js +67 -0
- package/lib/maintainability/site-fixes/duplicate-arrows.js +343 -0
- package/lib/maintainability/site-fixes/duplicate-bindings.js +149 -0
- package/lib/maintainability/site-fixes/duplicate-edits.js +396 -0
- package/lib/maintainability/site-fixes/duplicate-methods.js +407 -0
- package/lib/maintainability/site-fixes/duplicates.js +125 -0
- package/lib/maintainability/site-fixes/exports.js +25 -0
- package/lib/maintainability/site-fixes/extract-block-ast.js +130 -0
- package/lib/maintainability/site-fixes/extract-block-edits.js +156 -0
- package/lib/maintainability/site-fixes/extract-block-flow.js +265 -0
- package/lib/maintainability/site-fixes/extract-block-measure.js +131 -0
- package/lib/maintainability/site-fixes/extract-block-naming.js +164 -0
- package/lib/maintainability/site-fixes/extract-block-narrowing.js +141 -0
- package/lib/maintainability/site-fixes/extract-block.js +38 -0
- package/lib/maintainability/site-fixes/helpers.js +308 -0
- package/lib/maintainability/site-fixes/if-rewrites.js +468 -0
- package/lib/maintainability/site-fixes/isolated-program.js +85 -0
- package/lib/maintainability/site-fixes/large-module.js +175 -0
- package/lib/maintainability/site-fixes/parameters.js +460 -0
- package/lib/maintainability/site-fixes/stray-console.js +21 -0
- package/lib/maintainability/site-fixes/unused-bindings.js +158 -0
- package/lib/maintainability/size-limits.js +94 -0
- package/lib/maintainability/snapshot-context.js +63 -0
- package/lib/maintainability/source-exclusions.js +68 -0
- package/lib/maintainability/source-facts.js +39 -0
- package/lib/maintainability/stray-console.js +352 -0
- package/lib/maintainability/traversal-context.js +76 -0
- package/lib/maintainability/types/changed-lines.js +1 -0
- package/lib/maintainability/types/created-module.js +1 -0
- package/lib/maintainability/types/duplicate-sites.js +1 -0
- package/lib/maintainability/types/duplicates.js +1 -0
- package/lib/maintainability/types/entry-points.js +1 -0
- package/lib/maintainability/types/extract-block.js +1 -0
- package/lib/maintainability/types/extraction-drafts.js +1 -0
- package/lib/maintainability/types/finding-comparison.js +1 -0
- package/lib/maintainability/types/fix-files.js +1 -0
- package/lib/maintainability/types/module-graph.js +1 -0
- package/lib/maintainability/types/module-resolver.js +1 -0
- package/lib/maintainability/types/module-usage.js +1 -0
- package/lib/maintainability/types/policy.js +1 -0
- package/lib/maintainability/types/polyglot-scan.js +1 -0
- package/lib/maintainability/types/scan-report.js +1 -0
- package/lib/maintainability/types/scan-worker.js +1 -0
- package/lib/maintainability/types/site-fix-edits.js +1 -0
- package/lib/maintainability/types/site-fix-loader.js +1 -0
- package/lib/maintainability/types/site-fix-nodes.js +1 -0
- package/lib/maintainability/types/source-analysis.js +1 -0
- package/lib/maintainability/types/source-facts.js +1 -0
- package/lib/maintainability/types/typescript-jsdoc-internals.js +1 -0
- package/lib/maintainability/types/typescript-site-fix-internals.js +1 -0
- package/lib/maintainability/unused-bindings.js +182 -0
- package/lib/maintainability/unused-modules.js +258 -0
- package/lib/maintainability/verified-private-types.js +142 -0
- package/lib/maintainability/walk.js +17 -0
- package/lib/maintainability/workflow-entry-points.js +83 -0
- package/lib/performance/analyze.js +251 -0
- package/lib/performance/async-errors.js +190 -0
- package/lib/performance/await-before-early-exit.js +176 -0
- package/lib/performance/awaits.js +70 -0
- package/lib/performance/backend-mastery.js +444 -0
- package/lib/performance/cache-reads.js +170 -0
- package/lib/performance/call-syntax.js +27 -0
- package/lib/performance/cartesian-includes.js +364 -0
- package/lib/performance/changed-lines.js +141 -0
- package/lib/performance/cli-arguments.js +61 -0
- package/lib/performance/cli-output.js +175 -0
- package/lib/performance/cli-policy.js +79 -0
- package/lib/performance/cli-scan.js +419 -0
- package/lib/performance/cli-types.js +1 -0
- package/lib/performance/cli.js +120 -0
- package/lib/performance/collection-bindings.js +283 -0
- package/lib/performance/collection-bounds.js +247 -0
- package/lib/performance/collection-copy.js +169 -0
- package/lib/performance/collection-lookups.js +432 -0
- package/lib/performance/collection-reduce.js +340 -0
- package/lib/performance/collections.js +25 -0
- package/lib/performance/compiler.js +52 -0
- package/lib/performance/contracts/cli.js +230 -0
- package/lib/performance/contracts/dto.js +244 -0
- package/lib/performance/contracts/git-files.js +37 -0
- package/lib/performance/contracts/graphql.js +360 -0
- package/lib/performance/contracts/openapi.js +363 -0
- package/lib/performance/db/checks.js +398 -0
- package/lib/performance/db/cli-format.js +9 -0
- package/lib/performance/db/cli-mysql.js +82 -0
- package/lib/performance/db/cli.js +469 -0
- package/lib/performance/db/drivers.js +241 -0
- package/lib/performance/db/gateway.js +194 -0
- package/lib/performance/db/hypopg.js +52 -0
- package/lib/performance/db/measure.js +141 -0
- package/lib/performance/db/mongo.js +272 -0
- package/lib/performance/db/mysql-catalog.js +64 -0
- package/lib/performance/db/pg-catalog.js +114 -0
- package/lib/performance/db/plan-estimates.js +188 -0
- package/lib/performance/db/redact.js +126 -0
- package/lib/performance/db/snapshot.js +82 -0
- package/lib/performance/dependent-writes.js +228 -0
- package/lib/performance/discarded-error-result.js +46 -0
- package/lib/performance/drizzle-write-preflight.js +195 -0
- package/lib/performance/drizzle.js +288 -0
- package/lib/performance/editor-report.js +191 -0
- package/lib/performance/editor-setup.js +189 -0
- package/lib/performance/editor-signal.js +57 -0
- package/lib/performance/editor-watch-supervisor.js +104 -0
- package/lib/performance/editor-watch.js +193 -0
- package/lib/performance/emit-options.js +29 -0
- package/lib/performance/filter-existence.js +149 -0
- package/lib/performance/find-then-create.js +281 -0
- package/lib/performance/finding-ids.js +48 -0
- package/lib/performance/finding-text.js +117 -0
- package/lib/performance/fix-cli.js +200 -0
- package/lib/performance/floating-promises.js +248 -0
- package/lib/performance/frontend-dom-perf.js +310 -0
- package/lib/performance/frontend-helpers.js +93 -0
- package/lib/performance/frontend-perf.js +472 -0
- package/lib/performance/function-kinds.js +9 -0
- package/lib/performance/guard-queries.js +356 -0
- package/lib/performance/http-timeouts.js +492 -0
- package/lib/performance/impact.js +53 -0
- package/lib/performance/index-rules-foreign-keys.js +81 -0
- package/lib/performance/index-rules-order.js +152 -0
- package/lib/performance/index-rules-pattern.js +137 -0
- package/lib/performance/index-rules-table.js +288 -0
- package/lib/performance/index-rules.js +107 -0
- package/lib/performance/json-clone.js +28 -0
- package/lib/performance/json-parse-context.js +99 -0
- package/lib/performance/last-insert-id.js +120 -0
- package/lib/performance/list-counts.js +321 -0
- package/lib/performance/list-overfetch.js +216 -0
- package/lib/performance/literal-awaits.js +190 -0
- package/lib/performance/memory-growth.js +516 -0
- package/lib/performance/migrations/cli.js +203 -0
- package/lib/performance/migrations/discover.js +354 -0
- package/lib/performance/migrations/enforce.js +177 -0
- package/lib/performance/migrations/extract-code-builders.js +291 -0
- package/lib/performance/migrations/extract-code-discovery.js +179 -0
- package/lib/performance/migrations/extract-code-sql.js +196 -0
- package/lib/performance/migrations/extract-code-types.js +1 -0
- package/lib/performance/migrations/extract-code.js +123 -0
- package/lib/performance/migrations/extract-sql.js +452 -0
- package/lib/performance/migrations/operations.js +156 -0
- package/lib/performance/migrations/postgres-registry.js +135 -0
- package/lib/performance/migrations/rules-mysql.js +105 -0
- package/lib/performance/migrations/rules-postgres-add-column.js +145 -0
- package/lib/performance/migrations/rules-postgres-shared.js +22 -0
- package/lib/performance/migrations/rules-postgres.js +464 -0
- package/lib/performance/missing-packages.js +116 -0
- package/lib/performance/models/index.js +284 -0
- package/lib/performance/mongoose-patterns.js +245 -0
- package/lib/performance/native-checker.js +312 -0
- package/lib/performance/native-runtime.js +24 -0
- package/lib/performance/native-syntax.js +132 -0
- package/lib/performance/native-workspaces.js +31 -0
- package/lib/performance/native.js +342 -0
- package/lib/performance/node-fs-context.js +390 -0
- package/lib/performance/node-fs.js +452 -0
- package/lib/performance/notification-loops.js +176 -0
- package/lib/performance/notify-editor.js +1 -0
- package/lib/performance/offset-pagination.js +166 -0
- package/lib/performance/orm-owners.js +145 -0
- package/lib/performance/orm-queries.js +496 -0
- package/lib/performance/package-types.js +57 -0
- package/lib/performance/page-counts.js +262 -0
- package/lib/performance/parallel-reads-policy.js +41 -0
- package/lib/performance/parallel-reads.js +139 -0
- package/lib/performance/password-hashing.js +218 -0
- package/lib/performance/pg-fragments.js +300 -0
- package/lib/performance/pg-integrity.js +115 -0
- package/lib/performance/phase5-rules.js +539 -0
- package/lib/performance/plans.js +283 -0
- package/lib/performance/polyglot.js +193 -0
- package/lib/performance/pooling.js +200 -0
- package/lib/performance/postgres.js +182 -0
- package/lib/performance/prisma-aggregates.js +125 -0
- package/lib/performance/prisma-integrity.js +239 -0
- package/lib/performance/prisma.js +399 -0
- package/lib/performance/projects.js +431 -0
- package/lib/performance/promise-return-escapes-catch.js +96 -0
- package/lib/performance/pure-js-hashing.js +96 -0
- package/lib/performance/query-loop-batch.js +188 -0
- package/lib/performance/query-loop-bounds.js +219 -0
- package/lib/performance/query-loop-exits.js +171 -0
- package/lib/performance/query-loop-helpers.js +42 -0
- package/lib/performance/query-loop-memo.js +81 -0
- package/lib/performance/query-loop-pagination.js +130 -0
- package/lib/performance/query-loops.js +29 -0
- package/lib/performance/query-policy.js +94 -0
- package/lib/performance/query-results.js +179 -0
- package/lib/performance/queue-loops.js +87 -0
- package/lib/performance/recursive-watch.js +181 -0
- package/lib/performance/redis-client.js +19 -0
- package/lib/performance/redis-keys.js +78 -0
- package/lib/performance/redis.js +188 -0
- package/lib/performance/redundant-indexes.js +403 -0
- package/lib/performance/reference-checks.js +22 -0
- package/lib/performance/repeated.js +200 -0
- package/lib/performance/request-handlers.js +429 -0
- package/lib/performance/request-heavy-work.js +135 -0
- package/lib/performance/request-inputs.js +303 -0
- package/lib/performance/retry-backoff.js +132 -0
- package/lib/performance/return-in-finally.js +12 -0
- package/lib/performance/return-newline.js +54 -0
- package/lib/performance/review-context.js +434 -0
- package/lib/performance/rule-ids.js +357 -0
- package/lib/performance/scan-outcome.js +37 -0
- package/lib/performance/schema/context.js +145 -0
- package/lib/performance/schema/drizzle-schema.js +278 -0
- package/lib/performance/schema/model.js +169 -0
- package/lib/performance/schema/mongoose-schema.js +189 -0
- package/lib/performance/schema/prisma-schema.js +472 -0
- package/lib/performance/schema/project-indexes-events.js +494 -0
- package/lib/performance/schema/project-indexes.js +240 -0
- package/lib/performance/schema/query-site-support.js +61 -0
- package/lib/performance/schema/query-sites-drizzle.js +220 -0
- package/lib/performance/schema/query-sites-mongoose.js +140 -0
- package/lib/performance/schema/query-sites-prisma.js +201 -0
- package/lib/performance/schema/query-sites-sequelize.js +133 -0
- package/lib/performance/schema/query-sites-typeorm.js +180 -0
- package/lib/performance/schema/query-sites.js +19 -0
- package/lib/performance/schema/raw-sql-sites.js +284 -0
- package/lib/performance/schema/sequelize-schema.js +322 -0
- package/lib/performance/schema/ts-helpers.js +130 -0
- package/lib/performance/schema/typeorm-schema.js +262 -0
- package/lib/performance/schema-tooling.js +193 -0
- package/lib/performance/scope-evidence.js +137 -0
- package/lib/performance/sequential-loops.js +557 -0
- package/lib/performance/service-call-resolution.js +54 -0
- package/lib/performance/service-loop-collections.js +263 -0
- package/lib/performance/service-loop-operations.js +235 -0
- package/lib/performance/service-loops.js +416 -0
- package/lib/performance/session-store.js +86 -0
- package/lib/performance/site-fix.js +271 -0
- package/lib/performance/site-fixes/await-before-early-exit.js +121 -0
- package/lib/performance/site-fixes/backend-mastery-fixes.js +90 -0
- package/lib/performance/site-fixes/batch-loops.js +449 -0
- package/lib/performance/site-fixes/collection-copy.js +310 -0
- package/lib/performance/site-fixes/collection-existence.js +200 -0
- package/lib/performance/site-fixes/collection-find.js +195 -0
- package/lib/performance/site-fixes/collection-helpers.js +349 -0
- package/lib/performance/site-fixes/collection-lookup-declarations.js +47 -0
- package/lib/performance/site-fixes/collection-lookups.js +101 -0
- package/lib/performance/site-fixes/collection-membership.js +124 -0
- package/lib/performance/site-fixes/collections.js +18 -0
- package/lib/performance/site-fixes/database.js +455 -0
- package/lib/performance/site-fixes/delete-preflight.js +99 -0
- package/lib/performance/site-fixes/drizzle-index.js +239 -0
- package/lib/performance/site-fixes/error-handling.js +99 -0
- package/lib/performance/site-fixes/frontend-fixes.js +193 -0
- package/lib/performance/site-fixes/guard-queries.js +172 -0
- package/lib/performance/site-fixes/helpers.js +200 -0
- package/lib/performance/site-fixes/hoisting.js +155 -0
- package/lib/performance/site-fixes/http-timeouts.js +56 -0
- package/lib/performance/site-fixes/indexes.js +454 -0
- package/lib/performance/site-fixes/integrity-drizzle.js +188 -0
- package/lib/performance/site-fixes/integrity-wrap.js +45 -0
- package/lib/performance/site-fixes/integrity.js +555 -0
- package/lib/performance/site-fixes/json-parse.js +114 -0
- package/lib/performance/site-fixes/last-insert-id.js +230 -0
- package/lib/performance/site-fixes/list-queries.js +164 -0
- package/lib/performance/site-fixes/literal-awaits.js +431 -0
- package/lib/performance/site-fixes/method-calls.js +6 -0
- package/lib/performance/site-fixes/migration-column-rules.js +208 -0
- package/lib/performance/site-fixes/migration-context.js +317 -0
- package/lib/performance/site-fixes/migration-lock-rules.js +204 -0
- package/lib/performance/site-fixes/migration-placement.js +252 -0
- package/lib/performance/site-fixes/migrations.js +34 -0
- package/lib/performance/site-fixes/page-counts.js +88 -0
- package/lib/performance/site-fixes/prisma-aggregates.js +455 -0
- package/lib/performance/site-fixes/promise-catch.js +147 -0
- package/lib/performance/site-fixes/pure-js-hashing.js +68 -0
- package/lib/performance/site-fixes/query-loop-collections.js +202 -0
- package/lib/performance/site-fixes/query-loop-lookups.js +98 -0
- package/lib/performance/site-fixes/query-loop-materialization.js +279 -0
- package/lib/performance/site-fixes/query-loop-names.js +35 -0
- package/lib/performance/site-fixes/query-loop-nodes.js +162 -0
- package/lib/performance/site-fixes/query-loop-pg-redis.js +203 -0
- package/lib/performance/site-fixes/query-loop-prisma.js +304 -0
- package/lib/performance/site-fixes/query-loop-sites.js +317 -0
- package/lib/performance/site-fixes/query-loop-typeorm.js +294 -0
- package/lib/performance/site-fixes/query-loops.js +57 -0
- package/lib/performance/site-fixes/query-shapes.js +573 -0
- package/lib/performance/site-fixes/queue-loops.js +231 -0
- package/lib/performance/site-fixes/redis-keys.js +213 -0
- package/lib/performance/site-fixes/scope-names.js +30 -0
- package/lib/performance/site-fixes/service-loop-ast.js +85 -0
- package/lib/performance/site-fixes/service-loop-callee.js +57 -0
- package/lib/performance/site-fixes/service-loop-concurrent.js +88 -0
- package/lib/performance/site-fixes/service-loop-imports.js +68 -0
- package/lib/performance/site-fixes/service-loop-read-batch.js +255 -0
- package/lib/performance/site-fixes/service-loop-siblings.js +170 -0
- package/lib/performance/site-fixes/service-loop-signature.js +33 -0
- package/lib/performance/site-fixes/service-loop-sites.js +141 -0
- package/lib/performance/site-fixes/service-loop-write-batch.js +94 -0
- package/lib/performance/site-fixes/service-loops.js +153 -0
- package/lib/performance/site-fixes/small-rewrites.js +210 -0
- package/lib/performance/site-fixes/streams.js +150 -0
- package/lib/performance/site-fixes/sync-calls.js +485 -0
- package/lib/performance/site-fixes/sync-imports.js +170 -0
- package/lib/performance/site-fixes/transaction-escape.js +40 -0
- package/lib/performance/site-fixes/transaction-io.js +280 -0
- package/lib/performance/site-fixes/typeorm-updates.js +277 -0
- package/lib/performance/site-fixes/typeorm.js +239 -0
- package/lib/performance/site-fixes/types/module-binding.js +1 -0
- package/lib/performance/site-fixes/upload-limits.js +74 -0
- package/lib/performance/site-fixes/workbook-decodes.js +254 -0
- package/lib/performance/site-fixes/writes.js +342 -0
- package/lib/performance/sort-extreme.js +142 -0
- package/lib/performance/source-inputs.js +71 -0
- package/lib/performance/source-options.js +103 -0
- package/lib/performance/source-pillars.js +23 -0
- package/lib/performance/source-text.js +59 -0
- package/lib/performance/span-timing.js +54 -0
- package/lib/performance/sql/locations.js +91 -0
- package/lib/performance/sql/mysql-tokens.js +393 -0
- package/lib/performance/sql/pg-parser.js +330 -0
- package/lib/performance/stream-errors.js +650 -0
- package/lib/performance/traces.js +363 -0
- package/lib/performance/transaction-io.js +427 -0
- package/lib/performance/typeorm-projection.js +261 -0
- package/lib/performance/typeorm-transaction-loops.js +143 -0
- package/lib/performance/typeorm-unused-count.js +36 -0
- package/lib/performance/typeorm-updates.js +268 -0
- package/lib/performance/types/ast-grep-match.js +2 -0
- package/lib/performance/types/batch-plan.js +1 -0
- package/lib/performance/types/batched-fix-input.js +1 -0
- package/lib/performance/types/call-site.js +1 -0
- package/lib/performance/types/callee-helper.js +1 -0
- package/lib/performance/types/client-family.js +1 -0
- package/lib/performance/types/collections.js +1 -0
- package/lib/performance/types/contract-findings.js +3 -0
- package/lib/performance/types/db-cli.js +1 -0
- package/lib/performance/types/db-connection.js +1 -0
- package/lib/performance/types/db-model.js +3 -0
- package/lib/performance/types/db-plan-findings.js +1 -0
- package/lib/performance/types/db-plan.js +2 -0
- package/lib/performance/types/db-snapshot.js +1 -0
- package/lib/performance/types/declaration-link.js +2 -0
- package/lib/performance/types/decorator-call.js +1 -0
- package/lib/performance/types/drizzle-query.js +1 -0
- package/lib/performance/types/editor-report.js +1 -0
- package/lib/performance/types/find-lookup-facts.js +3 -0
- package/lib/performance/types/helper-function.js +1 -0
- package/lib/performance/types/hoist-anchor.js +1 -0
- package/lib/performance/types/http-call.js +1 -0
- package/lib/performance/types/lookup-construction.js +1 -0
- package/lib/performance/types/lookup-placement.js +1 -0
- package/lib/performance/types/loop-key-site.js +1 -0
- package/lib/performance/types/loop-lookup.js +1 -0
- package/lib/performance/types/method-call.js +1 -0
- package/lib/performance/types/migration-extraction.js +1 -0
- package/lib/performance/types/migration-files.js +1 -0
- package/lib/performance/types/migration-operations.js +1 -0
- package/lib/performance/types/migrations.js +1 -0
- package/lib/performance/types/model-fallback.js +2 -0
- package/lib/performance/types/mysql-statements.js +2 -0
- package/lib/performance/types/native-modules.js +1 -0
- package/lib/performance/types/native-typescript.js +1 -0
- package/lib/performance/types/otlp-attributes.js +1 -0
- package/lib/performance/types/otlp-trace.js +1 -0
- package/lib/performance/types/page-count-pair.js +1 -0
- package/lib/performance/types/parallel-reads.js +1 -0
- package/lib/performance/types/performance-policy.js +1 -0
- package/lib/performance/types/pg-statements.js +1 -0
- package/lib/performance/types/plain-property.js +1 -0
- package/lib/performance/types/postgres-registry.js +1 -0
- package/lib/performance/types/prisma-schema.js +1 -0
- package/lib/performance/types/program-scan.js +1 -0
- package/lib/performance/types/project-indexes.js +1 -0
- package/lib/performance/types/query-loops.js +1 -0
- package/lib/performance/types/query-site.js +1 -0
- package/lib/performance/types/related-location.js +2 -0
- package/lib/performance/types/repeat-owner.js +1 -0
- package/lib/performance/types/request-handler.js +1 -0
- package/lib/performance/types/request-input.js +1 -0
- package/lib/performance/types/schema-model.js +3 -0
- package/lib/performance/types/sibling-declaration.js +1 -0
- package/lib/performance/types/source-analyzer.js +1 -0
- package/lib/performance/types/source-check-values.js +1 -0
- package/lib/performance/types/source-command.js +1 -0
- package/lib/performance/types/source-position.js +2 -0
- package/lib/performance/types/source-scan-values.js +1 -0
- package/lib/performance/types/statement-range.js +2 -0
- package/lib/performance/types/typeorm-save-shape.js +1 -0
- package/lib/performance/types/typescript-binder.js +1 -0
- package/lib/performance/types/typescript-token-lookup.js +1 -0
- package/lib/performance/types/typescript-token-position.js +1 -0
- package/lib/performance/unbounded-list-queries.js +600 -0
- package/lib/performance/unscanned-javascript.js +29 -0
- package/lib/performance/upload-limits.js +68 -0
- package/lib/performance/vendor/README.md +7 -0
- package/lib/performance/vendor/typescript/LICENSE +55 -0
- package/lib/performance/vendor/typescript/NOTICE.txt +405 -0
- package/lib/performance/vendor/typescript/dist/api/compilerOptions.generated.js +8 -0
- package/lib/performance/vendor/typescript/dist/api/diagnosticFormatter.js +169 -0
- package/lib/performance/vendor/typescript/dist/api/fs.js +70 -0
- package/lib/performance/vendor/typescript/dist/api/fsCallbacks.js +111 -0
- package/lib/performance/vendor/typescript/dist/api/node/encoder.generated.js +74 -0
- package/lib/performance/vendor/typescript/dist/api/node/encoder.js +292 -0
- package/lib/performance/vendor/typescript/dist/api/node/msgpack.js +212 -0
- package/lib/performance/vendor/typescript/dist/api/node/node.generated.js +884 -0
- package/lib/performance/vendor/typescript/dist/api/node/node.infrastructure.js +102 -0
- package/lib/performance/vendor/typescript/dist/api/node/node.js +453 -0
- package/lib/performance/vendor/typescript/dist/api/node/protocol.generated.js +241 -0
- package/lib/performance/vendor/typescript/dist/api/node/protocol.js +33 -0
- package/lib/performance/vendor/typescript/dist/api/node/wtf8.js +130 -0
- package/lib/performance/vendor/typescript/dist/api/options.js +32 -0
- package/lib/performance/vendor/typescript/dist/api/path.js +884 -0
- package/lib/performance/vendor/typescript/dist/api/prepareCompilerOptions.generated.js +24 -0
- package/lib/performance/vendor/typescript/dist/api/proto.generated.js +21 -0
- package/lib/performance/vendor/typescript/dist/api/proto.js +50 -0
- package/lib/performance/vendor/typescript/dist/api/sourceFileCache.js +300 -0
- package/lib/performance/vendor/typescript/dist/api/sync/api.js +5408 -0
- package/lib/performance/vendor/typescript/dist/api/sync/client.js +174 -0
- package/lib/performance/vendor/typescript/dist/api/sync/generatorSupport.js +338 -0
- package/lib/performance/vendor/typescript/dist/api/syncChannel.js +526 -0
- package/lib/performance/vendor/typescript/dist/api/timing.js +149 -0
- package/lib/performance/vendor/typescript/dist/api/timingDump.js +38 -0
- package/lib/performance/vendor/typescript/dist/api/userPreferences.generated.js +3 -0
- package/lib/performance/vendor/typescript/dist/ast/ast.generated.js +4 -0
- package/lib/performance/vendor/typescript/dist/ast/ast.js +8 -0
- package/lib/performance/vendor/typescript/dist/ast/astnav.js +741 -0
- package/lib/performance/vendor/typescript/dist/ast/clone.js +104 -0
- package/lib/performance/vendor/typescript/dist/ast/factory.generated.js +5751 -0
- package/lib/performance/vendor/typescript/dist/ast/index.js +25 -0
- package/lib/performance/vendor/typescript/dist/ast/is.generated.js +1400 -0
- package/lib/performance/vendor/typescript/dist/ast/is.js +456 -0
- package/lib/performance/vendor/typescript/dist/ast/jsdoc.js +208 -0
- package/lib/performance/vendor/typescript/dist/ast/modifiers.js +41 -0
- package/lib/performance/vendor/typescript/dist/ast/scanner.js +2231 -0
- package/lib/performance/vendor/typescript/dist/ast/spanMap.js +417 -0
- package/lib/performance/vendor/typescript/dist/ast/utils.js +318 -0
- package/lib/performance/vendor/typescript/dist/ast/visitor.generated.js +979 -0
- package/lib/performance/vendor/typescript/dist/ast/visitor.js +87 -0
- package/lib/performance/vendor/typescript/dist/enums/caseSensitivity.js +7 -0
- package/lib/performance/vendor/typescript/dist/enums/characterCodes.js +130 -0
- package/lib/performance/vendor/typescript/dist/enums/checkFlags.js +36 -0
- package/lib/performance/vendor/typescript/dist/enums/commentDirectiveType.js +6 -0
- package/lib/performance/vendor/typescript/dist/enums/completionItemKind.js +30 -0
- package/lib/performance/vendor/typescript/dist/enums/diagnosticCategory.js +9 -0
- package/lib/performance/vendor/typescript/dist/enums/diagnosticDirectivePolicy.js +7 -0
- package/lib/performance/vendor/typescript/dist/enums/elementFlags.js +14 -0
- package/lib/performance/vendor/typescript/dist/enums/emitOnly.js +8 -0
- package/lib/performance/vendor/typescript/dist/enums/indexKind.js +7 -0
- package/lib/performance/vendor/typescript/dist/enums/internalSymbolName.js +25 -0
- package/lib/performance/vendor/typescript/dist/enums/jsDeclarationKind.js +12 -0
- package/lib/performance/vendor/typescript/dist/enums/jsxEmit.js +11 -0
- package/lib/performance/vendor/typescript/dist/enums/languageVariant.js +6 -0
- package/lib/performance/vendor/typescript/dist/enums/modifierFlags.js +44 -0
- package/lib/performance/vendor/typescript/dist/enums/moduleDetectionKind.js +9 -0
- package/lib/performance/vendor/typescript/dist/enums/moduleKind.js +19 -0
- package/lib/performance/vendor/typescript/dist/enums/moduleResolutionKind.js +11 -0
- package/lib/performance/vendor/typescript/dist/enums/newLineKind.js +8 -0
- package/lib/performance/vendor/typescript/dist/enums/nodeBuilderFlags.js +38 -0
- package/lib/performance/vendor/typescript/dist/enums/nodeFlags.js +46 -0
- package/lib/performance/vendor/typescript/dist/enums/objectFlags.js +53 -0
- package/lib/performance/vendor/typescript/dist/enums/outerExpressionKinds.js +18 -0
- package/lib/performance/vendor/typescript/dist/enums/regularExpressionFlags.js +14 -0
- package/lib/performance/vendor/typescript/dist/enums/scriptKind.js +11 -0
- package/lib/performance/vendor/typescript/dist/enums/scriptTarget.js +20 -0
- package/lib/performance/vendor/typescript/dist/enums/signatureFlags.js +17 -0
- package/lib/performance/vendor/typescript/dist/enums/signatureKind.js +7 -0
- package/lib/performance/vendor/typescript/dist/enums/spanMapFeature.js +27 -0
- package/lib/performance/vendor/typescript/dist/enums/spanMapFidelity.js +9 -0
- package/lib/performance/vendor/typescript/dist/enums/spanMapKind.js +8 -0
- package/lib/performance/vendor/typescript/dist/enums/symbolFlags.js +72 -0
- package/lib/performance/vendor/typescript/dist/enums/symbolOwnerKind.js +7 -0
- package/lib/performance/vendor/typescript/dist/enums/syntaxKind.js +392 -0
- package/lib/performance/vendor/typescript/dist/enums/tokenFlags.js +32 -0
- package/lib/performance/vendor/typescript/dist/enums/typeFlags.js +78 -0
- package/lib/performance/vendor/typescript/dist/enums/typeFormatFlags.js +31 -0
- package/lib/performance/vendor/typescript/dist/enums/typePredicateKind.js +9 -0
- package/lib/performance/vendor/typescript/dist/internal/utils.js +25 -0
- package/lib/performance/vendor/typescript/lib/getExePath.js +70 -0
- package/lib/performance/vendor/typescript/package.json +93 -0
- package/lib/performance/vendor/typescript/vendor/vscode-jsonrpc/License.txt +11 -0
- package/lib/performance/watch.js +99 -0
- package/lib/performance/workbook-decodes.js +147 -0
- package/lib/reliability/analyze.js +29 -0
- package/lib/reliability/boundary-access.js +521 -0
- package/lib/reliability/cli.js +20 -0
- package/lib/reliability/resource-leaks.js +526 -0
- package/lib/reliability/rule-ids.js +225 -0
- package/lib/reliability/site-fixes/boundary-access.js +80 -0
- package/lib/reliability/site-fixes/resource-leaks.js +125 -0
- package/lib/reliability/site-fixes/suspicious-logic.js +115 -0
- package/lib/reliability/source-helpers.js +32 -0
- package/lib/reliability/sql-insert-terminator.js +106 -0
- package/lib/reliability/standalone-sources.js +54 -0
- package/lib/reliability/suspicious-logic.js +364 -0
- package/lib/reliability/swallowed-errors.js +321 -0
- package/lib/reliability/usage.js +16 -0
- package/lib/reliability/walk.js +16 -0
- package/lib/security/analyze.js +129 -0
- package/lib/security/auth-crypto/comparison.js +97 -0
- package/lib/security/auth-crypto/hashing.js +302 -0
- package/lib/security/auth-crypto/index.js +32 -0
- package/lib/security/auth-crypto/jwt.js +468 -0
- package/lib/security/auth-crypto/plaintext-password.js +171 -0
- package/lib/security/auth-crypto/random.js +124 -0
- package/lib/security/auth-crypto/rate-limits.js +326 -0
- package/lib/security/auth-crypto/rule-ids.js +17 -0
- package/lib/security/auth-crypto/secrets.js +331 -0
- package/lib/security/auth-crypto/shared.js +105 -0
- package/lib/security/auth-crypto/transport-and-ciphers.js +217 -0
- package/lib/security/bindings.js +286 -0
- package/lib/security/cli.js +293 -0
- package/lib/security/declarations.js +25 -0
- package/lib/security/deps/advisory.js +142 -0
- package/lib/security/deps/cli.js +75 -0
- package/lib/security/deps/lockfiles.js +310 -0
- package/lib/security/deps/osv.js +217 -0
- package/lib/security/deps/rule-ids.js +6 -0
- package/lib/security/deps/scan.js +69 -0
- package/lib/security/examples/auth-crypto.cjs +57 -0
- package/lib/security/examples/deps.cjs +9 -0
- package/lib/security/examples/exposure.cjs +98 -0
- package/lib/security/examples/files.cjs +29 -0
- package/lib/security/examples/injection.cjs +53 -0
- package/lib/security/examples/moved.cjs +17 -0
- package/lib/security/examples/request-forgery.cjs +25 -0
- package/lib/security/exposure/backend-security-mastery.js +80 -0
- package/lib/security/exposure/cookies.js +173 -0
- package/lib/security/exposure/cors-origin-regex.js +177 -0
- package/lib/security/exposure/cors.js +217 -0
- package/lib/security/exposure/error-responses.js +437 -0
- package/lib/security/exposure/frontend-security.js +547 -0
- package/lib/security/exposure/graphql.js +131 -0
- package/lib/security/exposure/index.js +52 -0
- package/lib/security/exposure/literals.js +133 -0
- package/lib/security/exposure/logging.js +168 -0
- package/lib/security/exposure/mass-assignment.js +165 -0
- package/lib/security/exposure/password-response.js +315 -0
- package/lib/security/exposure/prototype-pollution.js +291 -0
- package/lib/security/exposure/reflected-xss.js +57 -0
- package/lib/security/exposure/report.js +10 -0
- package/lib/security/exposure/rule-ids.js +28 -0
- package/lib/security/exposure/storage-acl.js +87 -0
- package/lib/security/exposure/template-autoescape.js +39 -0
- package/lib/security/exposure/url-secrets.js +164 -0
- package/lib/security/exposure/validation-pipe.js +36 -0
- package/lib/security/exposure/xml.js +28 -0
- package/lib/security/file-context.js +82 -0
- package/lib/security/files/compose.js +79 -0
- package/lib/security/files/dockerfile.js +206 -0
- package/lib/security/files/index.js +100 -0
- package/lib/security/files/project-files.js +103 -0
- package/lib/security/files/review-directive.js +30 -0
- package/lib/security/files/rule-ids.js +10 -0
- package/lib/security/files/secret-values.js +98 -0
- package/lib/security/files/secrets.js +121 -0
- package/lib/security/injection/code.js +108 -0
- package/lib/security/injection/command.js +127 -0
- package/lib/security/injection/index.js +13 -0
- package/lib/security/injection/nosql.js +266 -0
- package/lib/security/injection/redos.js +609 -0
- package/lib/security/injection/regex.js +48 -0
- package/lib/security/injection/rule-ids.js +16 -0
- package/lib/security/injection/shared.js +119 -0
- package/lib/security/injection/sql.js +432 -0
- package/lib/security/pg-dynamic-query.js +30 -0
- package/lib/security/pg-identifier-guards.js +155 -0
- package/lib/security/phase5-rules.js +515 -0
- package/lib/security/polyglot.js +8 -0
- package/lib/security/request-forgery/index.js +11 -0
- package/lib/security/request-forgery/open-redirect.js +336 -0
- package/lib/security/request-forgery/path-traversal.js +103 -0
- package/lib/security/request-forgery/rule-ids.js +9 -0
- package/lib/security/request-forgery/shared.js +355 -0
- package/lib/security/request-forgery/ssrf.js +133 -0
- package/lib/security/request-forgery/upload-filename.js +75 -0
- package/lib/security/request-forgery/zip-slip.js +42 -0
- package/lib/security/rule-descriptions.js +84 -0
- package/lib/security/rule-ids.js +142 -0
- package/lib/security/scope/drizzle-policy.js +197 -0
- package/lib/security/scope/query-policy.js +156 -0
- package/lib/security/site-fixes/auth-crypto.js +223 -0
- package/lib/security/site-fixes/backend-security-fixes.js +86 -0
- package/lib/security/site-fixes/error-responses.js +84 -0
- package/lib/security/site-fixes/exposure.js +120 -0
- package/lib/security/site-fixes/files.js +45 -0
- package/lib/security/site-fixes/frontend-security-fixes.js +73 -0
- package/lib/security/site-fixes/injection.js +119 -0
- package/lib/security/site-fixes/jwt.js +89 -0
- package/lib/security/site-fixes/list-edits.js +16 -0
- package/lib/security/site-fixes/request-forgery.js +117 -0
- package/lib/security/site-fixes/secret-comparison.js +107 -0
- package/lib/security/site-fixes/template-autoescape.js +25 -0
- package/lib/security/taint/archive-sources.js +127 -0
- package/lib/security/taint/filename-guard.js +110 -0
- package/lib/security/taint/guards.js +274 -0
- package/lib/security/taint/index.js +559 -0
- package/lib/security/taint/propagate.js +117 -0
- package/lib/security/taint/sanitizers.js +67 -0
- package/lib/security/taint/sources.js +357 -0
- package/lib/security/taint/summaries.js +207 -0
- package/lib/security/taint/url-parts.js +264 -0
- package/lib/security/taint/validators.js +420 -0
- package/lib/security/types/condition-guards.js +1 -0
- package/lib/security/types/file-finding.js +1 -0
- package/lib/security/types/inspectable-type.js +1 -0
- package/lib/security/types/lockfile.js +1 -0
- package/lib/security/types/osv-vulnerability.js +1 -0
- package/lib/security/types/project-files.js +1 -0
- package/lib/security/types/propagation.js +1 -0
- package/lib/security/types/rule-example.js +1 -0
- package/lib/security/types/schema-call.js +1 -0
- package/lib/security/types/security-check.js +1 -0
- package/lib/shared/agent-init.js +235 -0
- package/lib/shared/agent-session.js +28 -0
- package/lib/shared/agent-verify.js +239 -0
- package/lib/shared/atomic-write.js +52 -0
- package/lib/shared/baseline-flags.js +33 -0
- package/lib/shared/baseline.js +237 -0
- package/lib/shared/build-output.js +22 -0
- package/lib/shared/check.js +254 -0
- package/lib/shared/config.js +286 -0
- package/lib/shared/coverage-notes.js +27 -0
- package/lib/shared/error-code.js +9 -0
- package/lib/shared/execution-context.js +278 -0
- package/lib/shared/explain.js +34 -0
- package/lib/shared/fix-command.js +23 -0
- package/lib/shared/fix-convergence.js +389 -0
- package/lib/shared/fix-handoff.js +57 -0
- package/lib/shared/fix-history.js +303 -0
- package/lib/shared/fix-hunks.js +108 -0
- package/lib/shared/fix-imports.js +233 -0
- package/lib/shared/fix-presentation-comments.js +253 -0
- package/lib/shared/fix-presentation-prettier.js +233 -0
- package/lib/shared/fix-presentation-rows.js +157 -0
- package/lib/shared/fix-presentation-style.js +230 -0
- package/lib/shared/fix-presentation.js +177 -0
- package/lib/shared/fix-rationales.js +151 -0
- package/lib/shared/fix-recipes.js +101 -0
- package/lib/shared/fix-safety.js +64 -0
- package/lib/shared/fix-terminal.js +65 -0
- package/lib/shared/fix-typecheck.js +188 -0
- package/lib/shared/fix.js +257 -0
- package/lib/shared/formats/contract-rules.js +9 -0
- package/lib/shared/formats/finding-location.js +31 -0
- package/lib/shared/formats/github.js +36 -0
- package/lib/shared/formats/index.js +29 -0
- package/lib/shared/formats/sarif.js +91 -0
- package/lib/shared/function-summaries.js +571 -0
- package/lib/shared/function-syntax.js +86 -0
- package/lib/shared/git-hook.js +153 -0
- package/lib/shared/git-paths.js +38 -0
- package/lib/shared/glob.js +53 -0
- package/lib/shared/heap-limit.js +71 -0
- package/lib/shared/hot-path-graph.js +268 -0
- package/lib/shared/hot-path.js +20 -0
- package/lib/shared/impact-levels.js +49 -0
- package/lib/shared/is-record.js +5 -0
- package/lib/shared/managed-blocks.js +54 -0
- package/lib/shared/notify-editor.js +50 -0
- package/lib/shared/pending-review.js +117 -0
- package/lib/shared/pillar-rules.js +6 -0
- package/lib/shared/pillars.js +384 -0
- package/lib/shared/polyglot-compatibility.js +105 -0
- package/lib/shared/project-root.js +35 -0
- package/lib/shared/real-target.js +23 -0
- package/lib/shared/reason-groups.js +20 -0
- package/lib/shared/review-delivery.js +33 -0
- package/lib/shared/review-mcp.js +262 -0
- package/lib/shared/review-request.js +59 -0
- package/lib/shared/rule-registry.js +57 -0
- package/lib/shared/scan-cache.js +234 -0
- package/lib/shared/shell-argument.js +9 -0
- package/lib/shared/source-report.js +156 -0
- package/lib/shared/types/baseline.js +1 -0
- package/lib/shared/types/checker-run.js +1 -0
- package/lib/shared/types/cli-finding.js +1 -0
- package/lib/shared/types/fix-hunks.js +1 -0
- package/lib/shared/types/fix-presentation.js +1 -0
- package/lib/shared/types/fix-run.js +1 -0
- package/lib/shared/types/function-summaries.js +1 -0
- package/lib/shared/types/managed-blocks.js +1 -0
- package/lib/shared/types/pillar-name.js +1 -0
- package/lib/shared/types/report-formats.js +1 -0
- package/lib/shared/types/review-event.js +1 -0
- package/lib/shared/types/review-history.js +1 -0
- package/lib/shared/types/settings.js +1 -0
- package/lib/shared/types/source-report.js +1 -0
- package/lib/shared/types/typescript-assignment-target.js +1 -0
- package/lib/shared/types/typescript-internals.js +1 -0
- package/lib/shared/types/typescript-module-resolution.js +1 -0
- package/lib/shared/types/typescript-outer-expression.js +1 -0
- package/lib/shared/types.js +1 -0
- package/lib/shared/workspaces.js +299 -0
- package/package.json +127 -4
- package/plugin/.claude-plugin/plugin.json +9 -0
- package/plugin/commands/loadwise.md +24 -0
- package/plugin/hooks/check-edited-file.js +142 -0
- package/plugin/hooks/hooks.json +17 -0
- package/polyglot/maintainability/rules.js +159 -0
- package/polyglot/maintainability/sgconfig.yml +12 -0
- package/polyglot/performance/rules/csharp.yml +104 -0
- package/polyglot/performance/rules/go.yml +123 -0
- package/polyglot/performance/rules/input.yml +37 -0
- package/polyglot/performance/rules/java.yml +115 -0
- package/polyglot/performance/rules/python.yml +159 -0
- package/polyglot/performance/rules/rust.yml +88 -0
- package/polyglot/performance/sgconfig.yml +8 -0
- package/polyglot/reliability/rules/csharp.yml +65 -0
- package/polyglot/reliability/rules/go.yml +76 -0
- package/polyglot/reliability/rules/java.yml +41 -0
- package/polyglot/reliability/rules/python.yml +32 -0
- package/polyglot/reliability/rules/rust.yml +34 -0
- package/polyglot/reliability/sgconfig.yml +8 -0
- package/polyglot/security/rules/csharp.yml +28 -0
- package/polyglot/security/rules/go.yml +42 -0
- package/polyglot/security/rules/java.yml +17 -0
- package/polyglot/security/rules/python.yml +48 -0
- package/polyglot/security/rules/rust.yml +23 -0
- package/polyglot/security/sgconfig.yml +8 -0
- package/schema/loadwise.config.schema.json +725 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { ts, nameUsed } from './helpers.js';
|
|
2
|
+
import { forOwnNodes } from './extract-block-ast.js';
|
|
3
|
+
// `items`, `ITEM_KEYS` or `item_keys` as a capitalized part of a camelCase name.
|
|
4
|
+
function pascal(word) {
|
|
5
|
+
const parts = /[a-z]/.test(word) && !word.includes('_') ? [word] : word.toLowerCase().split('_').filter(Boolean);
|
|
6
|
+
return parts.map((part) => part[0].toUpperCase() + part.slice(1)).join('');
|
|
7
|
+
}
|
|
8
|
+
// Methods that read or reshape their receiver, so the receiver names what the code is about.
|
|
9
|
+
const receiverMethods = new Set([
|
|
10
|
+
'get',
|
|
11
|
+
'has',
|
|
12
|
+
'includes',
|
|
13
|
+
'some',
|
|
14
|
+
'every',
|
|
15
|
+
'find',
|
|
16
|
+
'at',
|
|
17
|
+
'indexOf',
|
|
18
|
+
'filter',
|
|
19
|
+
'map',
|
|
20
|
+
'slice',
|
|
21
|
+
'entries',
|
|
22
|
+
'values',
|
|
23
|
+
'keys',
|
|
24
|
+
'flat',
|
|
25
|
+
'flatMap',
|
|
26
|
+
'sort',
|
|
27
|
+
'reverse',
|
|
28
|
+
'concat',
|
|
29
|
+
'from',
|
|
30
|
+
'toSorted',
|
|
31
|
+
'toReversed',
|
|
32
|
+
]);
|
|
33
|
+
// The noun a loop or condition is about: the last name in `a.b.items`, the receiver of
|
|
34
|
+
// `items.filter(...)`, the argument of `Object.entries(items)`, or `items` in `getItems()`.
|
|
35
|
+
function subjectName(expression) {
|
|
36
|
+
if (!expression)
|
|
37
|
+
return;
|
|
38
|
+
if (ts.isIdentifier(expression))
|
|
39
|
+
return expression.text;
|
|
40
|
+
if (ts.isPropertyAccessExpression(expression)) {
|
|
41
|
+
if (expression.name.text === 'length' || expression.name.text === 'size')
|
|
42
|
+
return subjectName(expression.expression);
|
|
43
|
+
return expression.name.text;
|
|
44
|
+
}
|
|
45
|
+
if (ts.isCallExpression(expression)) {
|
|
46
|
+
const callee = expression.expression;
|
|
47
|
+
if (ts.isPropertyAccessExpression(callee)) {
|
|
48
|
+
const receiver = callee.expression;
|
|
49
|
+
// Static helpers such as Object.entries(items) or Array.from(items) are about their argument.
|
|
50
|
+
const staticHelper = ts.isIdentifier(receiver) && /^[A-Z]/.test(receiver.text);
|
|
51
|
+
if (staticHelper && expression.arguments.length)
|
|
52
|
+
return subjectName(expression.arguments[0]);
|
|
53
|
+
if (receiverMethods.has(callee.name.text))
|
|
54
|
+
return subjectName(receiver);
|
|
55
|
+
}
|
|
56
|
+
return subjectName(callee)?.replace(/^(get|find|list|load|fetch)(?=[A-Z])/, '');
|
|
57
|
+
}
|
|
58
|
+
if (ts.isParenthesizedExpression(expression) ||
|
|
59
|
+
ts.isNonNullExpression(expression) ||
|
|
60
|
+
ts.isAsExpression(expression) ||
|
|
61
|
+
ts.isElementAccessExpression(expression))
|
|
62
|
+
return subjectName(expression.expression);
|
|
63
|
+
if (ts.isPrefixUnaryExpression(expression))
|
|
64
|
+
return subjectName(expression.operand);
|
|
65
|
+
if (ts.isBinaryExpression(expression))
|
|
66
|
+
return subjectName(expression.left) ?? subjectName(expression.right);
|
|
67
|
+
if (ts.isTypeOfExpression(expression))
|
|
68
|
+
return subjectName(expression.expression);
|
|
69
|
+
}
|
|
70
|
+
// The first call the statement makes, as the action a try block attempts.
|
|
71
|
+
function firstCallName(statement) {
|
|
72
|
+
let name;
|
|
73
|
+
forOwnNodes(statement, (node) => {
|
|
74
|
+
if (name)
|
|
75
|
+
return false;
|
|
76
|
+
if (ts.isCallExpression(node))
|
|
77
|
+
name = subjectName(node.expression);
|
|
78
|
+
});
|
|
79
|
+
return name;
|
|
80
|
+
}
|
|
81
|
+
function assertionCall(expression) {
|
|
82
|
+
if (!ts.isCallExpression(expression))
|
|
83
|
+
return false;
|
|
84
|
+
const callee = expression.expression;
|
|
85
|
+
if (ts.isIdentifier(callee))
|
|
86
|
+
return callee.text.startsWith('assert');
|
|
87
|
+
return (ts.isPropertyAccessExpression(callee) &&
|
|
88
|
+
((ts.isIdentifier(callee.expression) && callee.expression.text === 'assert') ||
|
|
89
|
+
callee.name.text.startsWith('assert')));
|
|
90
|
+
}
|
|
91
|
+
// Code that only checks: every path ends in a throw or an assertion call, so it changes nothing
|
|
92
|
+
// when it passes.
|
|
93
|
+
function onlyValidates(statement) {
|
|
94
|
+
if (ts.isThrowStatement(statement))
|
|
95
|
+
return true;
|
|
96
|
+
if (ts.isExpressionStatement(statement))
|
|
97
|
+
return assertionCall(statement.expression);
|
|
98
|
+
if (ts.isBlock(statement))
|
|
99
|
+
return statement.statements.length > 0 && statement.statements.every(onlyValidates);
|
|
100
|
+
if (ts.isIfStatement(statement))
|
|
101
|
+
return (onlyValidates(statement.thenStatement) && (!statement.elseStatement || onlyValidates(statement.elseStatement)));
|
|
102
|
+
if (ts.isIterationStatement(statement, false))
|
|
103
|
+
return onlyValidates(statement.statement);
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
// `if (file.isDeclarationFile)` is about the declaration file, so the name is
|
|
107
|
+
// handleDeclarationFile, not handleIsDeclarationFile.
|
|
108
|
+
const booleanPrefix = /^(?:is|has)(?=[A-Z])/;
|
|
109
|
+
function describedName(statement) {
|
|
110
|
+
const verb = onlyValidates(statement) ? 'assert' : undefined;
|
|
111
|
+
if (ts.isForOfStatement(statement) || ts.isForInStatement(statement)) {
|
|
112
|
+
const subject = subjectName(statement.expression);
|
|
113
|
+
return subject && (verb ?? 'process') + pascal(subject);
|
|
114
|
+
}
|
|
115
|
+
if (ts.isForStatement(statement) || ts.isWhileStatement(statement) || ts.isDoStatement(statement)) {
|
|
116
|
+
const condition = ts.isForStatement(statement) ? statement.condition : statement.expression;
|
|
117
|
+
// `i < items.length` is about items, not the counter.
|
|
118
|
+
const bound = condition && ts.isBinaryExpression(condition) ? subjectName(condition.right) : undefined;
|
|
119
|
+
const subject = bound ?? subjectName(condition);
|
|
120
|
+
return subject && (verb ?? 'process') + pascal(subject);
|
|
121
|
+
}
|
|
122
|
+
if (ts.isIfStatement(statement) || ts.isSwitchStatement(statement)) {
|
|
123
|
+
const subject = subjectName(statement.expression)?.replace(booleanPrefix, '');
|
|
124
|
+
return subject && (verb ?? 'handle') + pascal(subject);
|
|
125
|
+
}
|
|
126
|
+
if (ts.isTryStatement(statement)) {
|
|
127
|
+
const action = firstCallName(statement.tryBlock);
|
|
128
|
+
return action && 'try' + pascal(action);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
// A descriptive name that nothing in the file already uses, so the function shadows and clashes
|
|
132
|
+
// with nothing.
|
|
133
|
+
export function helperName(statement, sourceFile) {
|
|
134
|
+
const base = describedName(statement);
|
|
135
|
+
if (!base || !/^[A-Za-z_$][\w$]*$/.test(base))
|
|
136
|
+
return;
|
|
137
|
+
if (!nameUsed(sourceFile, base))
|
|
138
|
+
return base;
|
|
139
|
+
}
|
|
140
|
+
// `buildSeen` for the collection `seen`, when nothing in the file uses that name.
|
|
141
|
+
export function builderName(variable, sourceFile) {
|
|
142
|
+
const name = 'build' + pascal(variable.symbol.name);
|
|
143
|
+
if (!nameUsed(sourceFile, name))
|
|
144
|
+
return name;
|
|
145
|
+
}
|
|
146
|
+
// Whether a new method `name` would clash with a member the class declares or inherits, on its
|
|
147
|
+
// instance or static side, or one an implemented interface declares. A base or interface the
|
|
148
|
+
// isolated checker cannot resolve, such as an imported one, may define any name, so it counts as a
|
|
149
|
+
// clash.
|
|
150
|
+
export function memberNameTaken(classNode, name, checker) {
|
|
151
|
+
for (const clause of classNode.heritageClauses ?? [])
|
|
152
|
+
for (const heritage of clause.types) {
|
|
153
|
+
const type = checker.getTypeAtLocation(heritage);
|
|
154
|
+
if (type.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown))
|
|
155
|
+
return true;
|
|
156
|
+
if (checker.getPropertiesOfType(type).some((property) => property.name === name))
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
const symbol = classNode.name ? checker.getSymbolAtLocation(classNode.name) : classNode.symbol;
|
|
160
|
+
if (!symbol)
|
|
161
|
+
return true;
|
|
162
|
+
const sides = [checker.getDeclaredTypeOfSymbol(symbol), checker.getTypeOfSymbol(symbol)];
|
|
163
|
+
return sides.some((type) => checker.getPropertiesOfType(type).some((property) => property.name === name));
|
|
164
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { ts } from './helpers.js';
|
|
2
|
+
import { bindingList, contains, isIncrement, symbolOf } from './extract-block-ast.js';
|
|
3
|
+
// `a.b?.c!` and `a["b"]` as the path TypeScript narrows: `a.b.c`, `a.b`. Undefined for anything
|
|
4
|
+
// else.
|
|
5
|
+
function referencePath(node) {
|
|
6
|
+
if (ts.isIdentifier(node))
|
|
7
|
+
return node.text;
|
|
8
|
+
if (node.kind === ts.SyntaxKind.ThisKeyword)
|
|
9
|
+
return 'this';
|
|
10
|
+
if (ts.isParenthesizedExpression(node) || ts.isNonNullExpression(node))
|
|
11
|
+
return referencePath(node.expression);
|
|
12
|
+
if (!ts.isPropertyAccessExpression(node) && !ts.isElementAccessExpression(node))
|
|
13
|
+
return;
|
|
14
|
+
const owner = referencePath(node.expression);
|
|
15
|
+
if (!owner)
|
|
16
|
+
return;
|
|
17
|
+
if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.name))
|
|
18
|
+
return owner + '.' + node.name.text;
|
|
19
|
+
if (ts.isElementAccessExpression(node) && ts.isStringLiteralLike(node.argumentExpression))
|
|
20
|
+
return owner + '.' + node.argumentExpression.text;
|
|
21
|
+
// TypeScript also narrows `a[key]` for a constant key.
|
|
22
|
+
if (ts.isElementAccessExpression(node) && ts.isIdentifier(node.argumentExpression))
|
|
23
|
+
return owner + '[' + node.argumentExpression.text + ']';
|
|
24
|
+
}
|
|
25
|
+
function isPathNode(node) {
|
|
26
|
+
return (ts.isIdentifier(node) ||
|
|
27
|
+
node.kind === ts.SyntaxKind.ThisKeyword ||
|
|
28
|
+
ts.isPropertyAccessExpression(node) ||
|
|
29
|
+
ts.isElementAccessExpression(node));
|
|
30
|
+
}
|
|
31
|
+
// Paths under `root`. A called function is not narrowed by the call, so callees are left out.
|
|
32
|
+
function addPaths(root, paths) {
|
|
33
|
+
(function walk(node) {
|
|
34
|
+
const callee = ts.isCallExpression(node.parent) && node.parent.expression === node;
|
|
35
|
+
if (isPathNode(node) && !callee) {
|
|
36
|
+
const found = referencePath(node);
|
|
37
|
+
if (found)
|
|
38
|
+
paths.add(found);
|
|
39
|
+
}
|
|
40
|
+
ts.forEachChild(node, walk);
|
|
41
|
+
})(root);
|
|
42
|
+
}
|
|
43
|
+
// Expressions whose paths TypeScript may narrow for the code after them.
|
|
44
|
+
function narrowingParts(node) {
|
|
45
|
+
if (ts.isIfStatement(node) || ts.isWhileStatement(node) || ts.isDoStatement(node))
|
|
46
|
+
return [node.expression];
|
|
47
|
+
if (ts.isSwitchStatement(node))
|
|
48
|
+
return [node.expression];
|
|
49
|
+
if (ts.isForStatement(node))
|
|
50
|
+
return [node.condition];
|
|
51
|
+
if (ts.isConditionalExpression(node))
|
|
52
|
+
return [node.condition];
|
|
53
|
+
if (ts.isBinaryExpression(node)) {
|
|
54
|
+
const operator = node.operatorToken.kind;
|
|
55
|
+
if (ts.isAssignmentOperator(operator))
|
|
56
|
+
return [node.left];
|
|
57
|
+
if (operator === ts.SyntaxKind.AmpersandAmpersandToken ||
|
|
58
|
+
operator === ts.SyntaxKind.BarBarToken ||
|
|
59
|
+
operator === ts.SyntaxKind.QuestionQuestionToken)
|
|
60
|
+
return [node.left];
|
|
61
|
+
}
|
|
62
|
+
if (ts.isCallExpression(node) && /^assert/i.test(referencePath(node.expression)?.split('.').at(-1) ?? ''))
|
|
63
|
+
return node.arguments;
|
|
64
|
+
if (isIncrement(node))
|
|
65
|
+
return [node.operand];
|
|
66
|
+
// A declared union narrows to the type of its initializer.
|
|
67
|
+
if ((ts.isVariableDeclaration(node) || ts.isParameter(node)) && node.initializer)
|
|
68
|
+
return [node.name];
|
|
69
|
+
return [];
|
|
70
|
+
}
|
|
71
|
+
// Paths of `fn` outside `statement` that a condition, assertion or assignment may narrow.
|
|
72
|
+
function narrowedPaths(fn, statement) {
|
|
73
|
+
const paths = new Set();
|
|
74
|
+
(function walk(node) {
|
|
75
|
+
if (node === statement)
|
|
76
|
+
return;
|
|
77
|
+
for (const part of narrowingParts(node))
|
|
78
|
+
if (part)
|
|
79
|
+
addPaths(part, paths);
|
|
80
|
+
ts.forEachChild(node, walk);
|
|
81
|
+
})(fn);
|
|
82
|
+
return paths;
|
|
83
|
+
}
|
|
84
|
+
// A type narrowing cannot change: known, and neither a union nor any/unknown (which unresolved
|
|
85
|
+
// imports become).
|
|
86
|
+
function plainType(type) {
|
|
87
|
+
return !(type.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown | ts.TypeFlags.Never)) && !type.isUnion();
|
|
88
|
+
}
|
|
89
|
+
function constantSymbol(symbol) {
|
|
90
|
+
const declaration = symbol.valueDeclaration ?? symbol.declarations?.[0];
|
|
91
|
+
if (!declaration)
|
|
92
|
+
return false;
|
|
93
|
+
if (ts.isVariableDeclaration(declaration) || ts.isBindingElement(declaration)) {
|
|
94
|
+
const list = bindingList(declaration);
|
|
95
|
+
return Boolean(list && ts.isVariableDeclarationList(list) && list.flags & ts.NodeFlags.Const);
|
|
96
|
+
}
|
|
97
|
+
return (ts.isImportSpecifier(declaration) ||
|
|
98
|
+
ts.isImportClause(declaration) ||
|
|
99
|
+
ts.isNamespaceImport(declaration) ||
|
|
100
|
+
ts.isClassDeclaration(declaration) ||
|
|
101
|
+
ts.isEnumDeclaration(declaration));
|
|
102
|
+
}
|
|
103
|
+
// TypeScript narrows outer paths for the code inside them; a separate function sees only declared
|
|
104
|
+
// types. The parameters carry the narrowed type of each variable, but paths through properties and
|
|
105
|
+
// module bindings lose it.
|
|
106
|
+
export function narrowingLost(statement, fn, checker, variables, builtDeclaration) {
|
|
107
|
+
const narrowed = narrowedPaths(fn, statement);
|
|
108
|
+
const parameters = new Set(variables.map((variable) => variable.symbol));
|
|
109
|
+
let lost = false;
|
|
110
|
+
(function walk(node) {
|
|
111
|
+
if (lost)
|
|
112
|
+
return;
|
|
113
|
+
const path = isPathNode(node) && referencePath(node);
|
|
114
|
+
if (path && narrowed.has(path) && !(ts.isPropertyAccessExpression(node.parent) && node.parent.name === node)) {
|
|
115
|
+
if (ts.isIdentifier(node)) {
|
|
116
|
+
const symbol = symbolOf(checker, node);
|
|
117
|
+
const declaration = symbol?.valueDeclaration ?? symbol?.declarations?.[0];
|
|
118
|
+
if (!symbol)
|
|
119
|
+
lost = true;
|
|
120
|
+
// The parameter type is read at this spot, so it is narrowed already, unless it is unknown here.
|
|
121
|
+
else if (parameters.has(symbol))
|
|
122
|
+
lost = Boolean(checker.getTypeAtLocation(node).flags & ts.TypeFlags.Any);
|
|
123
|
+
else if (declaration && (contains(statement, declaration) || declaration === builtDeclaration))
|
|
124
|
+
lost = false;
|
|
125
|
+
else
|
|
126
|
+
lost = !(plainType(checker.getTypeOfSymbol(symbol)) ||
|
|
127
|
+
(declaration !== undefined &&
|
|
128
|
+
constantSymbol(symbol) &&
|
|
129
|
+
!ts.isVariableDeclaration(declaration) &&
|
|
130
|
+
!ts.isBindingElement(declaration)));
|
|
131
|
+
}
|
|
132
|
+
else if (path.includes('.') || path.includes('[')) {
|
|
133
|
+
const property = ts.isPropertyAccessExpression(node) && checker.getSymbolAtLocation(node.name);
|
|
134
|
+
if (!property || !plainType(checker.getTypeOfSymbol(property)))
|
|
135
|
+
lost = true;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
ts.forEachChild(node, walk);
|
|
139
|
+
})(statement);
|
|
140
|
+
return lost;
|
|
141
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Moves one statement into a named function and calls it where the statement stood:
|
|
2
|
+
// processRows(rows, seen);
|
|
3
|
+
// ...
|
|
4
|
+
// function processRows(rows: Row[], seen: Set<string>) { ...statement }
|
|
5
|
+
// The function is declared after the top-level statement that holds the code, or, inside a class
|
|
6
|
+
// method, as a private method next to it called through `this`. Local variables the statement reads
|
|
7
|
+
// become parameters, in order of first use. It is offered only when the statement finishes normally
|
|
8
|
+
// (no return, no break or continue that leaves it, no await or yield), takes at most four
|
|
9
|
+
// parameters, and reassigns none of them, except one outer `let` that the function returns and the
|
|
10
|
+
// call assigns back: `total = sumRows(rows, total)`. When the statement only fills one empty
|
|
11
|
+
// collection that the line above declares and the code after it uses, the function creates and
|
|
12
|
+
// returns that collection instead, and the call declares it: `const seen = buildSeen(rows)`. A
|
|
13
|
+
// parameter is a copy taken at the call, so it is refused when a closure could see the variable
|
|
14
|
+
// change. In TypeScript every parameter gets the type the checker gives the variable at that spot,
|
|
15
|
+
// and the rewritten file must not type-check worse.
|
|
16
|
+
import { applyEdits } from '../../shared/fix-hunks.js';
|
|
17
|
+
import { typeChecksAsBefore } from './isolated-program.js';
|
|
18
|
+
import { extractionEdits, extractionPlan } from './extract-block-edits.js';
|
|
19
|
+
import { decisionCount, fitsHunks, measuredEdits, ownStatements } from './extract-block-measure.js';
|
|
20
|
+
// The edits that move `statement` out of `fn` into a named function: the call in its place and the
|
|
21
|
+
// declaration after the enclosing member or top-level statement, with `typeChecks()` to run once
|
|
22
|
+
// the edits are wanted, since it checks the whole rewritten file. Undefined when it would not run
|
|
23
|
+
// the same code.
|
|
24
|
+
function extractionDraft(statement, fn, sourceFile) {
|
|
25
|
+
const plan = extractionPlan(statement, fn, sourceFile);
|
|
26
|
+
const edits = plan && extractionEdits(plan);
|
|
27
|
+
if (!edits || !fitsHunks(sourceFile, edits))
|
|
28
|
+
return;
|
|
29
|
+
const typeChecks = () => !plan.typeScript || typeChecksAsBefore(sourceFile, applyEdits(sourceFile.text, edits));
|
|
30
|
+
return { name: plan.signature.name, edits, typeChecks };
|
|
31
|
+
}
|
|
32
|
+
// Like extractionDraft, but also undefined when the rewritten file would not type-check the same.
|
|
33
|
+
function extractionEdit(statement, fn, sourceFile) {
|
|
34
|
+
const draft = extractionDraft(statement, fn, sourceFile);
|
|
35
|
+
if (draft?.typeChecks())
|
|
36
|
+
return { name: draft.name, edits: draft.edits };
|
|
37
|
+
}
|
|
38
|
+
export { extractionDraft, extractionEdit, fitsHunks, measuredEdits, ownStatements, decisionCount };
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
// Shared syntax helpers for site-fix builders. Builders return edits as { start, end, text } file
|
|
2
|
+
// offsets.
|
|
3
|
+
import * as ts from 'typescript';
|
|
4
|
+
function ancestor(node, predicate) {
|
|
5
|
+
for (let current = node; current; current = current.parent)
|
|
6
|
+
if (predicate(current))
|
|
7
|
+
return current;
|
|
8
|
+
}
|
|
9
|
+
function functionWithBody(node) {
|
|
10
|
+
return node !== undefined && ts.isFunctionLike(node) && 'body' in node && node.body !== undefined;
|
|
11
|
+
}
|
|
12
|
+
// The function a finding names: findings point at its name, or at the variable or property that
|
|
13
|
+
// holds it.
|
|
14
|
+
function hasBlockBody(fn) {
|
|
15
|
+
return ts.isBlock(fn.body);
|
|
16
|
+
}
|
|
17
|
+
function flaggedFunction(node) {
|
|
18
|
+
if (functionWithBody(node))
|
|
19
|
+
return node;
|
|
20
|
+
const parent = node.parent;
|
|
21
|
+
if (functionWithBody(parent) && parent.name === node)
|
|
22
|
+
return parent;
|
|
23
|
+
// An anonymous `async (...) => {}` is reported at its first token, the async modifier.
|
|
24
|
+
if (functionWithBody(parent) && parent.modifiers?.[0] === node)
|
|
25
|
+
return parent;
|
|
26
|
+
const named = parent &&
|
|
27
|
+
(ts.isVariableDeclaration(parent) || ts.isPropertyAssignment(parent) || ts.isPropertyDeclaration(parent)) &&
|
|
28
|
+
parent.name === node;
|
|
29
|
+
if (named && functionWithBody(parent.initializer))
|
|
30
|
+
return parent.initializer;
|
|
31
|
+
}
|
|
32
|
+
function lineStart(text, offset) {
|
|
33
|
+
return text.lastIndexOf('\n', offset - 1) + 1;
|
|
34
|
+
}
|
|
35
|
+
// Offset of the line break (or the end of the text) after `offset`.
|
|
36
|
+
function lineEnd(text, offset) {
|
|
37
|
+
const index = text.indexOf('\n', offset);
|
|
38
|
+
if (index === -1)
|
|
39
|
+
return text.length;
|
|
40
|
+
return text[index - 1] === '\r' ? index - 1 : index;
|
|
41
|
+
}
|
|
42
|
+
// Offset of the first character on the line after the one holding `offset`.
|
|
43
|
+
function nextLineStart(text, offset) {
|
|
44
|
+
const index = text.indexOf('\n', offset);
|
|
45
|
+
return index === -1 ? text.length : index + 1;
|
|
46
|
+
}
|
|
47
|
+
function indentationAt(text, offset) {
|
|
48
|
+
return /^[ \t]*/.exec(text.slice(lineStart(text, offset)))?.[0] ?? '';
|
|
49
|
+
}
|
|
50
|
+
function newlineOf(text) {
|
|
51
|
+
return text.includes('\r\n') ? '\r\n' : '\n';
|
|
52
|
+
}
|
|
53
|
+
function blank(text) {
|
|
54
|
+
return !text.trim();
|
|
55
|
+
}
|
|
56
|
+
// True when `name` appears anywhere under `node`, so a new binding with that name could shadow or
|
|
57
|
+
// clash.
|
|
58
|
+
function nameUsed(node, name) {
|
|
59
|
+
let used = false;
|
|
60
|
+
(function visit(current) {
|
|
61
|
+
if (used)
|
|
62
|
+
return;
|
|
63
|
+
if ((ts.isIdentifier(current) || ts.isPrivateIdentifier(current)) && current.text === name)
|
|
64
|
+
used = true;
|
|
65
|
+
else
|
|
66
|
+
ts.forEachChild(current, visit);
|
|
67
|
+
})(node);
|
|
68
|
+
return used;
|
|
69
|
+
}
|
|
70
|
+
// `node` is alone on its lines: only indentation before it and nothing after it on its last line.
|
|
71
|
+
function ownsLines(node) {
|
|
72
|
+
const sourceFile = node.getSourceFile();
|
|
73
|
+
const text = sourceFile.text;
|
|
74
|
+
const start = node.getStart(sourceFile);
|
|
75
|
+
return blank(text.slice(lineStart(text, start), start)) && blank(text.slice(node.end, lineEnd(text, node.end)));
|
|
76
|
+
}
|
|
77
|
+
// A comment inside `node`; rewrites that rebuild the node's text from its parts would drop it.
|
|
78
|
+
function hasComments(node) {
|
|
79
|
+
const sourceFile = node.getSourceFile();
|
|
80
|
+
const start = node.getStart(sourceFile);
|
|
81
|
+
let found = false;
|
|
82
|
+
(function visit(current) {
|
|
83
|
+
if (found)
|
|
84
|
+
return;
|
|
85
|
+
if (current.pos > start && ts.getLeadingCommentRanges(sourceFile.text, current.pos)?.length)
|
|
86
|
+
found = true;
|
|
87
|
+
else
|
|
88
|
+
for (const child of current.getChildren(sourceFile))
|
|
89
|
+
visit(child);
|
|
90
|
+
})(node);
|
|
91
|
+
return found;
|
|
92
|
+
}
|
|
93
|
+
// Template text and multiline strings keep their indentation as part of their value.
|
|
94
|
+
function hasMultilineLiteral(node) {
|
|
95
|
+
const sourceFile = node.getSourceFile();
|
|
96
|
+
let found = false;
|
|
97
|
+
(function visit(current) {
|
|
98
|
+
if (found)
|
|
99
|
+
return;
|
|
100
|
+
const literal = ts.isTemplateLiteralToken(current) ||
|
|
101
|
+
ts.isNoSubstitutionTemplateLiteral(current) ||
|
|
102
|
+
ts.isStringLiteral(current) ||
|
|
103
|
+
ts.isJsxText(current);
|
|
104
|
+
if (literal && current.getText(sourceFile).includes('\n'))
|
|
105
|
+
found = true;
|
|
106
|
+
else
|
|
107
|
+
ts.forEachChild(current, visit);
|
|
108
|
+
})(node);
|
|
109
|
+
return found;
|
|
110
|
+
}
|
|
111
|
+
// Removes one indentation `step` from each line, or undefined when a non-blank line is not indented
|
|
112
|
+
// that far. Callers reject multiline literals first, because their text would change.
|
|
113
|
+
function dedentLines(lines, step) {
|
|
114
|
+
const result = [];
|
|
115
|
+
for (const line of lines.split('\n')) {
|
|
116
|
+
if (blank(line))
|
|
117
|
+
result.push(line.replace(/^[ \t]+/, ''));
|
|
118
|
+
else if (line.startsWith(step))
|
|
119
|
+
result.push(line.slice(step.length));
|
|
120
|
+
else
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
return result.join('\n');
|
|
124
|
+
}
|
|
125
|
+
// The block's statements as whole lines, with the indentation step they carry beyond
|
|
126
|
+
// `outerIndentation`. Undefined unless the braces sit alone at the ends of their lines.
|
|
127
|
+
function blockBody(block, outerIndentation) {
|
|
128
|
+
const sourceFile = block.getSourceFile();
|
|
129
|
+
const text = sourceFile.text;
|
|
130
|
+
const open = block.getStart(sourceFile);
|
|
131
|
+
const close = block.end - 1;
|
|
132
|
+
if (!block.statements.length || !blank(text.slice(open + 1, lineEnd(text, open))))
|
|
133
|
+
return;
|
|
134
|
+
if (!blank(text.slice(lineStart(text, close), close)))
|
|
135
|
+
return;
|
|
136
|
+
const first = block.statements[0].getStart(sourceFile);
|
|
137
|
+
const indentation = indentationAt(text, first);
|
|
138
|
+
if (!indentation.startsWith(outerIndentation) || indentation === outerIndentation)
|
|
139
|
+
return;
|
|
140
|
+
return {
|
|
141
|
+
lines: text.slice(nextLineStart(text, open), lineStart(text, close)),
|
|
142
|
+
step: indentation.slice(outerIndentation.length),
|
|
143
|
+
closeLineStart: lineStart(text, close),
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
const looseOperators = new Set([
|
|
147
|
+
ts.SyntaxKind.BarBarToken,
|
|
148
|
+
ts.SyntaxKind.QuestionQuestionToken,
|
|
149
|
+
ts.SyntaxKind.CommaToken,
|
|
150
|
+
]);
|
|
151
|
+
// The expression as an operand of `&&` or `||`, parenthesized when it binds more loosely or cannot
|
|
152
|
+
// mix with them.
|
|
153
|
+
function logicalOperand(expression, sourceFile) {
|
|
154
|
+
const text = expression.getText(sourceFile);
|
|
155
|
+
const loose = (ts.isBinaryExpression(expression) &&
|
|
156
|
+
(looseOperators.has(expression.operatorToken.kind) || ts.isAssignmentOperator(expression.operatorToken.kind))) ||
|
|
157
|
+
ts.isConditionalExpression(expression) ||
|
|
158
|
+
ts.isArrowFunction(expression) ||
|
|
159
|
+
ts.isYieldExpression(expression);
|
|
160
|
+
return loose ? '(' + text + ')' : text;
|
|
161
|
+
}
|
|
162
|
+
// The expression's text on one line, for joining conditions. Undefined when a comment or a
|
|
163
|
+
// multiline literal would change meaning once line breaks are gone.
|
|
164
|
+
function singleLine(text, node) {
|
|
165
|
+
if (!text.includes('\n'))
|
|
166
|
+
return text;
|
|
167
|
+
if (hasComments(node) || hasMultilineLiteral(node))
|
|
168
|
+
return;
|
|
169
|
+
// A trailing comma goes with its line break, but never one of two commas that mark an array hole.
|
|
170
|
+
return text
|
|
171
|
+
.replaceAll(/([([])\s*\n\s*/g, '$1')
|
|
172
|
+
.replaceAll(/\{\s*\n\s*/g, '{ ')
|
|
173
|
+
.replaceAll(/(?<!,),?\s*\n\s*([)\]])/g, '$1')
|
|
174
|
+
.replaceAll(/(?<!,),?\s*\n\s*\}/g, ' }')
|
|
175
|
+
.replaceAll(/\s*\n\s*/g, ' ');
|
|
176
|
+
}
|
|
177
|
+
const comparisonInverses = new Map([
|
|
178
|
+
[ts.SyntaxKind.EqualsEqualsEqualsToken, '!=='],
|
|
179
|
+
[ts.SyntaxKind.ExclamationEqualsEqualsToken, '==='],
|
|
180
|
+
[ts.SyntaxKind.EqualsEqualsToken, '!='],
|
|
181
|
+
[ts.SyntaxKind.ExclamationEqualsToken, '=='],
|
|
182
|
+
]);
|
|
183
|
+
const logicalOperators = new Map([
|
|
184
|
+
[ts.SyntaxKind.AmpersandAmpersandToken, '&&'],
|
|
185
|
+
[ts.SyntaxKind.BarBarToken, '||'],
|
|
186
|
+
]);
|
|
187
|
+
function withoutParentheses(expression) {
|
|
188
|
+
let bare = expression;
|
|
189
|
+
while (ts.isParenthesizedExpression(bare))
|
|
190
|
+
bare = bare.expression;
|
|
191
|
+
return bare;
|
|
192
|
+
}
|
|
193
|
+
function logicalOperator(expression) {
|
|
194
|
+
return ts.isBinaryExpression(expression) ? logicalOperators.get(expression.operatorToken.kind) : undefined;
|
|
195
|
+
}
|
|
196
|
+
// The top-level operator that decides whether `text` needs parentheses inside an `&&` or `||`
|
|
197
|
+
// chain: '&&' or '||' for those chains, 'loose' for anything else that binds more loosely or cannot
|
|
198
|
+
// mix with them.
|
|
199
|
+
function joinOperator(expression) {
|
|
200
|
+
const operator = logicalOperator(expression);
|
|
201
|
+
if (operator)
|
|
202
|
+
return operator;
|
|
203
|
+
return logicalOperand(expression, expression.getSourceFile()).startsWith('(') ? 'loose' : undefined;
|
|
204
|
+
}
|
|
205
|
+
// The number of `&&` and `||` operands a reader has to keep in mind, through parentheses and
|
|
206
|
+
// negations.
|
|
207
|
+
function clauseCount(expression) {
|
|
208
|
+
const bare = withoutParentheses(expression);
|
|
209
|
+
if (ts.isBinaryExpression(bare) && logicalOperator(bare))
|
|
210
|
+
return clauseCount(bare.left) + clauseCount(bare.right);
|
|
211
|
+
if (ts.isPrefixUnaryExpression(bare) && bare.operator === ts.SyntaxKind.ExclamationToken)
|
|
212
|
+
return clauseCount(bare.operand);
|
|
213
|
+
return 1;
|
|
214
|
+
}
|
|
215
|
+
// A rewritten condition line stays readable: short enough to scan, with few clauses to combine.
|
|
216
|
+
const maxConditionLineLength = 100;
|
|
217
|
+
const maxConditionClauses = 3;
|
|
218
|
+
function readableCondition(line, clauses) {
|
|
219
|
+
return line.length <= maxConditionLineLength && clauses <= maxConditionClauses;
|
|
220
|
+
}
|
|
221
|
+
// Joins operands with `operator`, parenthesizing any whose own top-level operator differs, so `&&`
|
|
222
|
+
// and `||` never mix without explicit grouping.
|
|
223
|
+
function joinOperands(parts, operator) {
|
|
224
|
+
return parts
|
|
225
|
+
.map((part) => (part.operator && part.operator !== operator ? `(${part.text})` : part.text))
|
|
226
|
+
.join(` ${operator} `);
|
|
227
|
+
}
|
|
228
|
+
// The negation of `expression` as { text, operator }. `&&` and `||` chains negate operand by
|
|
229
|
+
// operand (De Morgan), so a negated operand never ends up inside a second negation.
|
|
230
|
+
function negation(expression, sourceFile) {
|
|
231
|
+
const bare = withoutParentheses(expression);
|
|
232
|
+
const operator = logicalOperator(bare);
|
|
233
|
+
if (operator && ts.isBinaryExpression(bare)) {
|
|
234
|
+
const flipped = operator === '&&' ? '||' : '&&';
|
|
235
|
+
const parts = [negation(bare.left, sourceFile), negation(bare.right, sourceFile)];
|
|
236
|
+
return { text: joinOperands(parts, flipped), operator: flipped };
|
|
237
|
+
}
|
|
238
|
+
if (ts.isPrefixUnaryExpression(bare) && bare.operator === ts.SyntaxKind.ExclamationToken) {
|
|
239
|
+
const operand = withoutParentheses(bare.operand);
|
|
240
|
+
return { text: operand.getText(sourceFile), operator: joinOperator(operand) };
|
|
241
|
+
}
|
|
242
|
+
return { text: negatedTerm(bare, sourceFile) };
|
|
243
|
+
}
|
|
244
|
+
// A condition that is true exactly when `expression` is falsy. Only valid where the result is
|
|
245
|
+
// tested for truth.
|
|
246
|
+
function negateCondition(expression, sourceFile) {
|
|
247
|
+
return negation(expression, sourceFile).text;
|
|
248
|
+
}
|
|
249
|
+
function negatedTerm(expression, sourceFile) {
|
|
250
|
+
const text = expression.getText(sourceFile);
|
|
251
|
+
if (ts.isBinaryExpression(expression) && comparisonInverses.has(expression.operatorToken.kind)) {
|
|
252
|
+
const operator = expression.operatorToken;
|
|
253
|
+
const start = expression.getStart(sourceFile);
|
|
254
|
+
return (text.slice(0, operator.getStart(sourceFile) - start) +
|
|
255
|
+
comparisonInverses.get(operator.kind) +
|
|
256
|
+
text.slice(operator.end - start));
|
|
257
|
+
}
|
|
258
|
+
const tight = ts.isIdentifier(expression) ||
|
|
259
|
+
ts.isPropertyAccessExpression(expression) ||
|
|
260
|
+
ts.isElementAccessExpression(expression) ||
|
|
261
|
+
ts.isCallExpression(expression) ||
|
|
262
|
+
ts.isParenthesizedExpression(expression);
|
|
263
|
+
return tight ? '!' + text : '!(' + text + ')';
|
|
264
|
+
}
|
|
265
|
+
function addBindingNames(name, names) {
|
|
266
|
+
if (ts.isIdentifier(name))
|
|
267
|
+
names.push(name.text);
|
|
268
|
+
else
|
|
269
|
+
for (const element of name.elements)
|
|
270
|
+
if (!ts.isOmittedExpression(element))
|
|
271
|
+
addBindingNames(element.name, names);
|
|
272
|
+
}
|
|
273
|
+
// Names declared directly among `statements` with block scope.
|
|
274
|
+
function blockScopedNames(statements) {
|
|
275
|
+
const names = [];
|
|
276
|
+
for (const statement of statements) {
|
|
277
|
+
if (ts.isVariableStatement(statement)) {
|
|
278
|
+
for (const declaration of statement.declarationList.declarations)
|
|
279
|
+
addBindingNames(declaration.name, names);
|
|
280
|
+
}
|
|
281
|
+
else if ((ts.isClassDeclaration(statement) ||
|
|
282
|
+
ts.isEnumDeclaration(statement) ||
|
|
283
|
+
ts.isInterfaceDeclaration(statement) ||
|
|
284
|
+
ts.isTypeAliasDeclaration(statement)) &&
|
|
285
|
+
statement.name)
|
|
286
|
+
names.push(statement.name.text);
|
|
287
|
+
}
|
|
288
|
+
return names;
|
|
289
|
+
}
|
|
290
|
+
// Moving `statements` out into the scope of `container` must not shadow or clash with any name used
|
|
291
|
+
// there outside `moved`. Function declarations hoist differently in blocks, so they never move.
|
|
292
|
+
function canHoist(statements, container, moved) {
|
|
293
|
+
if (statements.some((statement) => ts.isFunctionDeclaration(statement) || ts.isLabeledStatement(statement)))
|
|
294
|
+
return false;
|
|
295
|
+
const names = blockScopedNames(statements);
|
|
296
|
+
if (!names.length)
|
|
297
|
+
return true;
|
|
298
|
+
const outside = new Set();
|
|
299
|
+
(function collect(node) {
|
|
300
|
+
if (node === moved)
|
|
301
|
+
return;
|
|
302
|
+
if (ts.isIdentifier(node))
|
|
303
|
+
outside.add(node.text);
|
|
304
|
+
ts.forEachChild(node, collect);
|
|
305
|
+
})(container);
|
|
306
|
+
return names.every((name) => !outside.has(name));
|
|
307
|
+
}
|
|
308
|
+
export { ts, ancestor, functionWithBody, hasBlockBody, flaggedFunction, lineStart, lineEnd, nextLineStart, indentationAt, newlineOf, blank, nameUsed, ownsLines, hasComments, hasMultilineLiteral, dedentLines, blockBody, logicalOperand, singleLine, negateCondition, clauseCount, readableCondition, canHoist, };
|