unicorn/consistent-assert
Require assert.ok(value) instead of assert(value) with node:assert
fixable
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#
example.js1 problem
import assert from "node:assert";
assertInconsistent assert usage.(user.isActive);
assert.equal(user.name, "Ada");example.js1 problem
import { strict as assert } from "node:assert";
assertInconsistent assert usage.(user.isActive);example.jsNo problems
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():
example.jsNo problems
import { assert } from "chai";
const nodeAssert = require("node:assert");
assert(user.isActive);
nodeAssert(user.isActive);