Skip to content

Latest commit

 

History

History
51 lines (34 loc) · 1.38 KB

consistent-assert.md

File metadata and controls

51 lines (34 loc) · 1.38 KB

Enforce consistent assertion style with node:assert

💼 This rule is enabled in the ✅ recommended config.

🔧 This rule is automatically fixable by the --fix CLI option.

Prefer assert.ok() over assert() for its explicit intent and better readability. It aligns with other assert methods, ensuring consistency and making code easier to maintain and understand.

Examples

import assert from 'node:assert/strict';

assert.strictEqual(actual, expected);
assert.deepStrictEqual(actual, expected);

// ❌
assert(divide(10, 2) === 5); // Inconsistent with other API styles

// ✅
assert.ok(divide(10, 2) === 5);
import assert from 'node:assert';

assert.strictEqual(actual, expected);
assert.deepStrictEqual(actual, expected);

// ❌
assert(divide(10, 2) === 5); // Inconsistent with other API styles

// ✅
assert.ok(divide(10, 2) === 5);
import {strict as assert} from 'node:assert';

assert.strictEqual(actual, expected);
assert.deepStrictEqual(actual, expected);

// ❌
assert(divide(10, 2) === 5); // Inconsistent with other API styles

// ✅
assert.ok(divide(10, 2) === 5);