Idiomatic rules (opt-in): prefer-option, no-swallowed-error; undefined-to-option codemod #48
Loading…
Reference in a new issue
No description provided.
Delete branch "evobug/idiomatic-option"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
From the TwitchRTS diff review. The migration wrote
GorePose | undefinedwhere the framework's spelling isOption<GorePose>: about 200| undefinedagainst 828Option<…>in their branch. Our ownno-nullquick fix produced those.Opt-in idiomatic layer.
"safe-ts": { "idiomatic": true }in package.json turns it on. The project pass drops these rules' diagnostics unless the setting is on, socheck, Vite, the Node loader, the LSP and the oxlint plugin all follow one switch. The oxlint preset lists the rules, but they report nothing until the setting is on.prefer-option:T | undefinedis writtenOption<T>.Optiontype.null(no-null's job),void/any/unknown/never, the argument ofOption<…>, and.d.tsfiles.no-swallowed-error: a failure turned intoundefined.if (isErr(r)) return undefined(alsoisErr(a) || isErr(b)),isErr(r) ? undefined : r(and the negated form),catch { return undefined; },.catch(() => undefined).Fixes and codemod
safe-ts migrate undefined-to-option: appliesprefer-option's fix everywhere, with notes for files that have their ownOptiontype.no-null's quick fix onT | nullnow writesOption<T>, as thenull-to-undefinedcodemod already did.q-needs-result-returnnow accepts std'sJsonResult<T>.Docs turn the setting on, so every example follows the rules:
JsonResult<T>withq) instead ofundefined.JsonResult<Option<Account>>.Verification
idiomaticandidiomatic_off, plus codemod cases basic, clash and imported.npm run build, typecheck and typecheck:emit pass.🤖 Generated with Claude Code
`"safe-ts": { "idiomatic": true }` in package.json turns on a second layer of rules that hold code to the framework's own idioms. The project pass drops their diagnostics unless the setting is on, so check, Vite, the loader, the LSP and the oxlint plugin all follow it. - prefer-option: `T | undefined` is written `Option<T>`. Quick fix adds the import (none with the prelude); no fix where the file has its own `Option`. - no-swallowed-error: `if (isErr(r)) return undefined`, `isErr(r) ? undefined : r`, `catch { return undefined; }`, `.catch(() => undefined)`: return the Result. - `safe-ts migrate undefined-to-option` applies prefer-option's fix everywhere. - no-null's quick fix on `T | null` writes `Option<T>`, as the codemod does. - q-needs-result-return accepts std's `JsonResult<T>`. The docs turn the setting on: examples write `Option<T>`, and the JSON guide's examples return the parse error instead of `undefined`. Co-Authored-By: Claude Opus 5.5 <[email protected]>