Skip to content

Rule proposal: prefer-t-regex #163

@sindresorhus

Description

@sindresorhus

Issuehunt badges

Users should prefer the regex assertion as it's more readable and gives better output.

Fail

t.true(/\d+/.test(foo()));

Pass

t.regex(foo(), /\d+/);

Same for the negated ones, with t.notRegex.


Would also be useful to be able to detect the regex from a variable somewhere else in the scope as I often share a regex between multiple asserts:

const re = /\d+/;



t.true(re.test(foo()));

This could be auto-fixable, right?


Should we also detect the following?

t.true(foo().search(/\d+/));
t.truthy(foo().match(/\d+/));
IssueHunt Summary

gmartigny gmartigny has been rewarded.

Sponsors (Total: $60.00)

Tips

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