Skip to content

Rule proposal: No deepEqual for primitives values #158

@jfmengels

Description

@jfmengels

Issuehunt badges

I see a lot of of uses of t.deepEqual that compares to a promitive value when a simple t.is(a, b) or t.true(a === b) would work.

t.deepEqual(value, 'foo');

I'm not sure if there is a big perf hit or something, but I think it's better to use a simpler form of assertion whenever possible. I personally like to use t.is() or t.true(===) instead (frankly, most of my assertions now are t.true())

Invalid

t.deepEqual(expression, 'foo');
t.deepEqual(expression, 1);
t.deepEqual(expression, `foo${bar}`);
t.deepEqual(expression, null);
t.deepEqual(expression, undefined);
t.notDeepEqual(expression, undefined);
t.deepEqual(1, expression); // ?

Valid

t.deepEqual(expression, otherExpression);
t.deepEqual(expression, {});
t.deepEqual(expression, []);
t.notDeepEqual(expression, []);

As for the rule name, I think this only targets deepEqual and notDeepEqual, so I propose no-simple-deep-equal or something equivalent (but would love a better name for it).


IssueHunt Summary

mrhen mrhen has been rewarded.

Backers (Total: $60.00)

Submitted pull Requests


Tips


IssueHunt has been backed by the following sponsors. Become a sponsor

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions