unicorn/consistent-assert
Require `assert.ok(value)` instead of `assert(value)` with `node:assert`
assert(value) and assert.ok(value) do the same thing. Every other check in node:assert is a method, such as assert.equal() or assert.throws(), so the bare call is the odd one out in a list of assertions.
The rule looks at the default import of assert, node:assert, assert/strict and node:assert/strict, and at the strict export of the first two.
--fix adds .ok.
Configure#
Off by default. To turn it on:
bunfig.toml
[lint.rules]
"unicorn/consistent-assert" = "error" # or "warn"Examples#
Reported:
import assert from "node:assert";
assert(user.isActive);
assert.equal(user.name, "Ada");import { strict as assert } from "node:assert";
assert(user.isActive);Not reported:
import assert from "node:assert";
assert.ok(user.isActive);
assert.equal(user.name, "Ada");An assert that comes from anywhere else is left alone, and so is one loaded with require():
import { assert } from "chai";
const nodeAssert = require("node:assert");
assert(user.isActive);
nodeAssert(user.isActive);