loadwise 0.8.0 → 0.10.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/PERFORMANCE.md +17 -0
- package/README.md +294 -700
- package/agent/hooks/check-edited-file.mjs +800 -0
- package/dist/bin/github-action.js +72 -18
- package/dist/bin/loadwise.js +21 -34
- package/dist/lib/accessibility/angular-literal.js +1 -1
- package/dist/lib/accessibility/aria-tables.js +10 -6
- package/dist/lib/accessibility/astro-template.js +111 -0
- package/dist/lib/accessibility/autofocus.js +94 -0
- package/dist/lib/accessibility/document-reference-rules.js +143 -0
- package/dist/lib/accessibility/form-context.js +7 -2
- package/dist/lib/accessibility/frontend-detect.js +18 -8
- package/dist/lib/accessibility/heading-order.js +59 -0
- package/dist/lib/accessibility/interaction-semantics.js +90 -0
- package/dist/lib/accessibility/jinja-template.js +150 -0
- package/dist/lib/accessibility/jsx-elements.js +164 -21
- package/dist/lib/accessibility/language-tags.js +18 -0
- package/dist/lib/accessibility/markup-files.js +44 -17
- package/dist/lib/accessibility/markup.js +4 -1
- package/dist/lib/accessibility/media-rules.js +81 -0
- package/dist/lib/accessibility/native-interactive.js +145 -0
- package/dist/lib/accessibility/rule-ids.js +30 -0
- package/dist/lib/accessibility/rule-utilities.js +92 -0
- package/dist/lib/accessibility/rules.js +77 -140
- package/dist/lib/accessibility/site-fixes/aria-typo.js +65 -0
- package/dist/lib/accessibility/site-fixes/buttons.js +4 -11
- package/dist/lib/accessibility/site-fixes/email-autocomplete.js +103 -0
- package/dist/lib/accessibility/site-fixes/html-language.js +84 -0
- package/dist/lib/accessibility/site-fixes/media-autoplay.js +87 -0
- package/dist/lib/accessibility/site-fixes/positive-tabindex.js +102 -0
- package/dist/lib/accessibility/site-fixes/source-position.js +11 -0
- package/dist/lib/accessibility/site-fixes/viewport.js +107 -0
- package/dist/lib/accessibility/table-headers.js +70 -0
- package/dist/lib/accessibility/template-attributes.js +13 -2
- package/dist/lib/accessibility/template-binding-scope.js +122 -0
- package/dist/lib/accessibility/template-elements.js +259 -109
- package/dist/lib/accessibility/template-file.js +111 -22
- package/dist/lib/accessibility/template-tag-tables.js +86 -0
- package/dist/lib/accessibility/usage.js +1 -1
- package/dist/lib/editor/accessibility-examples.js +5 -0
- package/dist/lib/editor/actions.js +26 -14
- package/dist/lib/editor/apply-fix.js +30 -2
- package/dist/lib/editor/configured-setup.js +9 -14
- package/dist/lib/editor/diagnostics.js +121 -135
- package/dist/lib/editor/dismissals.js +21 -10
- package/dist/lib/editor/doctor.js +167 -0
- package/dist/lib/editor/editor-document.js +17 -1
- package/dist/lib/editor/editor-launcher.js +60 -26
- package/dist/lib/editor/finding-comparison.js +4 -25
- package/dist/lib/editor/fix-edits.js +87 -8
- package/dist/lib/editor/hover-markdown.js +104 -0
- package/dist/lib/editor/inline-fix.js +50 -0
- package/dist/lib/editor/inline-recommendation.js +27 -0
- package/dist/lib/editor/jetbrains-setup.js +2 -1
- package/dist/lib/editor/language-server.js +305 -56
- package/dist/lib/editor/native-setup.js +7 -2
- package/dist/lib/editor/perf-watch.js +7 -5
- package/dist/lib/editor/performance-examples.js +31 -0
- package/dist/lib/editor/polyglot-selection.js +193 -0
- package/dist/lib/editor/project-policy.js +146 -0
- package/dist/lib/editor/project-watches.js +86 -0
- package/dist/lib/editor/release-vsix.js +23 -1
- package/dist/lib/editor/reliability-examples.js +36 -0
- package/dist/lib/editor/scan-session.js +212 -62
- package/dist/lib/editor/security-examples.js +24 -14
- package/dist/lib/editor/server-commands.js +24 -11
- package/dist/lib/editor/setup.js +7 -12
- package/dist/lib/editor/standalone-performance-examples.js +51 -0
- package/dist/lib/editor/workspace-files.js +32 -8
- package/dist/lib/editor/workspace-paths.js +29 -7
- package/dist/lib/editor/zed-settings.js +118 -0
- package/dist/lib/editor/zed-setup.js +88 -0
- package/dist/lib/maintainability/analysis/analyze-source.js +8 -3
- package/dist/lib/maintainability/analysis/source-exclusions.js +2 -1
- package/dist/lib/maintainability/analysis/source-facts.js +2 -2
- package/dist/lib/maintainability/architecture/architecture.js +50 -2
- package/dist/lib/maintainability/architecture/graph.js +2 -1
- package/dist/lib/maintainability/architecture/layout.js +2 -1
- package/dist/lib/maintainability/cli/apply-fix.js +32 -7
- package/dist/lib/maintainability/cli/changed-lines.js +7 -113
- package/dist/lib/maintainability/cli/finding-ids.js +3 -6
- package/dist/lib/maintainability/cli/fix-cli.js +1 -9
- package/dist/lib/maintainability/cli/git-inventory.js +5 -6
- package/dist/lib/maintainability/cli/inputs.js +24 -16
- package/dist/lib/maintainability/cli/scan-arguments.js +33 -0
- package/dist/lib/maintainability/cli/site-fix.js +31 -13
- package/dist/lib/maintainability/cli.js +31 -38
- package/dist/lib/maintainability/entry-points/entry-points.js +27 -68
- package/dist/lib/maintainability/examples.js +60 -0
- package/dist/lib/maintainability/polyglot-duplicates.js +1 -0
- package/dist/lib/maintainability/polyglot.js +337 -12
- package/dist/lib/maintainability/project.js +4 -4
- package/dist/lib/maintainability/quality/console-tooling.js +114 -0
- package/dist/lib/maintainability/quality/declarative-imports.js +18 -0
- package/dist/lib/maintainability/quality/deprecated-apis.js +227 -40
- package/dist/lib/maintainability/quality/duplicates.js +5 -11
- package/dist/lib/maintainability/quality/generic-assertion-target.js +75 -0
- package/dist/lib/maintainability/quality/limits.js +5 -1
- package/dist/lib/maintainability/quality/modern-node-callbacks.js +188 -0
- package/dist/lib/maintainability/quality/modern-syntax.js +301 -0
- package/dist/lib/maintainability/quality/size-limits.js +2 -1
- package/dist/lib/maintainability/quality/stray-console.js +31 -7
- package/dist/lib/maintainability/quality/tsconfig-strict.js +432 -21
- package/dist/lib/maintainability/quality/type-escape-hatches.js +411 -0
- package/dist/lib/maintainability/quality/type-safety-hygiene.js +132 -42
- package/dist/lib/maintainability/quality/unowned-source.js +15 -0
- package/dist/lib/maintainability/rule-ids.js +27 -0
- package/dist/lib/maintainability/scan-changed.js +39 -3
- package/dist/lib/maintainability/scan-worker.js +3 -5
- package/dist/lib/maintainability/scan.js +26 -4
- package/dist/lib/maintainability/site-fixes/duplicate-edits.js +3 -2
- package/dist/lib/maintainability/site-fixes/duplicate-methods.js +7 -2
- package/dist/lib/maintainability/site-fixes/duplicates.js +3 -2
- package/dist/lib/maintainability/site-fixes/focused-test.js +230 -0
- package/dist/lib/maintainability/site-fixes/helpers.js +2 -6
- package/dist/lib/maintainability/site-fixes/if-rewrites.js +1 -7
- package/dist/lib/maintainability/site-fixes/large-module.js +2 -1
- package/dist/lib/maintainability/site-fixes/unused-bindings.js +15 -6
- package/dist/lib/maintainability/unused/ancestor-aliases.js +2 -2
- package/dist/lib/maintainability/unused/module-usage-dynamic.js +2 -1
- package/dist/lib/maintainability/unused/module-usage-named-exports.js +125 -0
- package/dist/lib/maintainability/unused/module-usage-signatures.js +116 -0
- package/dist/lib/maintainability/unused/module-usage.js +75 -109
- package/dist/lib/maintainability/unused/unused-bindings.js +143 -8
- package/dist/lib/maintainability/unused/unused-dependencies.js +218 -0
- package/dist/lib/maintainability/unused/unused-modules.js +39 -1
- package/dist/lib/performance/analysis/call-syntax.js +2 -1
- package/dist/lib/performance/analysis/function-kinds.js +1 -5
- package/dist/lib/performance/analysis/missing-packages.js +13 -7
- package/dist/lib/performance/analysis/package-types.js +10 -2
- package/dist/lib/performance/analysis/schema-tooling.js +157 -8
- package/dist/lib/performance/analysis/source-inputs.js +17 -12
- package/dist/lib/performance/analysis/source-text.js +2 -2
- package/dist/lib/performance/analysis/unscanned-javascript.js +6 -5
- package/dist/lib/performance/analyze.js +25 -6
- package/dist/lib/performance/async/async-errors.js +162 -14
- package/dist/lib/performance/async/await-before-early-exit.js +1 -6
- package/dist/lib/performance/async/floating-promises.js +27 -6
- package/dist/lib/performance/async/promise-return-escapes-catch.js +35 -2
- package/dist/lib/performance/async/stream-errors.js +1 -3
- package/dist/lib/performance/cli/changed-lines.js +14 -111
- package/dist/lib/performance/cli/cli-arguments.js +11 -9
- package/dist/lib/performance/cli/cli-markup.js +42 -0
- package/dist/lib/performance/cli/cli-output.js +9 -3
- package/dist/lib/performance/cli/cli-policy.js +174 -17
- package/dist/lib/performance/cli/cli-scan.js +170 -139
- package/dist/lib/performance/cli/finding-ids.js +7 -7
- package/dist/lib/performance/cli/fix-cli.js +83 -34
- package/dist/lib/performance/cli/prisma-schema-findings.js +23 -0
- package/dist/lib/performance/cli/scan-outcome.js +19 -1
- package/dist/lib/performance/cli/shared-security-inputs.js +27 -0
- package/dist/lib/performance/cli/watch-security.js +33 -0
- package/dist/lib/performance/cli/watch.js +42 -15
- package/dist/lib/performance/cli.js +8 -7
- package/dist/lib/performance/collections/array-drains.js +354 -0
- package/dist/lib/performance/collections/collection-bindings.js +1 -2
- package/dist/lib/performance/collections/collection-bounds.js +3 -2
- package/dist/lib/performance/collections/collection-copy.js +51 -1
- package/dist/lib/performance/collections/collection-lookups.js +74 -13
- package/dist/lib/performance/collections/collection-reduce.js +32 -6
- package/dist/lib/performance/collections/collections.js +34 -2
- package/dist/lib/performance/collections/json-clone.js +137 -17
- package/dist/lib/performance/collections/regex-allocation.js +156 -0
- package/dist/lib/performance/collections/repeated.js +26 -8
- package/dist/lib/performance/collections/sort-extreme.js +18 -1
- package/dist/lib/performance/collections/workbook-decodes.js +3 -2
- package/dist/lib/performance/contracts/cli.js +340 -21
- package/dist/lib/performance/contracts/git-files.js +102 -5
- package/dist/lib/performance/contracts/openapi-schema.js +187 -0
- package/dist/lib/performance/contracts/openapi-sources.js +260 -0
- package/dist/lib/performance/contracts/openapi.js +172 -233
- package/dist/lib/performance/contracts/protobuf.js +301 -0
- package/dist/lib/performance/contracts/trpc-moves.js +46 -0
- package/dist/lib/performance/contracts/trpc.js +477 -0
- package/dist/lib/performance/datastores/pg-integrity.js +2 -1
- package/dist/lib/performance/datastores/pooling.js +3 -18
- package/dist/lib/performance/datastores/postgres.js +41 -33
- package/dist/lib/performance/datastores/redis-keys.js +4 -3
- package/dist/lib/performance/datastores/redis.js +8 -1
- package/dist/lib/performance/datastores/repeated-reads.js +104 -0
- package/dist/lib/performance/datastores/search-clients.js +9 -0
- package/dist/lib/performance/datastores/session-store.js +166 -7
- package/dist/lib/performance/datastores/supabase.js +73 -0
- package/dist/lib/performance/db/checks.js +1 -1
- package/dist/lib/performance/db/cli-mysql.js +12 -2
- package/dist/lib/performance/db/cli.js +38 -5
- package/dist/lib/performance/db/drivers.js +20 -4
- package/dist/lib/performance/db/measure.js +1 -1
- package/dist/lib/performance/db/mysql-catalog.js +1 -1
- package/dist/lib/performance/db/plan-estimates.js +46 -7
- package/dist/lib/performance/db/redact.js +1 -3
- package/dist/lib/performance/db/snapshot.js +1 -1
- package/dist/lib/performance/db/sqlite-plan.js +95 -0
- package/dist/lib/performance/engine/compiler.js +3 -2
- package/dist/lib/performance/engine/native-checker.js +85 -10
- package/dist/lib/performance/engine/native-syntax.js +17 -0
- package/dist/lib/performance/engine/native-workspaces.js +36 -8
- package/dist/lib/performance/engine/native.js +42 -16
- package/dist/lib/performance/engine/review-config-inputs.js +57 -0
- package/dist/lib/performance/evidence/plans.js +14 -16
- package/dist/lib/performance/evidence/trace-formats.js +182 -0
- package/dist/lib/performance/evidence/traces.js +6 -6
- package/dist/lib/performance/frontend/angular-bootstrap.js +309 -0
- package/dist/lib/performance/frontend/angular-template-calls.js +187 -0
- package/dist/lib/performance/frontend/barrel-subpaths.js +204 -0
- package/dist/lib/performance/frontend/effect-cleanup.js +30 -4
- package/dist/lib/performance/frontend/frontend-dom-perf.js +79 -15
- package/dist/lib/performance/frontend/frontend-perf.js +119 -176
- package/dist/lib/performance/frontend/frontend-render-perf.js +17 -13
- package/dist/lib/performance/frontend/jsx-element-perf.js +171 -0
- package/dist/lib/performance/frontend/layout-binary-probe.js +186 -0
- package/dist/lib/performance/frontend/next-fetch-waterfall.js +405 -0
- package/dist/lib/performance/frontend/rxjs-subscriptions.js +155 -0
- package/dist/lib/performance/frontend/seo/client-fetched-content.js +196 -0
- package/dist/lib/performance/frontend/seo/navigation-without-link.js +116 -0
- package/dist/lib/performance/frontend/seo/next-routes.js +114 -0
- package/dist/lib/performance/frontend/seo/route-metadata.js +158 -0
- package/dist/lib/performance/frontend/seo/seo-rules.js +9 -0
- package/dist/lib/performance/frontend/seo/sitewide-noindex.js +103 -0
- package/dist/lib/performance/frontend/template-tracking.js +215 -0
- package/dist/lib/performance/frontend/vue-options-hooks.js +108 -0
- package/dist/lib/performance/index-rules/index-rules-table.js +3 -3
- package/dist/lib/performance/index-rules/redundant-indexes.js +6 -13
- package/dist/lib/performance/migrations/cli.js +65 -14
- package/dist/lib/performance/migrations/discover.js +63 -32
- package/dist/lib/performance/migrations/enforce.js +5 -12
- package/dist/lib/performance/migrations/extract-code-sql.js +10 -7
- package/dist/lib/performance/migrations/extract-code.js +1 -0
- package/dist/lib/performance/migrations/extract-sql.js +45 -4
- package/dist/lib/performance/migrations/extract-sqlite.js +302 -0
- package/dist/lib/performance/migrations/operations.js +122 -8
- package/dist/lib/performance/migrations/postgres-registry.js +6 -6
- package/dist/lib/performance/migrations/postgres-table-history.js +147 -0
- package/dist/lib/performance/migrations/rules-postgres-shared.js +4 -6
- package/dist/lib/performance/migrations/rules-postgres.js +67 -13
- package/dist/lib/performance/migrations/rules-sqlite.js +118 -0
- package/dist/lib/performance/migrations/sqlserver-creation.js +131 -0
- package/dist/lib/performance/migrations/sqlserver.js +81 -0
- package/dist/lib/performance/models/client-imports.js +286 -0
- package/dist/lib/performance/models/index.js +46 -8
- package/dist/lib/performance/orm/cartesian-includes.js +49 -22
- package/dist/lib/performance/orm/drizzle.js +86 -27
- package/dist/lib/performance/orm/knex-loop-operations.js +96 -0
- package/dist/lib/performance/orm/orm-owners.js +3 -5
- package/dist/lib/performance/orm/orm-queries.js +50 -152
- package/dist/lib/performance/orm/orm-result-uses.js +116 -0
- package/dist/lib/performance/orm/prisma-integrity.js +24 -3
- package/dist/lib/performance/orm/prisma.js +32 -33
- package/dist/lib/performance/orm/typeorm-batch-filter.js +43 -0
- package/dist/lib/performance/orm/typeorm-projection.js +2 -2
- package/dist/lib/performance/orm/typeorm-transaction-loops.js +3 -4
- package/dist/lib/performance/orm/typeorm-updates.js +1 -3
- package/dist/lib/performance/orm/unbounded-list-page-size.js +179 -0
- package/dist/lib/performance/orm/unbounded-list-queries.js +63 -146
- package/dist/lib/performance/polyglot.js +173 -61
- package/dist/lib/performance/probe-caches.js +42 -0
- package/dist/lib/performance/program-batches.js +138 -0
- package/dist/lib/performance/projects.js +86 -89
- package/dist/lib/performance/query-loops/guard-queries.js +2 -1
- package/dist/lib/performance/query-loops/parallel-reads-policy.js +1 -3
- package/dist/lib/performance/query-loops/query-loop-batch.js +81 -7
- package/dist/lib/performance/query-loops/query-loop-bounds.js +1 -13
- package/dist/lib/performance/query-loops/query-policy.js +19 -20
- package/dist/lib/performance/query-loops/query-results.js +1 -6
- package/dist/lib/performance/query-loops/query-write-context.js +89 -0
- package/dist/lib/performance/query-loops/sequential-loops.js +6 -24
- package/dist/lib/performance/query-loops/service-call-resolution.js +17 -2
- package/dist/lib/performance/query-loops/service-loop-source.js +124 -0
- package/dist/lib/performance/query-loops/service-loops.js +86 -25
- package/dist/lib/performance/query-loops/throw-on-miss-loops.js +141 -0
- package/dist/lib/performance/request/backend-mastery.js +18 -30
- package/dist/lib/performance/request/fixed-emitter-loop.js +98 -0
- package/dist/lib/performance/request/fresh-mapped-elements.js +137 -0
- package/dist/lib/performance/request/graphql-list-lookups.js +258 -0
- package/dist/lib/performance/request/http-options-writes.js +2 -8
- package/dist/lib/performance/request/http-timeouts.js +3 -2
- package/dist/lib/performance/request/json-stringify-output.js +217 -0
- package/dist/lib/performance/request/llm-max-tokens.js +27 -8
- package/dist/lib/performance/request/mongoose-lean.js +15 -10
- package/dist/lib/performance/request/node-event-listener-leak.js +190 -35
- package/dist/lib/performance/request/node-fs-context.js +6 -8
- package/dist/lib/performance/request/node-fs.js +4 -6
- package/dist/lib/performance/request/password-hashing.js +4 -3
- package/dist/lib/performance/request/phase5-ast.js +3 -9
- package/dist/lib/performance/request/phase5-rules.js +50 -102
- package/dist/lib/performance/request/promise-schedulers.js +180 -0
- package/dist/lib/performance/request/pure-js-hashing.js +2 -1
- package/dist/lib/performance/request/request-handlers.js +44 -7
- package/dist/lib/performance/request/request-inputs.js +121 -26
- package/dist/lib/performance/request/unbounded-promise-all.js +142 -52
- package/dist/lib/performance/rule-ids.js +72 -5
- package/dist/lib/performance/schema/context.js +7 -16
- package/dist/lib/performance/schema/model.js +1 -9
- package/dist/lib/performance/schema/prisma-owners.js +15 -1
- package/dist/lib/performance/schema/prisma-schema.js +5 -6
- package/dist/lib/performance/schema/project-indexes-events.js +8 -2
- package/dist/lib/performance/schema/project-indexes.js +4 -2
- package/dist/lib/performance/schema/query-site-support.js +1 -1
- package/dist/lib/performance/schema/sequelize-schema.js +1 -3
- package/dist/lib/performance/schema/ts-helpers.js +3 -7
- package/dist/lib/performance/shared-libs.js +48 -0
- package/dist/lib/performance/site-fix.js +33 -7
- package/dist/lib/performance/site-fixes/collection-copy.js +2 -1
- package/dist/lib/performance/site-fixes/collection-existence.js +2 -1
- package/dist/lib/performance/site-fixes/collection-find.js +2 -1
- package/dist/lib/performance/site-fixes/collection-helpers.js +0 -6
- package/dist/lib/performance/site-fixes/collection-lookups.js +2 -1
- package/dist/lib/performance/site-fixes/database.js +7 -16
- package/dist/lib/performance/site-fixes/drizzle-index.js +2 -9
- package/dist/lib/performance/site-fixes/frontend-fixes.js +47 -15
- package/dist/lib/performance/site-fixes/helpers.js +19 -18
- package/dist/lib/performance/site-fixes/last-insert-id.js +2 -1
- package/dist/lib/performance/site-fixes/llm-max-tokens.js +56 -0
- package/dist/lib/performance/site-fixes/migration-column-rules.js +11 -7
- package/dist/lib/performance/site-fixes/migration-lock-rules.js +6 -3
- package/dist/lib/performance/site-fixes/migrations.js +4 -0
- package/dist/lib/performance/site-fixes/pure-js-hashing.js +2 -2
- package/dist/lib/performance/site-fixes/query-shapes.js +1 -4
- package/dist/lib/performance/site-fixes/service-loop-ast.js +1 -9
- package/dist/lib/performance/site-fixes/small-rewrites.js +28 -2
- package/dist/lib/performance/site-fixes/template-tracking-fixes.js +82 -0
- package/dist/lib/performance/site-fixes/writes.js +1 -6
- package/dist/lib/performance/sql/local-statements.js +108 -0
- package/dist/lib/performance/sql/mysql-tokens.js +1 -4
- package/dist/lib/performance/sql/pg-parser.js +3 -5
- package/dist/lib/performance/sql/sqlserver-control.js +43 -0
- package/dist/lib/reliability/analyze.js +48 -5
- package/dist/lib/reliability/boundary-access.js +34 -27
- package/dist/lib/reliability/callback-completion.js +10 -2
- package/dist/lib/reliability/child-process.js +2 -2
- package/dist/lib/reliability/crlf-line-split.js +124 -73
- package/dist/lib/reliability/crlf-references.js +78 -0
- package/dist/lib/reliability/default-numeric-sort.js +25 -0
- package/dist/lib/reliability/error-cause-plan.js +29 -0
- package/dist/lib/reliability/error-values.js +68 -27
- package/dist/lib/reliability/json-cast.js +368 -0
- package/dist/lib/reliability/key-test-callee.js +50 -0
- package/dist/lib/reliability/lossy-text-rewrite.js +94 -0
- package/dist/lib/reliability/manifest-boundary.js +466 -0
- package/dist/lib/reliability/manifest-snapshot.js +40 -0
- package/dist/lib/reliability/parse-failure-flow.js +5 -2
- package/dist/lib/reliability/parse-failure-paths.js +39 -8
- package/dist/lib/reliability/parse-failure-reset.js +5 -17
- package/dist/lib/reliability/pool-timeout.js +31 -7
- package/dist/lib/reliability/promise-usage.js +281 -0
- package/dist/lib/reliability/react-bugs.js +16 -6
- package/dist/lib/reliability/react-state-aliases.js +94 -4
- package/dist/lib/reliability/react-state-order.js +2 -2
- package/dist/lib/reliability/react-state-paths.js +2 -2
- package/dist/lib/reliability/react-state-setter.js +5 -11
- package/dist/lib/reliability/react-state-walker.js +3 -3
- package/dist/lib/reliability/react-state.js +24 -5
- package/dist/lib/reliability/required-member.js +19 -0
- package/dist/lib/reliability/resource-leak-intervals.js +4 -7
- package/dist/lib/reliability/resource-leaks.js +4 -7
- package/dist/lib/reliability/rule-ids.js +70 -1
- package/dist/lib/reliability/same-file-io.js +135 -0
- package/dist/lib/reliability/short-write.js +220 -0
- package/dist/lib/reliability/site-fixes/crlf-line-split.js +71 -0
- package/dist/lib/reliability/site-fixes/error-values.js +40 -0
- package/dist/lib/reliability/site-fixes/pool-timeout.js +51 -0
- package/dist/lib/reliability/source-helpers.js +18 -8
- package/dist/lib/reliability/standalone-sources.js +8 -6
- package/dist/lib/reliability/suspicious-logic.js +6 -8
- package/dist/lib/reliability/swallowed-errors.js +3 -7
- package/dist/lib/reliability/switch-exhaustive.js +195 -5
- package/dist/lib/reliability/test-cleanup-after-await.js +2 -2
- package/dist/lib/reliability/throw-string-plan.js +121 -0
- package/dist/lib/reliability/uncaught-exception.js +2 -7
- package/dist/lib/reliability/usage.js +1 -1
- package/dist/lib/reliability/working-directory.js +101 -0
- package/dist/lib/security/analyze.js +2 -0
- package/dist/lib/security/auth-crypto/hashing.js +21 -4
- package/dist/lib/security/auth-crypto/index.js +6 -1
- package/dist/lib/security/auth-crypto/jwt-decode-helpers.js +163 -0
- package/dist/lib/security/auth-crypto/jwt.js +52 -36
- package/dist/lib/security/auth-crypto/plaintext-password.js +2 -1
- package/dist/lib/security/auth-crypto/random.js +2 -1
- package/dist/lib/security/auth-crypto/rate-limits.js +79 -8
- package/dist/lib/security/auth-crypto/rule-ids.js +2 -0
- package/dist/lib/security/auth-crypto/secrets.js +132 -19
- package/dist/lib/security/auth-crypto/shared.js +1 -4
- package/dist/lib/security/auth-crypto/signature-verification.js +29 -0
- package/dist/lib/security/auth-crypto/transport-and-ciphers.js +43 -3
- package/dist/lib/security/auth-crypto/weak-hash.js +183 -0
- package/dist/lib/security/bindings.js +41 -9
- package/dist/lib/security/cli.js +84 -27
- package/dist/lib/security/cookie-csrf.js +316 -7
- package/dist/lib/security/credential-entropy.js +12 -0
- package/dist/lib/security/deps/cargo-lock.js +78 -0
- package/dist/lib/security/deps/cli.js +4 -4
- package/dist/lib/security/deps/fixed-version.js +2 -2
- package/dist/lib/security/deps/lockfiles.js +207 -17
- package/dist/lib/security/deps/osv.js +190 -59
- package/dist/lib/security/deps/scan.js +87 -19
- package/dist/lib/security/examples/{auth-crypto.cjs → auth-crypto.js} +11 -5
- package/dist/lib/security/examples/{deps.cjs → deps.js} +1 -3
- package/dist/lib/security/examples/{exposure.cjs → exposure.js} +17 -3
- package/dist/lib/security/examples/files.js +146 -0
- package/dist/lib/security/examples/{injection.cjs → injection.js} +13 -3
- package/dist/lib/security/examples/{moved.cjs → moved.js} +1 -3
- package/dist/lib/security/examples/{request-forgery.cjs → request-forgery.js} +2 -4
- package/dist/lib/security/exposure/backend-security-mastery.js +2 -1
- package/dist/lib/security/exposure/client-env.js +2 -1
- package/dist/lib/security/exposure/content-disposition.js +71 -0
- package/dist/lib/security/exposure/cookies.js +200 -1
- package/dist/lib/security/exposure/cors.js +63 -4
- package/dist/lib/security/exposure/frontend-security.js +18 -62
- package/dist/lib/security/exposure/index.js +9 -0
- package/dist/lib/security/exposure/js-yaml.js +203 -0
- package/dist/lib/security/exposure/message-effects.js +266 -0
- package/dist/lib/security/exposure/package-manifest.js +2 -2
- package/dist/lib/security/exposure/prototype-pollution.js +99 -5
- package/dist/lib/security/exposure/reflected-xss.js +47 -12
- package/dist/lib/security/exposure/response-content-type.js +181 -0
- package/dist/lib/security/exposure/rule-ids.js +4 -0
- package/dist/lib/security/exposure/trust-boundary.js +142 -0
- package/dist/lib/security/exposure/url-secrets.js +38 -2
- package/dist/lib/security/exposure/webhook-verification.js +231 -0
- package/dist/lib/security/express-registration.js +45 -0
- package/dist/lib/security/express-router-factories.js +118 -0
- package/dist/lib/security/files/azure-pipelines.js +69 -0
- package/dist/lib/security/files/bitbucket-pipelines.js +32 -0
- package/dist/lib/security/files/ci-platforms.js +16 -0
- package/dist/lib/security/files/ci-shared.js +260 -0
- package/dist/lib/security/files/circleci.js +81 -0
- package/dist/lib/security/files/component-markup.js +66 -0
- package/dist/lib/security/files/compose.js +2 -1
- package/dist/lib/security/files/dockerfile.js +188 -3
- package/dist/lib/security/files/github-actions.js +490 -0
- package/dist/lib/security/files/gitlab-ci.js +90 -0
- package/dist/lib/security/files/hcl.js +264 -0
- package/dist/lib/security/files/hosting-config.js +159 -0
- package/dist/lib/security/files/http-headers.js +65 -0
- package/dist/lib/security/files/index.js +182 -33
- package/dist/lib/security/files/jenkinsfile.js +482 -0
- package/dist/lib/security/files/json-nodes.js +67 -0
- package/dist/lib/security/files/kubernetes.js +136 -0
- package/dist/lib/security/files/nginx.js +501 -0
- package/dist/lib/security/files/package-scripts.js +175 -0
- package/dist/lib/security/files/project-files.js +98 -31
- package/dist/lib/security/files/rule-ids.js +31 -0
- package/dist/lib/security/files/secret-values.js +31 -5
- package/dist/lib/security/files/secrets.js +53 -18
- package/dist/lib/security/files/terraform.js +345 -0
- package/dist/lib/security/injection/code.js +33 -5
- package/dist/lib/security/injection/command.js +51 -4
- package/dist/lib/security/injection/escape-preserving.js +219 -0
- package/dist/lib/security/injection/escape-replace.js +174 -2
- package/dist/lib/security/injection/index.js +5 -1
- package/dist/lib/security/injection/nosql.js +3 -2
- package/dist/lib/security/injection/redos.js +25 -4
- package/dist/lib/security/injection/rule-ids.js +3 -0
- package/dist/lib/security/injection/shell-output-guard.js +97 -0
- package/dist/lib/security/injection/sql.js +53 -2
- package/dist/lib/security/injection/xpath.js +35 -0
- package/dist/lib/security/lexical-declaration.js +28 -0
- package/dist/lib/security/pg-identifier-guards.js +146 -5
- package/dist/lib/security/phase5-rules.js +1 -0
- package/dist/lib/security/polyglot.js +35 -3
- package/dist/lib/security/provider-credentials.js +29 -0
- package/dist/lib/security/redirect-settings.js +131 -6
- package/dist/lib/security/request-forgery/contained-helper.js +75 -0
- package/dist/lib/security/request-forgery/member-chain.js +41 -0
- package/dist/lib/security/request-forgery/open-redirect-query.js +2 -1
- package/dist/lib/security/request-forgery/open-redirect.js +69 -9
- package/dist/lib/security/request-forgery/parsed-host-guard.js +213 -0
- package/dist/lib/security/request-forgery/path-traversal.js +36 -1
- package/dist/lib/security/request-forgery/shared.js +205 -30
- package/dist/lib/security/request-forgery/ssrf.js +145 -1
- package/dist/lib/security/rule-descriptions.js +46 -1
- package/dist/lib/security/rule-ids.js +50 -0
- package/dist/lib/security/scope/drizzle-policy.js +2 -1
- package/dist/lib/security/scope/kysely-policy.js +173 -0
- package/dist/lib/security/site-fixes/auth-crypto.js +3 -1
- package/dist/lib/security/taint/accessors.js +364 -0
- package/dist/lib/security/taint/array-writes.js +139 -0
- package/dist/lib/security/taint/binding-inputs.js +4 -3
- package/dist/lib/security/taint/field-access.js +80 -0
- package/dist/lib/security/taint/filename-guard.js +81 -6
- package/dist/lib/security/taint/guards.js +150 -17
- package/dist/lib/security/taint/index.js +41 -116
- package/dist/lib/security/taint/original-string-validation.js +229 -0
- package/dist/lib/security/taint/propagate.js +5 -6
- package/dist/lib/security/taint/resolution-cache.js +10 -1
- package/dist/lib/security/taint/sanitizers.js +5 -5
- package/dist/lib/security/taint/shape-flows.js +128 -0
- package/dist/lib/security/taint/sink-alphabets.js +237 -0
- package/dist/lib/security/taint/sources.js +151 -8
- package/dist/lib/security/taint/trace-nodes.js +35 -2
- package/dist/lib/security/taint/validators.js +59 -20
- package/dist/lib/security/trusted-bindings.js +44 -0
- package/dist/lib/shared/agent/agent-init.js +84 -9
- package/dist/lib/shared/agent/agent-integrations.js +626 -0
- package/dist/lib/shared/agent/agent-prompt.js +2 -1
- package/dist/lib/shared/agent/agent-session.js +1 -1
- package/dist/lib/shared/agent/agent-toml.js +98 -0
- package/dist/lib/shared/agent/agent-verify.js +21 -3
- package/dist/lib/shared/agent/git-hook.js +31 -4
- package/dist/lib/shared/agent/notify-editor.js +2 -1
- package/dist/lib/shared/agent/review-delivery.js +3 -1
- package/dist/lib/shared/agent/review-mcp.js +67 -13
- package/dist/lib/shared/agent/review-request.js +4 -0
- package/dist/lib/shared/analysis/ast-helpers.js +50 -0
- package/dist/lib/shared/analysis/ast-semantics.js +23 -1
- package/dist/lib/shared/analysis/binding-names.js +13 -0
- package/dist/lib/shared/analysis/execution-context.js +49 -9
- package/dist/lib/shared/analysis/hot-path-graph.js +55 -19
- package/dist/lib/shared/analysis/next-env-config.js +232 -0
- package/dist/lib/shared/analysis/polyglot-compatibility.js +102 -23
- package/dist/lib/shared/analysis/scan-cache-git.js +114 -0
- package/dist/lib/shared/analysis/scan-cache-loadwise-packages.js +54 -0
- package/dist/lib/shared/analysis/scan-cache-project-inputs.js +221 -0
- package/dist/lib/shared/analysis/scan-cache-sources.js +235 -0
- package/dist/lib/shared/analysis/scan-cache-storage.js +204 -0
- package/dist/lib/shared/analysis/scan-cache.js +373 -166
- package/dist/lib/shared/analysis/valid-javascript.js +118 -0
- package/dist/lib/shared/changed-lines.js +129 -0
- package/dist/lib/shared/check-options.js +63 -0
- package/dist/lib/shared/check-watch-inputs.js +152 -0
- package/dist/lib/shared/check-watch-process.js +57 -0
- package/dist/lib/shared/check-watch.js +136 -0
- package/dist/lib/shared/check.js +97 -40
- package/dist/lib/shared/completion-shells.js +127 -0
- package/dist/lib/shared/completion.js +124 -0
- package/dist/lib/shared/config-rule-validation.js +135 -0
- package/dist/lib/shared/config.js +330 -163
- package/dist/lib/shared/conventional-projects.js +40 -0
- package/dist/lib/shared/declarative-rule-packs.js +173 -0
- package/dist/lib/shared/explain.js +47 -9
- package/dist/lib/shared/fix/fix-command.js +2 -0
- package/dist/lib/shared/fix/fix-convergence.js +45 -128
- package/dist/lib/shared/fix/fix-history.js +130 -26
- package/dist/lib/shared/fix/fix-interactive.js +78 -0
- package/dist/lib/shared/fix/fix-patch.js +89 -0
- package/dist/lib/shared/fix/fix-polyglot-preview.js +166 -0
- package/dist/lib/shared/fix/fix-presentation-biome.js +120 -0
- package/dist/lib/shared/fix/fix-presentation-prettier.js +27 -10
- package/dist/lib/shared/fix/fix-presentation-rows.js +5 -1
- package/dist/lib/shared/fix/fix-presentation.js +22 -15
- package/dist/lib/shared/fix/fix-project-membership.js +79 -0
- package/dist/lib/shared/fix/fix-reversal-proof.js +107 -0
- package/dist/lib/shared/fix/fix-reverse.js +37 -0
- package/dist/lib/shared/fix/fix-safety.js +4 -4
- package/dist/lib/shared/fix/fix-scope.js +13 -9
- package/dist/lib/shared/fix/fix-source-snapshot.js +92 -0
- package/dist/lib/shared/fix/fix-staging.js +129 -0
- package/dist/lib/shared/fix/fix-terminal.js +34 -9
- package/dist/lib/shared/fix/fix-typecheck.js +21 -8
- package/dist/lib/shared/fix/fix-usage.js +47 -0
- package/dist/lib/shared/fix/project-file-access.js +85 -29
- package/dist/lib/shared/fix/read-fix-text.js +23 -0
- package/dist/lib/shared/fix/reversal-lock.js +37 -0
- package/dist/lib/shared/fix/review-fix-mode.js +9 -0
- package/dist/lib/shared/fix.js +157 -52
- package/dist/lib/shared/formats/ci-consumers.js +84 -0
- package/dist/lib/shared/formats/finding-location.js +52 -3
- package/dist/lib/shared/formats/github.js +22 -7
- package/dist/lib/shared/formats/index.js +21 -5
- package/dist/lib/shared/formats/readable.js +63 -0
- package/dist/lib/shared/formats/report-rows.js +38 -0
- package/dist/lib/shared/formats/sarif-fixes.js +261 -0
- package/dist/lib/shared/formats/sarif.js +175 -33
- package/dist/lib/shared/formats/security-cwe.js +142 -0
- package/dist/lib/shared/node-scan.js +64 -0
- package/dist/lib/shared/package-root.js +2 -0
- package/dist/lib/shared/project-root.js +27 -1
- package/dist/lib/shared/reporting/action-comparison.js +78 -0
- package/dist/lib/shared/reporting/action-summary.js +31 -0
- package/dist/lib/shared/reporting/automatic-fix-signal.js +7 -2
- package/dist/lib/shared/reporting/baseline.js +12 -12
- package/dist/lib/shared/reporting/check-text.js +7 -5
- package/dist/lib/shared/reporting/finding-id-hash.js +7 -0
- package/dist/lib/shared/reporting/impact-levels.js +1 -1
- package/dist/lib/shared/reporting/pillar-rules.js +13 -1
- package/dist/lib/shared/reporting/pillars.js +61 -23
- package/dist/lib/shared/reporting/rule-docs.js +2 -2
- package/dist/lib/shared/reporting/rule-pack-fingerprint.js +21 -0
- package/dist/lib/shared/reporting/source-report.js +20 -6
- package/dist/lib/shared/reporting/stray-console-methods.js +1 -0
- package/dist/lib/shared/rule-registry.js +6 -1
- package/dist/lib/shared/system/atomic-write.js +12 -6
- package/dist/lib/shared/system/component-source.js +28 -0
- package/dist/lib/shared/system/environment.js +12 -0
- package/dist/lib/shared/system/file-key.js +8 -0
- package/dist/lib/shared/system/git.js +62 -0
- package/dist/lib/shared/system/glob.js +233 -28
- package/dist/lib/shared/system/jsonc-config.js +63 -0
- package/dist/lib/shared/system/path-inside.js +19 -0
- package/dist/lib/shared/system/posix-path.js +22 -0
- package/dist/lib/shared/system/read-json.js +10 -0
- package/dist/lib/shared/system/sentry.js +6 -3
- package/dist/lib/shared/system/terminal-style.js +2 -2
- package/dist/lib/shared/system/text-helpers.js +40 -0
- package/dist/lib/shared/system/windows-orphans-script.js +75 -0
- package/dist/lib/shared/system/windows-orphans.js +28 -0
- package/dist/lib/shared/types/changed-lines.js +1 -0
- package/dist/lib/shared/types/completion.js +1 -0
- package/dist/lib/shared/workspace-selection.js +67 -0
- package/dist/lib/shared/workspaces.js +215 -68
- package/dist/polyglot/maintainability/rules.js +119 -3
- package/examples/README.md +45 -0
- package/examples/clean/avatar.html +1 -0
- package/examples/clean/source.ts +10 -0
- package/examples/clean/tsconfig.json +4 -0
- package/examples/findings/avatar.html +1 -0
- package/examples/findings/source.ts +11 -0
- package/examples/findings/tsconfig.json +4 -0
- package/examples/labels-clean.py +5 -0
- package/integrations/zed/Cargo.lock +1 -1
- package/integrations/zed/Cargo.toml +1 -1
- package/integrations/zed/LICENSE +201 -0
- package/integrations/zed/extension.toml +3 -3
- package/integrations/zed/extension.wasm +0 -0
- package/integrations/zed/src/lib.rs +108 -8
- package/package.json +28 -14
- package/polyglot/performance/rules/csharp.yml +173 -10
- package/polyglot/performance/rules/go.yml +15 -7
- package/polyglot/performance/rules/input.yml +12 -0
- package/polyglot/performance/rules/java.yml +52 -1
- package/polyglot/performance/rules/php.yml +146 -0
- package/polyglot/performance/rules/python.yml +7 -3
- package/polyglot/performance/rules/ruby.yml +81 -0
- package/polyglot/performance/sgconfig.yml +2 -0
- package/polyglot/reliability/rules/csharp.yml +105 -0
- package/polyglot/reliability/rules/go.yml +339 -0
- package/polyglot/reliability/rules/input.yml +6 -0
- package/polyglot/reliability/rules/java.yml +218 -0
- package/polyglot/reliability/rules/kotlin.yml +49 -0
- package/polyglot/reliability/rules/python.yml +288 -0
- package/polyglot/reliability/rules/rust.yml +83 -0
- package/polyglot/reliability/sgconfig.yml +1 -0
- package/polyglot/security/rules/csharp.yml +143 -3
- package/polyglot/security/rules/go.yml +59 -4
- package/polyglot/security/rules/java.yml +103 -0
- package/polyglot/security/rules/python.yml +413 -21
- package/polyglot/security/rules/rust.yml +176 -3
- package/polyglot/security/sgconfig.yml +2 -0
- package/polyglot/security/utils/java-imported-jca-cipher.yml +32 -0
- package/polyglot/security/utils/java-unshadowed-javax.yml +29 -0
- package/schema/loadwise.config.schema.json +1137 -600
- package/schema/loadwise.outcomes.schema.json +43 -0
- package/types/scan.d.ts +53 -0
- package/dist/lib/maintainability/site-fixes/exports.js +0 -25
- package/dist/lib/security/examples/files.cjs +0 -30
- package/docs/assets/cli-workflow.gif +0 -0
- package/plugin/.claude-plugin/plugin.json +0 -9
- package/plugin/commands/loadwise.md +0 -29
- package/plugin/hooks/check-edited-file.mjs +0 -173
- package/plugin/hooks/hooks.json +0 -17
- /package/dist/lib/{maintainability/types/changed-lines.js → editor/types/workspace-fix.js} +0 -0
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { walkNodes } from '../analysis/walk.js';
|
|
3
|
+
import { originalProgram } from '../site-fixes/isolated-program.js';
|
|
4
|
+
import { importedMember, staticMemberName, unwrapExpression } from '../../shared/analysis/ast-semantics.js';
|
|
5
|
+
import { bindingNames } from '../unused/module-usage-dynamic.js';
|
|
6
|
+
// Callback APIs with a promise form, keyed by module. `fs.exists` is left to deprecated-node-api.
|
|
7
|
+
// child_process `exec`/`execFile` are left out: callers often use the callback to read output of a
|
|
8
|
+
// failed command, which the promisified form only gives through the rejection.
|
|
9
|
+
const callbackMembers = new Map([
|
|
10
|
+
[
|
|
11
|
+
'fs',
|
|
12
|
+
new Set([
|
|
13
|
+
'access',
|
|
14
|
+
'appendFile',
|
|
15
|
+
'chmod',
|
|
16
|
+
'chown',
|
|
17
|
+
'copyFile',
|
|
18
|
+
'cp',
|
|
19
|
+
'lstat',
|
|
20
|
+
'mkdir',
|
|
21
|
+
'mkdtemp',
|
|
22
|
+
'readFile',
|
|
23
|
+
'readdir',
|
|
24
|
+
'readlink',
|
|
25
|
+
'realpath',
|
|
26
|
+
'rename',
|
|
27
|
+
'rm',
|
|
28
|
+
'rmdir',
|
|
29
|
+
'stat',
|
|
30
|
+
'symlink',
|
|
31
|
+
'truncate',
|
|
32
|
+
'unlink',
|
|
33
|
+
'utimes',
|
|
34
|
+
'writeFile',
|
|
35
|
+
]),
|
|
36
|
+
],
|
|
37
|
+
[
|
|
38
|
+
'dns',
|
|
39
|
+
new Set([
|
|
40
|
+
'lookup',
|
|
41
|
+
'resolve',
|
|
42
|
+
'resolve4',
|
|
43
|
+
'resolve6',
|
|
44
|
+
'resolveCname',
|
|
45
|
+
'resolveMx',
|
|
46
|
+
'resolveNs',
|
|
47
|
+
'resolveSrv',
|
|
48
|
+
'resolveTxt',
|
|
49
|
+
'reverse',
|
|
50
|
+
]),
|
|
51
|
+
],
|
|
52
|
+
['crypto', new Set(['generateKeyPair', 'pbkdf2', 'randomBytes', 'scrypt'])],
|
|
53
|
+
[
|
|
54
|
+
'zlib',
|
|
55
|
+
new Set(['brotliCompress', 'brotliDecompress', 'deflate', 'deflateRaw', 'gunzip', 'gzip', 'inflate', 'unzip']),
|
|
56
|
+
],
|
|
57
|
+
]);
|
|
58
|
+
const promiseModuleFor = { fs: 'node:fs/promises', dns: 'node:dns/promises' };
|
|
59
|
+
// A file that names none of the modules as a string cannot import them.
|
|
60
|
+
const WATCHED_MODULE_LITERAL = /['"`](?:node:)?(?:fs|dns|crypto|zlib)['"`]/;
|
|
61
|
+
const WATCHED_MODULE = /^(?:node:)?(?:fs|dns|crypto|zlib)$/;
|
|
62
|
+
const watchedMemberNames = new Set([...callbackMembers.values()].flatMap((members) => [...members]));
|
|
63
|
+
function isWatchedSpecifier(node) {
|
|
64
|
+
return node !== undefined && ts.isStringLiteralLike(node) && WATCHED_MODULE.test(node.text);
|
|
65
|
+
}
|
|
66
|
+
function requiresWatchedModule(node) {
|
|
67
|
+
if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === 'require')
|
|
68
|
+
return isWatchedSpecifier(node.arguments[0]);
|
|
69
|
+
return ts.forEachChild(node, (child) => requiresWatchedModule(child) || undefined) ?? false;
|
|
70
|
+
}
|
|
71
|
+
// Local names an import or require of a watched module binds in this file.
|
|
72
|
+
function watchedBindingNames(sourceFile) {
|
|
73
|
+
const names = new Set();
|
|
74
|
+
walkNodes(sourceFile, (node) => {
|
|
75
|
+
if (ts.isImportDeclaration(node) && isWatchedSpecifier(node.moduleSpecifier)) {
|
|
76
|
+
const clause = node.importClause;
|
|
77
|
+
if (clause?.name)
|
|
78
|
+
names.add(clause.name.text);
|
|
79
|
+
const named = clause?.namedBindings;
|
|
80
|
+
if (named && ts.isNamespaceImport(named))
|
|
81
|
+
names.add(named.name.text);
|
|
82
|
+
if (named && ts.isNamedImports(named))
|
|
83
|
+
for (const element of named.elements)
|
|
84
|
+
names.add(element.name.text);
|
|
85
|
+
}
|
|
86
|
+
else if (ts.isImportEqualsDeclaration(node) &&
|
|
87
|
+
ts.isExternalModuleReference(node.moduleReference) &&
|
|
88
|
+
isWatchedSpecifier(node.moduleReference.expression)) {
|
|
89
|
+
names.add(node.name.text);
|
|
90
|
+
}
|
|
91
|
+
else if (ts.isVariableDeclaration(node) && node.initializer && requiresWatchedModule(node.initializer)) {
|
|
92
|
+
for (const binding of bindingNames(node.name))
|
|
93
|
+
names.add(binding.text);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
return names;
|
|
97
|
+
}
|
|
98
|
+
// A cheap syntactic gate before building a type checker: `it('x', () => {})` names no watched API.
|
|
99
|
+
function mayNameWatchedApi(callee, boundNames) {
|
|
100
|
+
const target = unwrapExpression(callee);
|
|
101
|
+
if (ts.isPropertyAccessExpression(target) || ts.isElementAccessExpression(target)) {
|
|
102
|
+
const member = staticMemberName(target);
|
|
103
|
+
return member !== undefined && watchedMemberNames.has(member);
|
|
104
|
+
}
|
|
105
|
+
return ts.isIdentifier(target) && boundNames().has(target.text);
|
|
106
|
+
}
|
|
107
|
+
function messageFor({ module, exported }) {
|
|
108
|
+
const promiseModule = promiseModuleFor[module];
|
|
109
|
+
const promiseForm = promiseModule
|
|
110
|
+
? `Import \`${exported}\` from \`${promiseModule}\` and \`await\` it`
|
|
111
|
+
: `Wrap it once with \`util.promisify(${module}.${exported})\` and \`await\` the result`;
|
|
112
|
+
return `\`${module}.${exported}()\` is called with a callback, the older Node.js style. ${promiseForm} inside try/catch, so its errors follow the same path as the rest of the async code instead of a separate \`err\` argument.`;
|
|
113
|
+
}
|
|
114
|
+
function isFunctionLiteral(node) {
|
|
115
|
+
const value = unwrapExpression(node);
|
|
116
|
+
return value !== undefined && (ts.isArrowFunction(value) || ts.isFunctionExpression(value));
|
|
117
|
+
}
|
|
118
|
+
function isPromiseExecutor(node) {
|
|
119
|
+
const parent = node.parent;
|
|
120
|
+
return ts.isNewExpression(parent) && ts.isIdentifier(parent.expression) && parent.expression.text === 'Promise';
|
|
121
|
+
}
|
|
122
|
+
function callsWithFirstArgument(node, callees, firstArgument) {
|
|
123
|
+
if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && callees.has(node.expression.text)) {
|
|
124
|
+
const [first] = node.arguments;
|
|
125
|
+
if (first && ts.isIdentifier(first) && first.text === firstArgument)
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
return ts.forEachChild(node, (child) => callsWithFirstArgument(child, callees, firstArgument) || undefined) ?? false;
|
|
129
|
+
}
|
|
130
|
+
// The parameters of a function and the variables its body declares at the top, such as
|
|
131
|
+
// `const callback = typeof options === 'function' ? options : maybeCallback`.
|
|
132
|
+
function outerNames(outer) {
|
|
133
|
+
const names = outer.parameters.flatMap((parameter) => bindingNames(parameter.name));
|
|
134
|
+
const body = 'body' in outer ? outer.body : undefined;
|
|
135
|
+
if (body && ts.isBlock(body))
|
|
136
|
+
for (const statement of body.statements)
|
|
137
|
+
if (ts.isVariableStatement(statement))
|
|
138
|
+
names.push(...statement.declarationList.declarations.flatMap((declaration) => bindingNames(declaration.name)));
|
|
139
|
+
return new Set(names.map((name) => name.text));
|
|
140
|
+
}
|
|
141
|
+
// `function lookup(host, options, callback) { dns.lookup(host, options, (err, address) => callback(err, address)); }`
|
|
142
|
+
// implements a callback API itself, such as an http agent's `lookup` hook, so the inner call cannot just be awaited.
|
|
143
|
+
// Forwarding to a `new Promise` executor's `reject` is a hand-written promisify and stays reported.
|
|
144
|
+
function forwardsErrorToOuterCallback(callback) {
|
|
145
|
+
const literal = unwrapExpression(callback);
|
|
146
|
+
if (!literal || (!ts.isArrowFunction(literal) && !ts.isFunctionExpression(literal)))
|
|
147
|
+
return false;
|
|
148
|
+
const errorName = literal.parameters[0]?.name;
|
|
149
|
+
const outer = ts.findAncestor(literal.parent, ts.isFunctionLike);
|
|
150
|
+
if (!errorName || !ts.isIdentifier(errorName) || !outer || isPromiseExecutor(outer))
|
|
151
|
+
return false;
|
|
152
|
+
return callsWithFirstArgument(literal.body, outerNames(outer), errorName.text);
|
|
153
|
+
}
|
|
154
|
+
// Only a call whose result is discarded, so nothing depends on what the callback form returns.
|
|
155
|
+
function isCallbackCandidate(node) {
|
|
156
|
+
return (ts.isCallExpression(node) &&
|
|
157
|
+
ts.isExpressionStatement(node.parent) &&
|
|
158
|
+
node.arguments.length >= 2 &&
|
|
159
|
+
isFunctionLiteral(node.arguments[node.arguments.length - 1]));
|
|
160
|
+
}
|
|
161
|
+
function checkNodeCallbackApis(sourceFile, file) {
|
|
162
|
+
if (!WATCHED_MODULE_LITERAL.test(sourceFile.text))
|
|
163
|
+
return [];
|
|
164
|
+
const findings = [];
|
|
165
|
+
let checker;
|
|
166
|
+
let boundNames;
|
|
167
|
+
const watchedNames = () => (boundNames ??= watchedBindingNames(sourceFile));
|
|
168
|
+
walkNodes(sourceFile, (node) => {
|
|
169
|
+
if (!isCallbackCandidate(node) || !mayNameWatchedApi(node.expression, watchedNames))
|
|
170
|
+
return;
|
|
171
|
+
checker ??= originalProgram(sourceFile).getTypeChecker();
|
|
172
|
+
const binding = importedMember(node.expression, checker);
|
|
173
|
+
if (!binding?.exported || !callbackMembers.get(binding.module)?.has(binding.exported))
|
|
174
|
+
return;
|
|
175
|
+
if (forwardsErrorToOuterCallback(node.arguments[node.arguments.length - 1]))
|
|
176
|
+
return;
|
|
177
|
+
const position = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile));
|
|
178
|
+
findings.push({
|
|
179
|
+
file,
|
|
180
|
+
line: position.line + 1,
|
|
181
|
+
column: position.character + 1,
|
|
182
|
+
ruleId: 'node-callback-api',
|
|
183
|
+
message: messageFor(binding),
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
return findings;
|
|
187
|
+
}
|
|
188
|
+
export { checkNodeCallbackApis };
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { walkNodes } from '../analysis/walk.js';
|
|
3
|
+
import { hasModifier } from './modifiers.js';
|
|
4
|
+
import { isExcludedSource } from './unowned-source.js';
|
|
5
|
+
import { declaresName } from './deprecated-apis.js';
|
|
6
|
+
import { checkNodeCallbackApis } from './modern-node-callbacks.js';
|
|
7
|
+
import { outermostExpression, unwrapExpression } from '../../shared/analysis/ast-semantics.js';
|
|
8
|
+
import { testPathKindInProject } from '../../shared/analysis/execution-context.js';
|
|
9
|
+
import { normalizeSlashes } from '../../shared/system/posix-path.js';
|
|
10
|
+
import { eslintDisabledLines, isBundledLibrary } from '../analysis/source-exclusions.js';
|
|
11
|
+
const TYPESCRIPT_FILE = /\.[cm]?tsx?$/i;
|
|
12
|
+
// `.mjs`, `.cjs`, `.mts` and `.cts` files always get their own scope, so a top-level `var` is not a global.
|
|
13
|
+
const OWN_SCOPE_FILE = /\.[cm][jt]s$/i;
|
|
14
|
+
const CHAIN_METHODS = new Set(['then', 'catch', 'finally']);
|
|
15
|
+
const MAX_THEN_ARGUMENTS = 2;
|
|
16
|
+
const PROMISE_NAME = 'Promise';
|
|
17
|
+
const ARGUMENTS_NAME = 'arguments';
|
|
18
|
+
const NO_VAR_RULES = ['no-var'];
|
|
19
|
+
const PREFER_REST_PARAMS_RULES = ['prefer-rest-params'];
|
|
20
|
+
// Build output checked into the source tree, such as a Tauri plugin's `dist-js/index.cjs`.
|
|
21
|
+
const BUILD_OUTPUT_PATH = /(?:^|\/)dist(?:-[\w-]+)?\//i;
|
|
22
|
+
// Formatted source stays well below this; a longer line is minified or obfuscated code.
|
|
23
|
+
const MINIFIED_LINE_LENGTH = 300;
|
|
24
|
+
const TEST_CHAIN_CONTEXT = 'This source is a test, where asserting on a request or client chain inside `.then()` is a common style.';
|
|
25
|
+
const ONE_STEP_CHAIN_CONTEXT = 'The chain only maps or probes the settled value in one step, which reads about as clearly as a separate `await`.';
|
|
26
|
+
const SETTLED_CHAIN_CONTEXT = 'The chain turns success and failure into one value for a variable, which `try`/`catch` would need a `let` for.';
|
|
27
|
+
const thenChainRule = {
|
|
28
|
+
ruleId: 'then-chain-in-async',
|
|
29
|
+
message: 'This async function awaits or returns a `.then()` chain, mixing two promise styles. Write `const value = await promise;` and handle failures with try/catch, so the function reads top to bottom and one error path covers every step.',
|
|
30
|
+
};
|
|
31
|
+
const promiseWrapperRule = {
|
|
32
|
+
ruleId: 'redundant-promise-wrapper',
|
|
33
|
+
message: '`new Promise` here only forwards another promise to `resolve` and `reject`. Return that promise directly, or `await` it in an async function; the wrapper adds nothing and is easy to break by dropping `reject`.',
|
|
34
|
+
};
|
|
35
|
+
const varRule = {
|
|
36
|
+
ruleId: 'var-declaration',
|
|
37
|
+
message: '`var` is function-scoped and hoisted, so the name leaks out of its block and loop and can be read before it is assigned. Use `const`, or `let` when the variable is reassigned.',
|
|
38
|
+
};
|
|
39
|
+
const argumentsRule = {
|
|
40
|
+
ruleId: 'arguments-object',
|
|
41
|
+
message: 'The `arguments` object is array-like, has no type and does not exist in arrow functions. Declare a rest parameter (`function name(...args)`) and use the real array instead.',
|
|
42
|
+
};
|
|
43
|
+
function findingAt(sourceFile, file, node, { ruleId, message }, contextualReason) {
|
|
44
|
+
const position = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile));
|
|
45
|
+
return {
|
|
46
|
+
file,
|
|
47
|
+
line: position.line + 1,
|
|
48
|
+
column: position.character + 1,
|
|
49
|
+
ruleId,
|
|
50
|
+
message,
|
|
51
|
+
...(contextualReason && { contextualReason }),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function enclosingFunction(node) {
|
|
55
|
+
return ts.findAncestor(node.parent, ts.isFunctionLike);
|
|
56
|
+
}
|
|
57
|
+
function isAsyncFunction(node) {
|
|
58
|
+
return node !== undefined && hasModifier(node, ts.SyntaxKind.AsyncKeyword);
|
|
59
|
+
}
|
|
60
|
+
function containsAwait(node) {
|
|
61
|
+
return Boolean(ts.forEachChild(node, (child) => ts.isAwaitExpression(child) || (!ts.isFunctionLike(child) && containsAwait(child))));
|
|
62
|
+
}
|
|
63
|
+
// A reference (`.then(parse)`) or a callback that returns or throws one expression: `(res) => res.json()`,
|
|
64
|
+
// `() => true`, `async (res) => res.arrayBuffer()` or `(error) => { throw wrap(error); }`.
|
|
65
|
+
function isOneStepCallback(argument) {
|
|
66
|
+
const callback = unwrapExpression(argument);
|
|
67
|
+
if (!callback || (!ts.isArrowFunction(callback) && !ts.isFunctionExpression(callback)))
|
|
68
|
+
return true;
|
|
69
|
+
if (!ts.isBlock(callback.body)) {
|
|
70
|
+
const body = unwrapExpression(callback.body);
|
|
71
|
+
return !containsAwait(ts.isAwaitExpression(body) ? body.expression : body);
|
|
72
|
+
}
|
|
73
|
+
if (isAsyncFunction(callback))
|
|
74
|
+
return false;
|
|
75
|
+
const [statement, ...rest] = callback.body.statements;
|
|
76
|
+
return !rest.length && (!statement || ts.isReturnStatement(statement) || ts.isThrowStatement(statement));
|
|
77
|
+
}
|
|
78
|
+
// `p.then(f)`, `p.then(f).catch(g)` or `p.catch(g).then(f)`: a chain of promise methods with at least one
|
|
79
|
+
// `.then`. A chain of only `.catch` or `.finally` (`await load().catch(() => null)`) is a compact fallback,
|
|
80
|
+
// and `await import('./m').then((m) => m.x)` is the idiomatic way to pick one export of a lazy module.
|
|
81
|
+
function chainHandlers(expression) {
|
|
82
|
+
let current = unwrapExpression(expression);
|
|
83
|
+
const handlers = { thenCount: 0, oneStepSuccess: true, oneStepRejection: true, hasRejection: false };
|
|
84
|
+
while (current &&
|
|
85
|
+
ts.isCallExpression(current) &&
|
|
86
|
+
ts.isPropertyAccessExpression(current.expression) &&
|
|
87
|
+
CHAIN_METHODS.has(current.expression.name.text)) {
|
|
88
|
+
const method = current.expression.name.text;
|
|
89
|
+
const [first, second] = current.arguments;
|
|
90
|
+
if (method === 'then' && current.arguments.length >= 1 && current.arguments.length <= MAX_THEN_ARGUMENTS)
|
|
91
|
+
handlers.thenCount++;
|
|
92
|
+
// `.finally` handlers count with the success path: neither turns a failure into a value.
|
|
93
|
+
const success = method === 'catch' ? undefined : first;
|
|
94
|
+
const rejection = method === 'then' ? second : method === 'catch' ? first : undefined;
|
|
95
|
+
if (!isOneStepCallback(success))
|
|
96
|
+
handlers.oneStepSuccess = false;
|
|
97
|
+
if (rejection)
|
|
98
|
+
handlers.hasRejection = true;
|
|
99
|
+
if (!isOneStepCallback(rejection))
|
|
100
|
+
handlers.oneStepRejection = false;
|
|
101
|
+
current = unwrapExpression(current.expression.expression);
|
|
102
|
+
}
|
|
103
|
+
if (current && ts.isCallExpression(current) && current.expression.kind === ts.SyntaxKind.ImportKeyword)
|
|
104
|
+
return;
|
|
105
|
+
return handlers.thenCount ? handlers : undefined;
|
|
106
|
+
}
|
|
107
|
+
// `const value = await ...` or `value = await ...`.
|
|
108
|
+
function storesValue(node) {
|
|
109
|
+
const outer = outermostExpression(node);
|
|
110
|
+
const parent = outer.parent;
|
|
111
|
+
if (ts.isVariableDeclaration(parent))
|
|
112
|
+
return parent.initializer === outer;
|
|
113
|
+
return (ts.isBinaryExpression(parent) &&
|
|
114
|
+
parent.right === outer &&
|
|
115
|
+
parent.operatorToken.kind >= ts.SyntaxKind.FirstAssignment &&
|
|
116
|
+
parent.operatorToken.kind <= ts.SyntaxKind.LastAssignment);
|
|
117
|
+
}
|
|
118
|
+
// A single `.then` whose handlers each map or probe the value in one expression is one step, as in
|
|
119
|
+
// `await fetch(url).then((res) => res.json())` or `.then(() => true).catch(() => false)`. Stored with a
|
|
120
|
+
// longer failure handler, `const found = await probe().then(() => true, (error) => { ... })` settles both
|
|
121
|
+
// outcomes into a `const`. A second `.then` or a longer handler elsewhere is code `await` reads better.
|
|
122
|
+
function thenChainShape(node) {
|
|
123
|
+
const handlers = chainHandlers(asyncOperand(node));
|
|
124
|
+
if (!handlers)
|
|
125
|
+
return;
|
|
126
|
+
if (handlers.thenCount > 1 || !handlers.oneStepSuccess)
|
|
127
|
+
return 'multi-step';
|
|
128
|
+
if (handlers.oneStepRejection)
|
|
129
|
+
return 'one-step';
|
|
130
|
+
return ts.isAwaitExpression(node) && handlers.hasRejection && storesValue(node) ? 'settled' : 'multi-step';
|
|
131
|
+
}
|
|
132
|
+
// The value an async function awaits or returns. Fire-and-forget statements and promise combinator
|
|
133
|
+
// arguments are not reached, because neither is the operand of `await` or `return`.
|
|
134
|
+
function asyncOperand(node) {
|
|
135
|
+
if (ts.isAwaitExpression(node))
|
|
136
|
+
return isAsyncFunction(enclosingFunction(node)) ? node.expression : undefined;
|
|
137
|
+
if (ts.isReturnStatement(node))
|
|
138
|
+
return isAsyncFunction(enclosingFunction(node)) ? node.expression : undefined;
|
|
139
|
+
if (ts.isArrowFunction(node) && isAsyncFunction(node) && !ts.isBlock(node.body))
|
|
140
|
+
return node.body;
|
|
141
|
+
}
|
|
142
|
+
function identifierName(node) {
|
|
143
|
+
const value = node && ts.isParameter(node) ? node.name : unwrapExpression(node);
|
|
144
|
+
return value && ts.isIdentifier(value) ? value.text : undefined;
|
|
145
|
+
}
|
|
146
|
+
// `source.then(resolve, reject)`, `source.then(resolve).catch(reject)` or `source.then(resolve)`.
|
|
147
|
+
function forwardsToExecutor(expression, resolve, reject) {
|
|
148
|
+
let current = unwrapExpression(expression);
|
|
149
|
+
let forwardsValue = false;
|
|
150
|
+
while (current && ts.isCallExpression(current) && ts.isPropertyAccessExpression(current.expression)) {
|
|
151
|
+
const method = current.expression.name.text;
|
|
152
|
+
// `api.get(url).then(resolve, reject)`: the chain ends at the source promise's own call.
|
|
153
|
+
if (method !== 'then' && method !== 'catch')
|
|
154
|
+
break;
|
|
155
|
+
const [first, second, ...rest] = current.arguments.map(identifierName);
|
|
156
|
+
if (rest.length)
|
|
157
|
+
return false;
|
|
158
|
+
if (method === 'then') {
|
|
159
|
+
if (first !== resolve || (second !== undefined && second !== reject))
|
|
160
|
+
return false;
|
|
161
|
+
forwardsValue = true;
|
|
162
|
+
}
|
|
163
|
+
else if (reject === undefined || first !== reject || second !== undefined) {
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
current = unwrapExpression(current.expression.expression);
|
|
167
|
+
}
|
|
168
|
+
return forwardsValue;
|
|
169
|
+
}
|
|
170
|
+
function executorBodyExpression(executor) {
|
|
171
|
+
if (!ts.isBlock(executor.body))
|
|
172
|
+
return executor.body;
|
|
173
|
+
const [statement, ...rest] = executor.body.statements;
|
|
174
|
+
if (!statement || rest.length)
|
|
175
|
+
return;
|
|
176
|
+
if (ts.isExpressionStatement(statement) || ts.isReturnStatement(statement))
|
|
177
|
+
return statement.expression;
|
|
178
|
+
}
|
|
179
|
+
function isRedundantPromiseWrapper(node) {
|
|
180
|
+
if (!ts.isNewExpression(node) || !ts.isIdentifier(node.expression) || node.expression.text !== PROMISE_NAME)
|
|
181
|
+
return false;
|
|
182
|
+
const executor = unwrapExpression(node.arguments?.length === 1 ? node.arguments[0] : undefined);
|
|
183
|
+
if (!executor || (!ts.isArrowFunction(executor) && !ts.isFunctionExpression(executor)))
|
|
184
|
+
return false;
|
|
185
|
+
// An async executor is the reliability rule async-promise-executor.
|
|
186
|
+
if (isAsyncFunction(executor) || executor.parameters.length < 1 || executor.parameters.length > 2)
|
|
187
|
+
return false;
|
|
188
|
+
const [resolve, reject] = executor.parameters.map(identifierName);
|
|
189
|
+
if (resolve === undefined || (executor.parameters.length === 2 && reject === undefined))
|
|
190
|
+
return false;
|
|
191
|
+
return forwardsToExecutor(executorBodyExpression(executor), resolve, reject);
|
|
192
|
+
}
|
|
193
|
+
// `declare var x` and the members of `declare global { var x }` describe globals and have no block form.
|
|
194
|
+
function isAmbient(node) {
|
|
195
|
+
return ts.findAncestor(node, (ancestor) => hasModifier(ancestor, ts.SyntaxKind.DeclareKeyword)) !== undefined;
|
|
196
|
+
}
|
|
197
|
+
function isFunctionScopedVar(node) {
|
|
198
|
+
return ts.isVariableDeclarationList(node) && !(node.flags & ts.NodeFlags.BlockScoped) && !isAmbient(node);
|
|
199
|
+
}
|
|
200
|
+
function lineLengthAt(sourceFile, line) {
|
|
201
|
+
const starts = sourceFile.getLineStarts();
|
|
202
|
+
const end = line + 1 < starts.length ? starts[line + 1] : sourceFile.text.length;
|
|
203
|
+
return sourceFile.text.slice(starts[line], end).trimEnd().length;
|
|
204
|
+
}
|
|
205
|
+
// `foo.arguments`, `{ arguments: 1 }`, `{ arguments: string[] }` and `const { arguments: args } = call`
|
|
206
|
+
// name a property, not the object.
|
|
207
|
+
function isArgumentsReference(node) {
|
|
208
|
+
if (!ts.isIdentifier(node) || node.text !== ARGUMENTS_NAME)
|
|
209
|
+
return false;
|
|
210
|
+
const parent = node.parent;
|
|
211
|
+
if (ts.isBindingElement(parent) && parent.propertyName === node)
|
|
212
|
+
return false;
|
|
213
|
+
const namesParent = 'name' in parent && parent.name === node;
|
|
214
|
+
return !namesParent || ts.isShorthandPropertyAssignment(parent);
|
|
215
|
+
}
|
|
216
|
+
// The function whose `arguments` a reference reads: arrow functions see through to the one around them.
|
|
217
|
+
function argumentsOwner(node) {
|
|
218
|
+
let owner = enclosingFunction(node);
|
|
219
|
+
while (owner && ts.isArrowFunction(owner))
|
|
220
|
+
owner = enclosingFunction(owner);
|
|
221
|
+
return owner;
|
|
222
|
+
}
|
|
223
|
+
// Beside named parameters, `arguments` is deliberate: `arguments.length` tells an omitted argument from
|
|
224
|
+
// `undefined`, and `super(...arguments)` forwards everything. A rest parameter would replace the typed
|
|
225
|
+
// signature, so only functions without named parameters are reported. A TypeScript `this` parameter is a type.
|
|
226
|
+
function declaresNamedParameter(owner) {
|
|
227
|
+
return owner.parameters.some((parameter) => !parameter.dotDotDotToken && !(ts.isIdentifier(parameter.name) && parameter.name.text === 'this'));
|
|
228
|
+
}
|
|
229
|
+
// `dataLayer.push(arguments)` is the gtag and analytics snippet idiom: gtag reads only a real arguments object.
|
|
230
|
+
function isQueuedArguments(node) {
|
|
231
|
+
const call = node.parent;
|
|
232
|
+
return (ts.isCallExpression(call) &&
|
|
233
|
+
call.arguments.length === 1 &&
|
|
234
|
+
ts.isPropertyAccessExpression(call.expression) &&
|
|
235
|
+
call.expression.name.text === 'push');
|
|
236
|
+
}
|
|
237
|
+
function fileScopeOf(sourceFile, file) {
|
|
238
|
+
const ownScope = ts.isExternalModule(sourceFile) || OWN_SCOPE_FILE.test(file);
|
|
239
|
+
return { ownScope, modernFile: ownScope || TYPESCRIPT_FILE.test(file) };
|
|
240
|
+
}
|
|
241
|
+
// A top-level `var` in a script file is a global that other scripts may read. A top-level `var` in a test
|
|
242
|
+
// is hoisted on purpose, so `vi.mock` and `jest.mock` factories can assign it before the imports run.
|
|
243
|
+
// `// eslint-disable-next-line no-var` and a file-wide `/* eslint-disable */` over copied code are kept.
|
|
244
|
+
function isReportableVar(node, sourceFile, { ownScope, isTest, varDisabled }) {
|
|
245
|
+
const topLevel = !enclosingFunction(node);
|
|
246
|
+
if ((topLevel && !ownScope) || (topLevel && isTest))
|
|
247
|
+
return false;
|
|
248
|
+
const line = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile)).line;
|
|
249
|
+
return !varDisabled(line + 1) && lineLengthAt(sourceFile, line) <= MINIFIED_LINE_LENGTH;
|
|
250
|
+
}
|
|
251
|
+
// `// eslint-disable-next-line prefer-rest-params` keeps a deliberate use, and minified lines are not edited by hand.
|
|
252
|
+
function isReportableArguments(node, sourceFile, restParamsDisabled) {
|
|
253
|
+
if (isQueuedArguments(node))
|
|
254
|
+
return false;
|
|
255
|
+
const line = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile)).line;
|
|
256
|
+
return !restParamsDisabled(line + 1) && lineLengthAt(sourceFile, line) <= MINIFIED_LINE_LENGTH;
|
|
257
|
+
}
|
|
258
|
+
function thenChainContext(shape, isTest) {
|
|
259
|
+
if (isTest)
|
|
260
|
+
return TEST_CHAIN_CONTEXT;
|
|
261
|
+
if (shape === 'one-step')
|
|
262
|
+
return ONE_STEP_CHAIN_CONTEXT;
|
|
263
|
+
if (shape === 'settled')
|
|
264
|
+
return SETTLED_CHAIN_CONTEXT;
|
|
265
|
+
}
|
|
266
|
+
function checkModernSyntax(sourceFile, file) {
|
|
267
|
+
if (isExcludedSource(file, sourceFile) || BUILD_OUTPUT_PATH.test(normalizeSlashes(file)))
|
|
268
|
+
return [];
|
|
269
|
+
if (isBundledLibrary(sourceFile))
|
|
270
|
+
return [];
|
|
271
|
+
const scope = fileScopeOf(sourceFile, file);
|
|
272
|
+
const isTest = Boolean(testPathKindInProject(sourceFile.fileName, () => file));
|
|
273
|
+
const varDisabled = eslintDisabledLines(sourceFile, NO_VAR_RULES);
|
|
274
|
+
const restParamsDisabled = eslintDisabledLines(sourceFile, PREFER_REST_PARAMS_RULES);
|
|
275
|
+
const findings = [];
|
|
276
|
+
const wrappers = [];
|
|
277
|
+
const argumentsOwners = new Map();
|
|
278
|
+
walkNodes(sourceFile, (node) => {
|
|
279
|
+
const shape = thenChainShape(node);
|
|
280
|
+
if (shape)
|
|
281
|
+
findings.push(findingAt(sourceFile, file, node, thenChainRule, thenChainContext(shape, isTest)));
|
|
282
|
+
if (isRedundantPromiseWrapper(node))
|
|
283
|
+
wrappers.push(node);
|
|
284
|
+
if (!scope.modernFile)
|
|
285
|
+
return;
|
|
286
|
+
if (isFunctionScopedVar(node) && isReportableVar(node, sourceFile, { ...scope, isTest, varDisabled }))
|
|
287
|
+
findings.push(findingAt(sourceFile, file, node, varRule));
|
|
288
|
+
if (isArgumentsReference(node) && isReportableArguments(node, sourceFile, restParamsDisabled)) {
|
|
289
|
+
const owner = argumentsOwner(node);
|
|
290
|
+
if (owner && !declaresNamedParameter(owner) && !argumentsOwners.has(owner))
|
|
291
|
+
argumentsOwners.set(owner, node);
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
if (wrappers.length && !declaresName(sourceFile, PROMISE_NAME, []))
|
|
295
|
+
findings.push(...wrappers.map((node) => findingAt(sourceFile, file, node, promiseWrapperRule)));
|
|
296
|
+
if (argumentsOwners.size && !declaresName(sourceFile, ARGUMENTS_NAME, []))
|
|
297
|
+
findings.push(...[...argumentsOwners.values()].map((node) => findingAt(sourceFile, file, node, argumentsRule)));
|
|
298
|
+
findings.push(...checkNodeCallbackApis(sourceFile, file));
|
|
299
|
+
return findings.sort((left, right) => (left.line ?? 0) - (right.line ?? 0) || (left.column ?? 0) - (right.column ?? 0));
|
|
300
|
+
}
|
|
301
|
+
export { checkModernSyntax };
|
|
@@ -5,6 +5,7 @@ import { functionAnchor } from './functions.js';
|
|
|
5
5
|
import { generatedSource } from './duplicates.js';
|
|
6
6
|
import { isVendoredMinified } from '../../shared/analysis/execution-context.js';
|
|
7
7
|
import { defaultLimits } from './limits.js';
|
|
8
|
+
import { normalizeSlashes } from '../../shared/system/posix-path.js';
|
|
8
9
|
// Lines that hold at least one token, so comments and blank lines are not counted.
|
|
9
10
|
function linesOfCode(sourceFile, root = sourceFile) {
|
|
10
11
|
const codeLines = new Set();
|
|
@@ -59,7 +60,7 @@ function checkSizeLimits(sourceFile, file, limits = defaultLimits, isGenerated)
|
|
|
59
60
|
findings.push({ file, line: position.line + 1, column: position.character + 1, ruleId, message });
|
|
60
61
|
}
|
|
61
62
|
if (isVendoredMinified(file) ||
|
|
62
|
-
/(?:^|\/)(?:vendors?|third[-_]party|assets\/private)\/.*\.js$/i.test(file
|
|
63
|
+
/(?:^|\/)(?:vendors?|third[-_]party|assets\/private)\/.*\.js$/i.test(normalizeSlashes(file))) {
|
|
63
64
|
return findings;
|
|
64
65
|
}
|
|
65
66
|
const lineCount = sourceFile.getLineStarts().length;
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { testPathKindInProject } from '../../shared/analysis/execution-context.js';
|
|
2
2
|
import ts from 'typescript';
|
|
3
|
+
import { strayConsoleMethods } from '../../shared/reporting/stray-console-methods.js';
|
|
3
4
|
import { walkNodes } from '../analysis/walk.js';
|
|
4
5
|
import { hasModifier } from './modifiers.js';
|
|
6
|
+
import { toolingConsoleContext } from './console-tooling.js';
|
|
5
7
|
import { generatedSource } from './duplicates.js';
|
|
6
8
|
import { classifyExecutionContext, isVendoredMinified } from '../../shared/analysis/execution-context.js';
|
|
7
9
|
import { NO_CONSOLE_RULES, eslintDisabledLines, isBundledLibrary, isVendoredOrSamplePath, } from '../analysis/source-exclusions.js';
|
|
8
|
-
|
|
10
|
+
import { normalizeSlashes } from '../../shared/system/posix-path.js';
|
|
11
|
+
const CONSOLE_METHODS = new Set(strayConsoleMethods);
|
|
9
12
|
// Output of these methods goes to stderr; the rest goes to stdout.
|
|
10
13
|
const STDERR_METHODS = new Set(['warn', 'error', 'trace']);
|
|
11
14
|
// Files that are run once by hand or by a tool, where printing is the point. Matched against the
|
|
@@ -114,8 +117,7 @@ function loggerCandidateName(node) {
|
|
|
114
117
|
}
|
|
115
118
|
// A file that defines a logger is the one place allowed to reach the console.
|
|
116
119
|
function definesLogger(sourceFile, file) {
|
|
117
|
-
const baseName = file
|
|
118
|
-
.replaceAll('\\', '/')
|
|
120
|
+
const baseName = normalizeSlashes(file)
|
|
119
121
|
.split('/')
|
|
120
122
|
.pop()
|
|
121
123
|
?.replace(/\.[^.]+$/, '') ?? '';
|
|
@@ -371,14 +373,34 @@ function loggerReplacement(sourceFile, callNode) {
|
|
|
371
373
|
const loggerName = plainLoggerName(sourceFile, plainMethod);
|
|
372
374
|
return loggerName ? { replacement: `${loggerName}.${plainMethod}` } : undefined;
|
|
373
375
|
}
|
|
376
|
+
// Read actual leading comment trivia so a directive embedded in a string cannot hide a console call.
|
|
377
|
+
function oxlintConsoleExceptions(sourceFile) {
|
|
378
|
+
const lines = new Set();
|
|
379
|
+
if (!sourceFile.text.includes('oxlint-disable-next-line'))
|
|
380
|
+
return lines;
|
|
381
|
+
walkNodes(sourceFile, (node) => {
|
|
382
|
+
if (!ts.isStatement(node) && !ts.isCallExpression(node) && !ts.isMethodDeclaration(node))
|
|
383
|
+
return;
|
|
384
|
+
for (const comment of ts.getLeadingCommentRanges(sourceFile.text, node.pos) ?? []) {
|
|
385
|
+
if (comment.kind !== ts.SyntaxKind.SingleLineCommentTrivia)
|
|
386
|
+
continue;
|
|
387
|
+
const body = sourceFile.text.slice(comment.pos + 2, comment.end).split(/\s+--?(?:\s|$)/, 1)[0];
|
|
388
|
+
const rules = /^\s*oxlint-disable-next-line\s+(.+)$/.exec(body)?.[1];
|
|
389
|
+
if (rules?.split(/[\s,]+/).some((name) => name === 'no-console')) {
|
|
390
|
+
lines.add(sourceFile.getLineAndCharacterOfPosition(comment.pos).line + 2);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
});
|
|
394
|
+
return lines;
|
|
395
|
+
}
|
|
374
396
|
function isReportable(node, sourceFile) {
|
|
375
397
|
return (!isInDevGuard(node, sourceFile) &&
|
|
376
398
|
!isInsideLoggerImplementationOrBoundary(node) &&
|
|
377
399
|
!(consoleMethodOf(node) === 'error' && isLastResortReport(node, sourceFile)) &&
|
|
378
400
|
!isFailFastReport(node, consoleMethodOf(node) ?? ''));
|
|
379
401
|
}
|
|
380
|
-
function checkStrayConsole(sourceFile, file, options) {
|
|
381
|
-
const normalized = file
|
|
402
|
+
function checkStrayConsole(sourceFile, file, options, allowedMethods = []) {
|
|
403
|
+
const normalized = normalizeSlashes(file);
|
|
382
404
|
if (testPathKindInProject(sourceFile.fileName, () => file) ||
|
|
383
405
|
NON_PRODUCTION_PATH.test(normalized) ||
|
|
384
406
|
FRONTEND_PATH.test(normalized) ||
|
|
@@ -394,13 +416,15 @@ function checkStrayConsole(sourceFile, file, options) {
|
|
|
394
416
|
if (hasNonServerBehaviour(sourceFile))
|
|
395
417
|
return [];
|
|
396
418
|
const isDisabled = eslintDisabledLines(sourceFile, NO_CONSOLE_RULES);
|
|
419
|
+
const oxlintExceptions = oxlintConsoleExceptions(sourceFile);
|
|
420
|
+
const isTooling = toolingConsoleContext(sourceFile);
|
|
397
421
|
const findings = [];
|
|
398
422
|
walkNodes(sourceFile, (node) => {
|
|
399
423
|
const method = consoleMethodOf(node);
|
|
400
|
-
if (!method || !isReportable(node, sourceFile))
|
|
424
|
+
if (!method || allowedMethods.includes(method) || !isReportable(node, sourceFile))
|
|
401
425
|
return;
|
|
402
426
|
const position = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile));
|
|
403
|
-
if (isDisabled(position.line + 1))
|
|
427
|
+
if (isDisabled(position.line + 1) || oxlintExceptions.has(position.line + 1) || isTooling(node))
|
|
404
428
|
return;
|
|
405
429
|
findings.push({
|
|
406
430
|
file,
|