assertStyles
Prefer
assert.ok()overassert()for explicit intent and better readability.
✅ This rule is included in the node stylistic preset.
Using assert.ok() aligns with other assert methods, ensuring consistency and making code easier to maintain and understand.
The explicit method call clarifies the assertion’s purpose, making it immediately clear that a boolean check is being performed.
Examples
Section titled “Examples”import assert from "node:assert";
assert(divide(10, 2) === 5);import { strict as assert } from "node:assert";
assert(value);import assert from "node:assert";
assert.ok(divide(10, 2) === 5);import { strict as assert } from "node:assert";
assert.ok(value);import assert from "node:assert";
assert.strictEqual(actual, expected);assert.deepStrictEqual(actual, expected);Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If you have a strong preference for the shorter assert() syntax and find it clear enough in your codebase, you might choose not to enable this rule.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- ESLint:
unicorn/consistent-assert - Oxlint:
unicorn/consistent-assert
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.