Rules Explorer
SAFE-TS ships 170 static rules: 116 core rules enabled by default, 27 opt-in idiomatic rules, 23 Vue rules, and 4 React rules. Every rule page includes tested rejected/accepted examples, quick fixes, and a What the rule can't see section.
Rule severities can be overridden per package or per directory in package.json (rule levels).
no-throwerrorFixFailures
throw is only allowed for errors that extend PropagateError.
unhandled-failureerrorFixFailures
A call that can throw is not handled.
must-use-resulterrorFixFailures
A Result is ignored, so its error is silently dropped.
uncaught-propagationerrorFixFailures
A PropagateError reaches a place where nothing can catch it.
floating-rejectionerrorFixFailures
An async call that can reject with a PropagateError is neither awaited, returned, nor .catch()ed.
floating-promisewarnFixFailures
An async call whose promise a statement drops: not awaited, returned, chained (.then(...), .catch(...), .finally(...)) or started on purpose with void, when it can't reject. On by default, as a warning.
promise-as-valueerrorFixFailures
A promise used where the value it resolves to is meant: an async call's result put in a template, tested with !, compared with undefined, handed to isErr or q, or an async function handed where its answer is read right away (filter, some, find, reduce, forEach, new Promise, a function of yours that tests its callback's answer). On by default, as an error.
failure-contracterrorFailures
A function that can propagate a PropagateError put into a slot that doesn't declare it. A slot is a place whose callers can't see what fills it: a member of an interface or of an object type, an abstract method, a method a subclass overrides, the type of a callback kept for later (a parameter, a field, the items of a collection). On by default, as an error.
implicit-propagationerrorFailures
A method the language calls for you that can propagate a PropagateError: toString, valueOf, [Symbol.toPrimitive], toJSON, toLocaleString, [Symbol.iterator], [Symbol.asyncIterator], an iterator's next / return / throw, [Symbol.dispose], [Symbol.asyncDispose], then, [Symbol.hasInstance] and the other well-known symbols, a Proxy handler's traps, an object literal's getters and setters, handleEvent and Node's [inspect.custom]. Reported at the method, in a class or an object literal at any depth, also where the member names a function (toString = format). On by default, as an error.
fetch-signalwarnFixFailures
A fetch(...) without a signal.
bounded-concurrencywarnFailures
Promise.all(items.map(...)) or Promise.allSettled(items.map(...)) over a list whose length isn't fixed.
pending-without-closewarnFailures
A class, or a function outside any class, keeps the resolve / reject of pending promises in a collection (pending.set(id, { resolve, reject }), waiting[id] = entry, push, add, also from Promise.withResolvers()) and listens for message (or data) to settle them, but nothing in it handles close, error, exit, end, disconnect or abort.
unbounded-pollwarnFailures
A loop that awaits a delay (sleep(...), tick(), new Promise((r) => setTimeout(r, ms)), Promise.resolve(), a function of the file that returns such a promise) and ends only when polled state changes, with no deadline, no attempt limit and no AbortSignal: while (!ready) await tick(), for (;;) { if (done) break; await sleep(10); }, or a loop with no way out at all.
no-mutable-globalerrorState
Module-level mutable state: a let/var at module level, or a module-level value changed from inside a function.
no-param-mutationerrorFixState
A function changes data it received as a parameter, or lends it to be changed (mut(x)), without declaring it Mut<...>.
missing-muterrorState
A value passed to a parameter declared Mut<...> (of a function, a method, a callback type, a component's prop) without mut(...) at the call. On by default, as an error.
aliased-muterrorState
One call that lends a value with mut(x) and also gets x, a part of it, or what holds it, through another argument or as the receiver of a method; or two loans of one object alive at once, or the owner writing it while it is lent, because an async call still holds the loan until its promise settles. On by default, as an error.
mutating-gettererrorState
A getter that changes its object: it assigns a field, calls a method of the object that changes it, or lends the object or a part of it with mut(...). Reported at the getter. On by default, as an error.
covariant-aliaserrorState
A value whose written type is a container of one type (Sub[], Box<Sub>, Map<string, Sub>) bound to a place written with the same container of another, wider type (Base[]), where a value can be written into it: a local, a field, a return, a property of an object literal. On by default, as an error.
union-tag-writeerrorState
A write to a property through a value whose written type is a union of object types, where the members disagree on that property's type (kind: "mason" in one, kind: "archer" in the other). On by default, as an error.
readonly-droppederrorState
A value whose written type has a readonly property is given a place whose written type has the same property writable: an annotated const or let, a declared return type, a field (also its initialiser in a class body) or a property, an element of a list, a value put into a Map or a Set. On by default, as an error. Quick fix, for a frozen value under an annotation: Keep it read-only: Readonly<…>.
no-mutation-while-iteratingerrorFixState
A collection gets elements added, removed or reordered while a loop goes over it.
stale-readwarnState
A local holds an object read from a parameter, then a call replaces that object, and the local is used again: it still points at the object from before.
no-foreign-prototype-patchwarnState
Changing the prototype of a class the module doesn't own: an imported class (Batcher.prototype.begin = ..., PIXI.Batcher.prototype), or a global one other than the ECMAScript built-ins (HTMLElement.prototype, WebSocket.prototype). Assignments, compound assignments and delete of its members, Object.defineProperty, Object.defineProperties, Object.assign, Object.setPrototypeOf, Reflect.defineProperty, Reflect.set and Reflect.deleteProperty on it, also through a binding that holds it (const proto = Batcher.prototype as Patched; proto.begin = ...), and handing it to a function that patches its parameter (patchMethod(Batcher.prototype, "begin", ...)), of the same file or imported from another. At module level too.
no-nullerrorFixTypes
null is not used: absence is undefined (Option<T>).
no-undefined-check-for-nullerrorFixTypes
A value from an API that returns null (localStorage.getItem, querySelector, parentElement, RegExp#exec, ...) compared with undefined.
no-null-check-for-undefinederrorFixTypes
A value whose type has no null (an Option, a field declared ?:, a pack's safe version) compared with null, or expected to be null by an assertion. The mirror of no-undefined-check-for-null.
no-anyerrorFixTypes
any is not allowed.
no-hidden-anyerrorTypes
An any nobody wrote: a type of TypeScript's lib or of Node that hands one out. MessageEvent or CustomEvent without a type argument, MessageEvent<Job> (a claim about another context's data), Function, history.state, event.data in a "message" listener whose parameter isn't annotated, Node's workerData and a worker's "message" value. On by default, as an error.
no-unchecked-casterrorTypes
value as T, <T>value, the non-null assertion value! and the definite assignment assertion let x!: T are not allowed (as const is).
no-unknown-in-resulterrorTypes
Result<unknown, E>, Result<any, E>, Option<unknown> and Option<any> are not allowed.
no-nested-optionerrorTypes
Option<Option<T>> and Option<T | undefined> are not allowed.
no-method-signatureerrorTypes
A member written as a method with parameters in an interface or a type literal: handle(animal: Animal): string. Write it as a property with a function type, readonly handle: (animal: Animal) => string. On by default, as an error.
override-parametererrorTypes
A class member that overrides a base class's method and asks for more than the method it replaces: a parameter written with a narrower type, a required one where the base's is optional (or where the base's rest parameter may be given nothing), or a mutable list where the base takes a readonly one. The override may be a method or an arrow function property, instance or static; the base's method may be abstract. Reported at the parameter. On by default, as an error.
test-only-helpererrorTypes
A test helper from @evobug_com/safe-ts-std/testing (fixture, testDouble, unchecked, expectPresent) used outside a test file.
brand-constructorerrorTypes
A brand (Html, SafeUrl, RegexSource, Ascii, SafePath, or one of the project's own, Brand<"Name">) made without its constructor: a cast to it (as Html, as unknown as SafeUrl, <Html>raw, also inside another type, as Html[]), a type argument that names it on a call TypeScript doesn't check it against (inject<SafeUrl>(key), axios.get<Html>(url)), or a type predicate or assertion signature that claims it ((text: string): text is SafeUrl => ...: TypeScript doesn't check a predicate's body; other predicates are no-type-predicate's).
no-type-predicateerrorTypes
A hand-written type predicate (value is User, this is Open) or assertion signature (asserts value is User, asserts value) on a function, method or arrow of the project. On by default, as an error.
no-overloaderrorTypes
Overload signatures on the project's own functions and class methods (constructors too), reported once per function, at its first signature. On by default, as an error.
markup-sinkerrorSinks
Markup written into the page from a value that isn't a constant the source shows or an Html: el.innerHTML = text, outerHTML, insertAdjacentHTML(position, text), setHTMLUnsafe(text), document.write(text), range.createContextualFragment(text), iframe.srcdoc = text, setAttribute("srcdoc", text), document.execCommand("insertHTML", false, text).
url-sinkerrorSinks
A URL the browser may navigate to, set from a value that isn't a constant with a safe scheme or a SafeUrl: link.href = url (also <area>, <base>), iframe.src, form.action, a button's or input's formAction, object.data, embed.src, location.href = url, location.assign(url), location.replace(url), window.open(url), navigation.navigate(url), and setAttribute("href" | "src" | "action" | "formaction" | "data", url).
code-sinkerrorSinks
Code run from text the source doesn't show: setTimeout(text) and setInterval(text) in a browser, an event handler attribute (setAttribute("onclick", text), or an attribute whose name isn't a constant), script.text, script.textContent and script.src, new Worker(url), new SharedWorker(url), navigator.serviceWorker.register(url), a worklet's addModule(url), import(specifier), and in Node vm.runInThisContext, runInNewContext, runInContext, compileFunction, new vm.Script, child_process.fork(module), new Worker(file) of node:worker_threads, module.register(specifier).
command-sinkerrorSinks
A shell command built from text the source doesn't show: exec(command) and execSync(command) of node:child_process, and spawn, spawnSync, execFile, execFileSync given an options object with shell set (then the arguments array is part of the command too).
path-sinkwarnSinks
A file path given to node:fs (every function @types/node declares with a path parameter, at each such argument: readFile, writeFile, rm, cp, rename, createReadStream, ..., promises and callbacks alike), new DatabaseSync(file), or the program spawn and execFile run, in code that input from outside the program can reach, from a value that isn't a constant the source shows or a SafePath. Idiomatic: reported where the project turns the idiomatic rules on. Reported by safe-ts check only, which sees the whole program: what a handler calls is a question about every file, so the editor and the lint plugin don't report it.
pattern-sinkerrorSinks
A regular expression compiled from text that isn't a constant the source shows or a RegexSource: new RegExp(text), RegExp(text), and a string given to str.match(text), str.matchAll(text) or str.search(text), which compile it into a pattern too.
sql-sinkerrorSinks
An SQL statement given to node:sqlite (db.exec(sql), db.prepare(sql)) that isn't a constant the source shows.
brand-sinkerrorSinks
A member the project (or a pack) declared to take only a brand of its own, given anything else: brandSinks("Sql", ["pg Pool#query"]) makes pool.query(text) with a plain string a finding, as a string given to innerHTML is. Also a brandSinks call whose brand or members the source doesn't show.
q-positionerrorq(...) and the prelude
q(...) is used where it can't be rewritten into an early return.
q-needs-result-returnerrorq(...) and the prelude
q(...) is used in a function that doesn't declare a Result return type.
q-undeclared-errorerrorq(...) and the prelude
q(...) returns early an error that the function it returns from doesn't declare. On by default, as an error.
prelude-shadowwarnq(...) and the prelude
A local named like a prelude value that code reads as SAFE-TS's own: unsafe or unsafeAsync anywhere, and q, match, is, err or Result in a file that also uses the prelude's name. Reported in files with the prelude on.
prelude-in-pageerrorq(...) and the prelude
A prelude value used inside a function that Playwright or Puppeteer runs in the browser page: page.evaluate(fn), evaluateHandle, addInitScript(fn), waitForFunction(fn), $eval(selector, fn) and $$eval(selector, fn). Reported in files with the prelude on.
needs-transformerrorq(...) and the prelude
Something that only works after the safe-ts transform, in a file that runs without it: a file that vite.config., vitest.config. or vitest.workspace.* imports, directly or not, and the config itself. Reported: q(...), parseJson<T> / validate<T> / fromFields<T> / arbitrary<T>(), and prelude names (err, isErr, match, is, ...) used without an import.
exhaustive-switcherrorFixEnums
A switch on a closed set has no default: unreachable(value). A closed set is an enum's tag (switch (x.tag)), a union of string or number literals, or the constants of a code object (type Phase = (typeof Phase)[keyof typeof Phase]), as the value's declared type says.
exhaustive-dispatcherrorEnums
An if / else if chain, a run of if (...) return ...;, a chain of ?: or a switch that compares one value with two or more members of a closed set, and doesn't handle the others. A closed set is:
negative-member-guarderrorEnums
x !== E.A on a closed set guards work, in a branch that is a case of its own: every member but A takes it, and so does every member added to the set later. Reported when the test also compares another value with a member (u.phase === Phase.INSIDE && u.job !== Job.FLEE), or excludes two members or more (x !== E.A && x !== E.B). A closed set is an enum's tag, a union of literals, or the constants of a code object, as for exhaustive-dispatch.
code-range-compareerrorEnums
<, <=, > or >= with a constant of a code object of whole numbers: afterJob >= Job.MOVE && afterJob <= Job.IGNITE, u.job < Job.DEPOSIT. A code object is an as const or frozen object of literals, such as a codesOf(...) table. Not reported for one declared ordered with /* @ordered /, nor for one with a fraction among its values ({ ms: 650, reach: 1.5 }), which holds measures rather than codes.
inline-member-seterrorEnums
The same value is tested inline against members of one closed set in more than one function, and the sets share members: u.afterJob === Job.DEPOSIT || u.afterJob === Job.MINE in one check, afterJob >= Job.MOVE && afterJob <= Job.IGNITE || … in the save reader. Both places are reported, each naming the other and what differs. Reported by safe-ts check only, which sees the whole program; the editor and the lint plugin check one file at a time.
no-ts-enumerrorFixEnums
TypeScript's enum is not allowed.
enum-constructorserrorEnums
Shape.Circle(...) where Shape is only an Enum type, without constructors declared.
enum-method-nameerrorEnums
An enum method (a member of M in Enum<V, M>) named like a method of a built-in type or of a library API safe-ts knows (get, next, map, update, send), like one every object has (toString, valueOf, constructor), or toJSON, then, impl, tag. On by default, as an error, where the method is declared.
enum-method-receivererrorEnums
A call of an enum method that the build can't turn into a call of the enum's table: the value's type isn't declared anywhere the checker follows, the call is written in a form the rewrite doesn't take, it is in a Vue template, or the method is taken off its value. On by default, as an error.
enum-method-escapeerrorEnums
A value of an enum with methods given where its type isn't the enum's but names one of the methods: an argument for a parameter declared with an object type or interface that has the method, or a binding declared with one. On by default, as an error.
enum-as-texterrorEnums
An enum value turned into text: ${job}, String(job), job + "...", jobs.join(", "), job.toString(). On by default, as an error.
json-typeerrorJSON
parseJson<T>, validate<T>, fromFields<T> or arbitrary<T> is used with a type that JSON can't produce, or that SAFE-TS can't resolve. Options for parseJson and validate that aren't an object literal ({ unknownKeys: "error" }) are reported too: the validator is generated for them at build time.
safe-ts-ignoreerrorIgnore comments
A // safe-ts-ignore <rule>: <reason> comment that doesn't do its job: it names no rule, a rule that doesn't exist, or no reason, or it silences nothing. Ignore comments are described in Ignoring one finding.
no-ts-suppressionerrorIgnore comments
A comment that switches TypeScript's own checks off: // @ts-nocheck (the whole file), // @ts-ignore (the next line), or // @ts-expect-error with no reason after it. On by default, as an error.
no-lint-suppressionerrorIgnore comments
A lint-suppression comment that silences SAFE-TS: one that names no rule (/ eslint-disable /, // oxlint-disable-next-line), or one that names a safe-ts/ rule (// oxlint-disable-next-line safe-ts/no-any). On by default, as an error.
unlisted-markererrorIgnore comments
A // @safe-ts std or // @safe-ts legacy marker in a file the project's package.json doesn't list: "safe-ts": { "trustedFiles": [...] } for std, "legacyFiles": [...] for legacy. On by default, as an error.
no-unchecked-declareerrorIgnore comments
An ambient declaration that says a value exists, with a type, and leaves both unchecked: a cast with no as. On by default, as an error.
compare-misses-undefinederrorCorrectness
A test that compares a value with "", 0 or 0n (id !== "", count === 0, n != 0n) where the value may be undefined and the test doesn't say what happens then. Reported in if, while, for, ?:, && and ||, !, and the callbacks of filter, find, some, every. On by default, as an error.
number-parse-nanwarnFixCorrectness
Number(x), parseInt(x), parseFloat(x) or +x on a string, Date.parse(text), or a number read from new Date(text), used before anything checks the result for NaN. On by default, as a warning.
not-found-indexwarnCorrectness
The result of a search, -1 when nothing matches, used as a position before anything checks it: indexOf, lastIndexOf, findIndex, findLastIndex and search, passed to splice, slice, substring, at, with and the like, or written to as an index. On by default, as a warning.
regex-last-indexerrorCorrectness
test or exec on a regex with the g or y flag, called again with the lastIndex the last call left: in a loop over other strings, in a method called again, in a callback. On by default, as an error.
divide-by-lengthwarnCorrectness
A division (or remainder) by the size of a collection the function itself made by selecting, before anything checks that it isn't empty: rows.length / rows.filter(isOk).length, the share of none. On by default, as a warning.
sparse-array-writeerrorCorrectness
A write that may land past an array's end, and so leaves holes: slots[n] = 1 into an array filled by position, values[values.length + 1] = 0, delete values[i]. On by default, as an error.
sort-comparatorerrorFixCorrectness
A comparator that doesn't return a number, or .sort() on numbers without one.
no-literal-collection-keyerrorCorrectness
map.get([x, y]), set.has({ id }): a lookup with an object created right there.
prefer-nullish-defaultwarnFixCorrectness
enabled || true, limit || 10: a default given with || where ?? was meant.
dataview-endiannesserrorFixCorrectness
view.getUint32(offset) without the littleEndian argument.
keep-error-causewarnFixCorrectness
A catch that creates a new error without passing the caught one on.
import-attributeserrorFixCorrectness
import data from "./data.json" assert { type: "json" }.
duplicate-code-valueerrorCorrectness
Two names for one code: two members of a code table with the same value, a literal union that names a member twice, or two case labels of one switch with the same value.
list-invarianterrorCorrectness
A list marked /* @sorted / whose elements are out of order, or a list marked /* @unique / that names an element twice; and either tag where the checker can't verify it.
pinned-constant-assertwarnCorrectness
A test that asserts a constant has the literal value it is declared with: expect(ENCODING_VERSION).toBe(34), assert.equal(Op.Hello, 1). Reported in test files (named .test.ts / .spec.ts, importing a test runner or node:assert, or in a test, tests or __tests__ directory). A warning by default.
cycle-init-readerrorCorrectness
Code that runs while a module loads reads a binding imported through an import cycle: a top-level const initializer, a top-level call, class X extends Y, a static field or static block, and the module's own functions that this code calls (an async one up to its first await). The message names the cycle.
unbound-methoderrorCorrectness
A method that uses this, taken off its object without being called or bound: handed to a function (queueMicrotask(this.tick), items.forEach(this.tick)), returned, stored in an object, copied to a binding (const f = ticker.tick) or destructured (const { tick } = ticker). On by default, as an error.
constructor-calls-overrideerrorCorrectness
A constructor, or an instance field's initializer, that calls a method a subclass overrides: directly (this.describe()) or through the class's own methods (this.setup(), which calls this.describe()). On by default, as an error. Reported by safe-ts check only, which sees the whole program; the editor and the lint plugin check one file at a time and don't see the subclasses in other files.
unbounded-spreadwarnCorrectness
A list of unknown length spread into a built-in that takes its elements as arguments: Math.max(...values), target.push(...extra), String.fromCharCode(...codes). On by default, as a warning, like the other rules about lists of any length (bounded-concurrency, no-accumulating-copy).
use-after-consumeerrorCorrectness
A value used again on a path where an operation used it up: an ArrayBuffer after transfer() or after it went in a transfer list (worker.postMessage(buf, [buf]), structuredClone(x, { transfer: [buf] })), an iterator iterated a second time (a generator object, list.values(), text.matchAll(re)), a Response or Request body read twice, a ReadableStream read after getReader() locked it, a WebSocket, MessagePort, Node FileHandle or readline interface used after close(). On by default, as an error.
stale-across-awaitwarnCorrectness
Shared state read before an await and written after it from that read: a lost update (this.total += await price(id)), or a check made before the await and acted on after it (a cache that two callers both miss, a "stopping" flag set only after the work). On by default, as a warning.
late-listenererrorCorrectness
A listener for an event that happens once in an object's life, added after the function waited: conn.once("close", ...) after an await, on a socket the function already had. If the event came during the await, the listener waits for ever. On by default, as an error.
superseded-task-writeerrorCorrectness
A run of a useTask (Vue or React) or of std's latest that changes state itself after an await, without asking its signal whether a newer run started meanwhile. On by default, as an error.
promise-never-settleserrorCorrectness
A new Promise whose executor has a path that neither calls resolve or reject nor hands them to something that will. On by default, as an error.
unreleased-resourcewarnCorrectness
A resource a function acquires (a file handle, an interval or a timeout, a listening server, a worker, an observer, an AbortController wired to listeners, an object URL, a stream reader's lock, a temporary directory) and doesn't release on some way out of the function: a return, the end of the body, an await in between that rejects, or a call in between that throws. On by default, as a warning.
unbalanced-updatewarnCorrectness
A change and the change that undoes it, written as a pair in one function (a flag set and cleared, a count taken and given back, an entry added and removed, a value changed and given back what it held), and a way out between the two that leaves with the first and without the second: an await that rejects, a call that throws, a return, a q(...) that returns the error, a throw, and in a loop's body a continue or a break. On by default, as a warning.
unreachable-codeerrorCorrectness
Code that can never run: statements after a call that never returns, and a branch the subject's closed type already decides. On by default, as an error. One file and the functions it imports say it all: reported in the editor and by safe-ts check alike.
unknown-eventerrorCorrectness
A listener for an event its platform object never dispatches, and nothing in the program does: el.addEventListener("clik", ...) on an HTMLElement, server.on("lisening", ...) on a Node server. On by default, as an error. Reported by safe-ts check only: whether the program dispatches the name somewhere is a question about every file.
unmatched-eventerrorCorrectness
A listener for a name nothing in the program emits on that emitter, and an emit nobody listens for. When one of each differ by a typo (one or two letters, case, a separator), both findings name the other site: that is the bug the two usually are. On by default, as an error. Reported by safe-ts check only: the two ends are in different files.
unused-answererrorCorrectness
A call whose only point is its answer, written as a statement of its own: the answer is thrown away, and the call did nothing else. name.trim(); leaves name as it was; list.concat(more); makes a list nobody keeps; new TextEncoder().encodeInto(text, out); writes what fits and says how much in an answer nobody reads. On by default, as an error.
misplaced-argumentwarnCorrectness
An argument named after another parameter of the function it is passed to, and not after its own: corner(x, y, 1.05) for corner(size, x, y, margin), area(height, width) for area(width, height). On by default, as a warning.
decided-testwarnCorrectness
A test of a place (worker.task !== undefined, if (job.done), lamp.mode === Mode.ON) while the place holds a literal the function itself just gave it, with nothing between that could change it: the test is always false (what it guards never runs) or always true. On by default, as an error. The finding says which line set the value.
test-without-assertionerrorTests
A test with a path from its start to its end on which no assertion runs: it has none at all, its assertions sit in a branch the test may not take, it returns before them, or they are all in a catch. Reported in test files (named .test.ts / .spec.ts, or importing a test runner: node:test, Vitest, Jest's @jest/globals, bun:test, @playwright/test, a package re-exporting one, one listed in "testRunners"). On by default, as an error.
assertion-cannot-failerrorTests
An assertion whose outcome doesn't depend on the code: both sides the same expression (expect(r).toBe(r), assert.equal(r, r), assert.ok(a === a)), only constants (expect(true).toBe(true), expect([1, 2]).toEqual([1, 2]), a literal compared with a local const holding it), expect(x) with no matcher, toBeDefined() / not.toBeUndefined() on a value whose written type has no undefined, and a call of a mock the test made (const spy = vi.fn(() => 3); expect(spy()).toBe(3)). Reported in test files. On by default, as an error.
deferred-assertionerrorTests
An assertion in a callback that runs after the test has ended, or only if something happens: a timer (setTimeout, setInterval, setImmediate, queueMicrotask, requestAnimationFrame, process.nextTick), an event listener (addEventListener, .on, .once, ...), or a promise's .then / .catch / .finally that the test neither awaits nor returns. Reported in test files. On by default, as an error.
swallowed-assertionerrorTests
An assertion inside a try whose catch neither rethrows, fails the test, nor looks at the error. Reported in test files. On by default, as an error.
focused-testerrorTests
.only on a test or a suite (test.only, it.only, describe.only, Jest's fit and fdescribe, node:test's { only: true }). Reported in test files. On by default, as an error.
skipped-testwarnTests
A test that doesn't run, and nothing says why: test.skip, it.todo, describe.skip, xit / xtest / xdescribe, test.skipIf(true), node:test's { skip: true } / { todo: true }, t.skip() with no reason, a test with no body (test("name")) and one whose body is empty (test("name", () => {}), often a body taken out or commented out). Reported in test files. A warning by default.
duplicate-test-namewarnTests
Two tests with the same name in one describe (or in a file's top level), or two describes of the same name next to each other. Reported in test files. A warning by default.
empty-test-suitewarnTests
A describe with no test in it, and a test file (named .test.ts / .spec.ts) that imports a runner's test or describe and registers no test. Reported in test files. A warning by default.
no-redoserrorSecurity
A regular expression that can take exponential time on some inputs.
no-object-dictionaryerrorSecurity
A plain object used as a dictionary keyed by data: counts[word], delete cache[key], key in table.
no-for-inerrorFixSecurity
for (const key in object).
no-math-random-for-secretswarnSecurity
Math.random() used for something named like a secret: a token, key, salt, nonce, password, session or CSRF value.
inlineerrorPerformance
/* @inline / asks for code to be rewritten at build time, and it can't be: a statement that can't become a loop, or a function that can't be inlined. A chain on std's InlineArray asks the same as @inline on its statement.
tail-callerrorPerformance
A function marked /* @loop / that can't be turned into a loop.
json-literalerrorPerformance
A constant marked /* @json / whose value isn't plain data that JSON keeps exactly.
stable-shapewarnPerformance
Objects that get properties after they were created, so objects of the same kind end up with different sets of keys.
hoist-intlwarnFixPerformance
new Intl.NumberFormat(...) with constant arguments inside a function or loop, and localeCompare with a locale inside a sort comparator.
no-accumulating-copywarnPerformance
[...acc, x], { ...acc, [key]: value } or acc.concat(x) on every step of a reduce, or assigned back to acc on every turn of a loop.
listener-cleanupwarnPerformance
Inside a function: addEventListener with a handler written in place (or passed by a name that nothing else reads) and no way to remove it, or setInterval whose id is thrown away.
prefer-optionOpt-inFixIdiomatic
A value that may be missing is written Option<T>, not T | undefined. An idiomatic rule: reported only with "safe-ts": { "idiomatic": true } in package.json.
no-optional-fieldOpt-inIdiomatic
An optional property (key?: T) in a type the project declares: write key: Option<T>. An idiomatic rule: reported only with "safe-ts": { "idiomatic": true } in package.json (or check --idiomatic). Reported by safe-ts check only: whether a type is a JSON payload or a component's props depends on where it is used, anywhere in the program, which the editor and the lint plugin, one file at a time, don't see. A // safe-ts-ignore no-optional-field: <reason> is judged by safe-ts check too: the editor and the lint plugin don't call it unused.
no-swallowed-errorOpt-inIdiomatic
A failure turned into undefined: if (isErr(result)) return undefined;, isErr(result) ? undefined : value, catch { return undefined; }, unwrapOr(result, undefined) (or null), and a rejection handler that does nothing: .catch(() => undefined), .catch(() => {}), .then(ok, () => undefined). An idiomatic rule: reported only with "safe-ts": { "idiomatic": true } in package.json.
sentinel-errorOpt-inIdiomatic
A function declared string that returns '' for "no error" and a message otherwise, with callers that test the string: if (error), if (!error), error ? a : b, error === ''. An idiomatic rule: reported only with "safe-ts": { "idiomatic": true } in package.json.
wide-paramOpt-inIdiomatic
A parameter of a wide context type that the function uses only through one or two field paths: shippingCost(shop: Shop) that reads shop.state.cart and shop.rates.perKg, and nothing else of the shop. An idiomatic rule: reported only with "safe-ts": { "idiomatic": true } in package.json.
unneeded-mutOpt-inIdiomatic
A parameter declared Mut<T> that the function never changes, and a loan mut(x) at a parameter that isn't Mut. An idiomatic rule: reported only with "safe-ts": { "idiomatic": true } in package.json.
prefer-is-over-tagOpt-inIdiomatic
x.tag === "Ready", x.tag !== "Failed" and switch (x.tag), in code and in Vue templates. An idiomatic rule: reported only with "safe-ts": { "idiomatic": true } in package.json.
prefer-qOpt-inIdiomatic
if (isErr(x)) return x; and isErr(x) ? x : ...: a failure passed up by hand. An idiomatic rule: reported only with "safe-ts": { "idiomatic": true } in package.json.
prefer-map-errOpt-inIdiomatic
if (isErr(x)) return err(f(x.error)); and isErr(x) ? err(...x.error...) : x: an error re-wrapped by hand. An idiomatic rule: reported only with "safe-ts": { "idiomatic": true } in package.json.
json-null-in-appOpt-inIdiomatic
JsonNull used as a second "none" inside the app: Option<T | JsonNull>, T | JsonNull | undefined for a variable, parameter or return type, a Ref<T | JsonNull>, and jsonNull put into reactive state (ref(jsonNull), state.value = jsonNull). An idiomatic rule: reported only with "safe-ts": { "idiomatic": true } in package.json.
null-or-undefined-checkOpt-inIdiomatic
A strict test for one of null and undefined (x === undefined, x !== null, x === jsonNull) on a value whose declared type holds both (deletedAt?: string | JsonNull, Option<T | JsonNull>, T | null | undefined), in a function that never tests it for the other one. An idiomatic rule: reported only with "safe-ts": { "idiomatic": true } in package.json.
undefined-to-nullOpt-inIdiomatic
A serializer that writes null (or jsonNull) for every undefined: a JSON.stringify replacer that returns null for undefined, or a function that walks an object's keys (Object.entries, Object.keys, for...in) and does the same. An idiomatic rule: reported only with "safe-ts": { "idiomatic": true } in package.json.
latest-wins-counterOpt-inIdiomatic
A let n = 0 outside an async function that the function increments before an await and compares after it, whatever it is called: a hand-written "latest run wins" ticket. An idiomatic rule: reported only with "safe-ts": { "idiomatic": true } in package.json.
unused-task-signalOpt-inIdiomatic
A useTask callback (@evobug_com/safe-ts-vue, @evobug_com/safe-ts-react), or a callback of std's latest (@evobug_com/safe-ts-std/async), that never reads its signal (no first parameter, or one that isn't used: _signal) and calls something that could take it. An idiomatic rule: reported only with "safe-ts": { "idiomatic": true } in package.json.
catch-on-resultOpt-inIdiomatic
.catch(...) (or .then(ok, fail)) on a call of the project's async function that returns Promise<Result<...>>, and a try/catch around nothing but calls of functions that return a Result. An idiomatic rule: reported only with "safe-ts": { "idiomatic": true } in package.json.
misplaced-axios-checkOpt-inIdiomatic
isAxiosError(x) (or axios.isAxiosError(x)) where x can't be an HTTP library's error: the error of a Result that a project function returns with its own error type, or the error of a catch whose try holds only calls that return a Result. An idiomatic rule: reported only with "safe-ts": { "idiomatic": true } in package.json.
unsafe-project-callOpt-inIdiomatic
unsafe(() => f(...)) or unsafeAsync(() => f(...)) without Panic, where f is the project's own function in a checked file and the checker finds nothing it throws or rejects with. An idiomatic rule: reported only with "safe-ts": { "idiomatic": true } in package.json.
key-presence-unionOpt-inIdiomatic
"key" in x, where x is declared as a union of the project's object types and only some of them have key: the variants are told apart by which keys they have. An idiomatic rule: reported only with "safe-ts": { "idiomatic": true } in package.json.
panic-on-loadingOpt-inIdiomatic
panic(...) under a condition that reads a loading flag: a name made of loading, loaded, hydrated, pending, fetched or fetching (store.hydrated, isLoading, hydratedData), or a Loading / Idle / Pending variant. Checked: if (cond) panic(...), cond || panic(...), value ?? panic(...) and cond ? panic(...) : x. An idiomatic rule: reported only with "safe-ts": { "idiomatic": true } in package.json.
cast-in-testOpt-inIdiomatic
as unknown as T and as never in a test file (named .test.ts / .spec.ts, importing a test runner, or in a test, tests or __tests__ directory). An idiomatic rule: reported only with "safe-ts": { "idiomatic": true } in package.json.
strict-truthinessOpt-inIdiomatic
A test of a value whose type includes number, string or bigint: if (count), name && ..., !id, x ? a : b, while (n), v-if="item.count", v-show="title", .filter(Boolean) and .filter((x) => x.label). An idiomatic rule: reported only with "safe-ts": { "idiomatic": true } in package.json.
no-positional-childrenOpt-inIdiomatic
A child of a scene graph or a DOM element picked by its position: actor.children[2], el.childNodes[0], el.children.item(1), container.getChildAt(0). An idiomatic rule: reported only with "safe-ts": { "idiomatic": true } in package.json.
prefer-constructor-tagOpt-inIdiomatic
is(x, "Published") and variant(x, "Published") where the enum has constructors in scope (const Status = constructors<Status>(), declared in the file or imported). An idiomatic rule: reported only with "safe-ts": { "idiomatic": true } in package.json.
string-dispatchOpt-inIdiomatic
One plain string (not a union of literals) compared with three or more words in one function: an if chain, || tests, switch cases. An idiomatic rule: reported only with "safe-ts": { "idiomatic": true } in package.json.
undeclared-return-typeOpt-inFixIdiomatic
A function without a declared return type whose result the checker can't read off its returns. An idiomatic rule: reported, as a warning, where the project turns the idiomatic rules on ("safe-ts": { "idiomatic": true }).
unused-codeOpt-inIdiomatic
A function, class, type, interface, constant or enum of the program that nothing used refers to: an export no file of the program imports and that the program doesn't offer outside, or a declaration only such code uses. Idiomatic (on with "idiomatic": true), a warning. Reported by safe-ts check only, which sees the whole program; the editor and the lint plugin check one file and its imports, and can't know who imports a file.
unused-privateOpt-inIdiomatic
A private or # member of a class that nothing in the class uses, a private field written and never read, and a private member used only by other private members that are themselves unused. Idiomatic (on with "idiomatic": true), a warning. A private member is used only inside its class, so one file says it all: reported in the editor and by safe-ts check alike.
vue-sfcerrorComponents
A Vue component the checker can't see into: a <script> without lang="ts", or a component without <script setup> written with the Options API (data(), methods). A defineComponent({ setup() { ... } }) is plain code the rules can follow, and isn't reported.
vue-ref-valueerrorFixComponents
A ref used without .value where its value was meant: as a condition, with !, &&, || or ??, or in a template string.
vue-lost-reactivityerrorFixComponents
Reactive state read once where it should stay connected: destructuring a reactive() object, the props or a Pinia store; watching a value read from one (watch(props.id, ...)); or passing such a value to a composable (useUser(props.id)).
vue-setup-after-awaiterrorComponents
A lifecycle hook, watcher, computed, provide/inject or similar Vue API called after an await in a function.
vue-side-effect-in-rendererrorComponents
State changed in a computed getter or while the template renders: an assignment, ++/--, or a method that changes its object (push, sort, reverse, splice, set, delete, ...). Also an async computed getter.
vue-inject-keyerrorComponents
provide or inject with a string as the key.
vue-async-raceerrorAsync and errors
An async watcher that changes state after an await, without cancelling the run before it.
vue-split-stateerrorAsync and errors
Async state kept by hand in refs, set around an await:
vue-ref-without-valueerrorAsync and errors
A ref() made without a value (ref<User>()), set after an await, and shown in the template.
vue-async-componenterrorAsync and errors
defineAsyncComponent(...) without an errorComponent or onError.
vue-matcherrorTemplates
<Match :value="state"> must have a slot for every variant of state's enum type (or #_ for the rest), and every slot must name a variant.
vue-exhaustive-v-iferrorTemplates
A v-if / v-else-if chain that tests the same value's .tag against two or more variants, doesn't end with v-else, and misses a variant of the value's enum type.
vue-maybe-undefinederrorTemplates
The template reads a field or index of a value that may be undefined (x.name, x[0]), and no v-if, &&, ? : or ?. around the read checks it.
vue-template-referrorTemplates
useElement("name") from @evobug_com/safe-ts-vue/element gives the element with ref="name", typed without null. That holds when the element is always rendered and is read after the component is mounted. This rule checks both:
vue-v-for-keyerrorTemplates
A v-for without a :key, keyed by its position in a row that keeps state, or keyed by a new object or array.
vue-v-if-with-v-forerrorTemplates
v-if and v-for on the same element.
vue-render-costwarnPerformance
Work in the template that repeats on every render: sorting, filtering or reducing a whole list, a lookup in a list inside v-for, or a new Intl formatter.
vue-deep-watchwarnPerformance
A deep watcher: watch on a whole reactive() object, the props or a store (which is deep by default), or with { deep: true }.
vue-prefer-shallow-refwarnFixPerformance
ref<T>(...) where T is readonly: readonly T[], Readonly<...>, ReadonlyArray, ReadonlyMap, ReadonlySet.
vue-v-htmlerrorSecurity
v-html with a value that isn't a constant string, the result of a sanitizer, or typed Html.
vue-unsafe-urlerrorSecurity
A bound URL that isn't checked: :href, :action, :formaction, :xlink:href, or :src on an <iframe>.
vue-ssr-browser-globalerrorServer-side rendering
A browser global used while the component is set up or rendered, in an app that also renders on a server: window, document, localStorage, sessionStorage, navigator, location, matchMedia, requestAnimationFrame, innerWidth, innerHeight, getComputedStyle.
vue-hydration-mismatcherrorServer-side rendering
A value that differs between the server and the browser, computed while the component is set up or rendered: Date.now(), new Date(), Math.random(), crypto.randomUUID(), performance.now().
react-async-raceerrorAsync
An effect that sets state after its async work finishes (after an await, or in .then), and neither aborts that work nor returns a cleanup.
react-split-stateerrorAsync
A function sets a state to true before an await and back after it (a loading flag), and sets other states after the await (the data, the error).
react-uncached-promiseerrorAsync
use(...) given a promise made while rendering: use(fetch(...)), use(load(id)) where load is an async function, use(new Promise(...)), use(Promise.all(...)), use(x.then(...)).
react-dangerous-htmlerrorSecurity
dangerouslySetInnerHTML with a value that isn't a constant string, an Html or the result of a known sanitizer: the same values markup-sink accepts at innerHTML, and vue-v-html at v-html.