Skip to content

chore(solana): add return types across the Solana platform modules - #635

Open
ulissesferreira wants to merge 2 commits into
mainfrom
chore/solana-lint-suppressions-core-platform
Open

ulissesferreira wants to merge 2 commits into
mainfrom
chore/solana-lint-suppressions-core-platform

Conversation

@ulissesferreira

Copy link
Copy Markdown
Contributor

Description

Clears the Oxlint suppressions for the Solana Snap's core platform modules: the polyfill shims, the instruction parsers, the SDK extensions and the event emitter. 36 of the 37 suppressed violations in these files are gone; the rules cleared are typescript/explicit-function-return-type (20), typescript/no-explicit-any (2 of 3), typescript/no-unsafe-assignment (3), typescript/no-unsafe-return, typescript/no-unsafe-argument, internal-snaps/no-in-operator (2), vitest/no-conditional-in-test (4), no-unused-vars, no-shadow and promise/no-callback-in-promise.

The change is behaviour-neutral: return types are the ones TypeScript already inferred, the two in operators were replaced with hasProperty() from @metamask/utils (an own-property check with the same narrowing, on plain decoded objects), catch (error) became catch where the binding was unused (a @ts-expect-error on a branded-address lookup became a typed accessor), and the conditional test setup was turned into it.each data. The polyfill signatures match the DOM/Node signatures they polyfill (Promise<ArrayBuffer | JsonWebKey>, Promise<CryptoKey>, void, string, Uint8Array).

Changes

  • packages/solana-wallet-snap/src/core/components/Domain/Domain.tsx — returns a SnapElement<DomainProps> from the component (the Snaps SDK leaves JSX expressions untyped in this repo, so the element is labelled with the type SnapComponent already declares) (typescript/no-unsafe-return)
  • packages/solana-wallet-snap/src/core/sdk-extensions/codecs.ts — the signer pairs are mapped as tuples before Object.fromEntries, so the signatures map stops falling through the any overload (typescript/no-unsafe-assignment)
  • packages/solana-wallet-snap/src/core/sdk-extensions/codecs.test.ts — the fixture transaction is labelled Transaction at the call site, since MockExecutionScenario.signedTransaction is typed any (typescript/no-unsafe-argument)
  • packages/solana-wallet-snap/src/core/sdk-extensions/transaction-messages.ts — explicit lifetime-setter return type, boolean predicates, and catch without the unused binding (typescript/explicit-function-return-type, no-unused-vars)
  • packages/solana-wallet-snap/src/entities/instructions/instructions.ts — string return types, boolean predicate, hasProperty() instead of in, and a getParsingConfig() accessor that replaces the @ts-expect-error on the branded-address lookup (typescript/explicit-function-return-type, typescript/no-unsafe-assignment, internal-snaps/no-in-operator)
  • packages/solana-wallet-snap/src/entities/instructions/instructions.test.ts — per-version fixture data via it.each, a module-level lookup-table predicate, and assert() for the fixture invariants instead of if/throw and ?? {} defaults (vitest/no-conditional-in-test)
  • packages/solana-wallet-snap/src/entities/instructions/programs/secp256k1-secp256r1.ts — return types for the identifier, the two isSecp256*Instruction predicates and the verify parser (typescript/explicit-function-return-type)
  • packages/solana-wallet-snap/src/infrastructure/event-emitter/EventEmitter.ts — void return types, and a Listener<Data> payload type (default unknown) instead of any, erased when the listener is stored because listeners are keyed by event name only (typescript/explicit-function-return-type, typescript/no-explicit-any)
  • packages/solana-wallet-snap/src/polyfills/ed25519/polyfill.ts — DOM-matching return types on toBase64, toBuffer, exportKey and importKey, and hasProperty() for the JWK d check (typescript/explicit-function-return-type, internal-snaps/no-in-operator)
  • packages/solana-wallet-snap/src/polyfills/dom-exception/index.ts, packages/solana-wallet-snap/src/polyfills/index.ts — void return types (typescript/explicit-function-return-type)
  • packages/solana-wallet-snap/src/polyfills/queue-microtask/index.ts — Promise<void> return type, a non-shadowing local name for the shim, and the microtask deferral expressed as await instead of passing the callback to .then() (typescript/explicit-function-return-type, no-shadow, promise/no-callback-in-promise)
  • oxlint-suppressions.json — regenerated with --prune-suppressions

Quality gates

  • yarn lint:oxlint packages/solana-wallet-snap — clean, 36 suppression entries removed (2069 → 2033 for the repo; the 12 files in this unit go 37 → 1)
  • tsc --noEmit — clean
  • vitest run — 88 files, 1124 passed | 4 skipped | 1 todo, same as origin/main
  • oxfmt --check — clean

Left behind

One violation stays suppressed: typescript/no-explicit-any on ParsedInstruction.data in entities/instructions/instructions.ts. The value is the untyped parse output of every instruction parser, and tightening it to Json/unknown breaks the consumers that read it as a scalar — TransactionMapper (BigNumber(rawAmount)), analyzeFeePayment and features/confirmation/components/Instruction — so it needs its own change across those call sites rather than a type swap here.

The SonarCloud new-code coverage gate was failing at 76% because two
polyfill lines changed in this PR had no tests.

- Add tests for the queue-microtask polyfill: it installs a global
  `queueMicrotask`, defines it as writable/configurable/enumerable, and
  runs its callback asynchronously.
- Move the queue-microtask implementation from `index.ts` to
  `install.ts`, matching the `ed25519` polyfill layout. Vitest excludes
  `src/**/index.ts` from coverage (the old Jest
  `coveragePathIgnorePatterns`), so the implementation could never be
  measured there and SonarCloud reported it as 0% covered. `index.ts`
  is now a re-export.
- Add a JWK import test for the Ed25519 polyfill, covering the
  `hasProperty(jwk, 'd')` branch this PR introduced.
@sonarqubecloud

Copy link
Copy Markdown

This branch was previously deployed

1 inactive (outdated) deployment
default-branch — 439abde3 Deployed Nov 17, 2026 by ulissesferreira via Determine whether this PR is a release PR #2409
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant